stack_and_upgrade_controller_test.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/admin/stack_and_upgrade_controller');
  20. require('utils/string_utils');
  21. var testHelpers = require('test/helpers');
  22. describe('App.MainAdminStackAndUpgradeController', function() {
  23. var controller = App.MainAdminStackAndUpgradeController.create({
  24. getDBProperty: Em.K,
  25. setDBProperty: Em.K
  26. });
  27. before(function () {
  28. sinon.stub(App.router, 'get').withArgs('clusterController.isLoaded').returns(false);
  29. });
  30. after(function () {
  31. App.router.get.restore();
  32. controller.destroy();
  33. });
  34. describe("#realRepoUrl", function() {
  35. before(function () {
  36. this.mock = sinon.stub(App, 'get');
  37. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  38. .withArgs('stackVersionURL').returns('stackVersionURL');
  39. });
  40. after(function () {
  41. this.mock.restore();
  42. });
  43. it("should be valid", function() {
  44. controller.propertyDidChange('realRepoUrl');
  45. expect(controller.get('realRepoUrl')).to.equal('apiPrefixstackVersionURL/repository_versions?fields=*,RepositoryVersions/*,operating_systems/*,operating_systems/repositories/*');
  46. });
  47. });
  48. describe("#realStackUrl", function() {
  49. before(function () {
  50. this.mock = sinon.stub(App, 'get');
  51. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  52. .withArgs('clusterName').returns('clusterName');
  53. });
  54. after(function () {
  55. this.mock.restore();
  56. });
  57. it("should be valid", function() {
  58. controller.propertyDidChange('realStackUrl');
  59. expect(controller.get('realStackUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=*,repository_versions/*,repository_versions/operating_systems/repositories/*');
  60. });
  61. });
  62. describe("#realUpdateUrl", function() {
  63. before(function () {
  64. this.mock = sinon.stub(App, 'get');
  65. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  66. .withArgs('clusterName').returns('clusterName');
  67. });
  68. after(function () {
  69. this.mock.restore();
  70. });
  71. it("realUpdateUrl is valid", function() {
  72. controller.propertyDidChange('realUpdateUrl');
  73. expect(controller.get('realUpdateUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=ClusterStackVersions/*');
  74. });
  75. });
  76. describe("#requestStatus", function() {
  77. it("state ABORTED", function() {
  78. controller.set('upgradeData', { Upgrade: {request_status: 'ABORTED'}});
  79. controller.propertyDidChange('requestStatus');
  80. expect(controller.get('requestStatus')).to.equal('SUSPENDED');
  81. });
  82. it("state not ABORTED", function() {
  83. controller.set('upgradeData', { Upgrade: {request_status: 'INIT'}});
  84. controller.propertyDidChange('requestStatus');
  85. expect(controller.get('requestStatus')).to.equal('INIT');
  86. });
  87. });
  88. describe("#load()", function() {
  89. beforeEach(function(){
  90. sinon.stub(controller, 'loadUpgradeData').returns({
  91. done: Em.clb
  92. });
  93. sinon.stub(controller, 'loadStackVersionsToModel').returns({
  94. done: Em.clb
  95. });
  96. sinon.stub(controller, 'loadRepoVersionsToModel').returns({
  97. done: Em.clb
  98. });
  99. sinon.stub(App.StackVersion, 'find').returns([Em.Object.create({
  100. state: 'CURRENT',
  101. repositoryVersion: {
  102. repositoryVersion: '2.2',
  103. displayName: 'HDP-2.2'
  104. }
  105. })]);
  106. controller.load();
  107. });
  108. afterEach(function(){
  109. controller.loadUpgradeData.restore();
  110. controller.loadStackVersionsToModel.restore();
  111. controller.loadRepoVersionsToModel.restore();
  112. App.StackVersion.find.restore();
  113. });
  114. it("loadUpgradeData called with valid arguments", function() {
  115. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  116. });
  117. it('loadStackVersionsToModel called with valid arguments', function () {
  118. expect(controller.loadStackVersionsToModel.calledWith(true)).to.be.true;
  119. });
  120. it('loadRepoVersionsToModel called once', function () {
  121. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  122. });
  123. it('currentVersion is corrent', function () {
  124. expect(controller.get('currentVersion')).to.eql({
  125. "repository_version": "2.2",
  126. "repository_name": "HDP-2.2"
  127. });
  128. });
  129. });
  130. describe("#loadUpgradeData()", function() {
  131. it("get entire data", function() {
  132. controller.set('upgradeId', 1);
  133. controller.loadUpgradeData();
  134. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
  135. expect(args[0]).to.exists;
  136. expect(args[0].sender).to.be.eql(controller);
  137. expect(args[0].data).to.be.eql({
  138. id: 1
  139. });
  140. });
  141. it("get only state", function() {
  142. controller.set('upgradeId', 1);
  143. controller.loadUpgradeData(true);
  144. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
  145. expect(args[0]).to.exists;
  146. expect(args[0].sender).to.be.eql(controller);
  147. expect(args[0].data).to.be.eql({
  148. id: 1
  149. });
  150. });
  151. it("upgrade id is null", function() {
  152. controller.set('upgradeId', null);
  153. controller.loadUpgradeData();
  154. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
  155. var args2 = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
  156. expect(args).to.not.exists;
  157. expect(args2).to.not.exists;
  158. });
  159. });
  160. describe("#loadUpgradeDataSuccessCallback()", function() {
  161. var retryCases = [
  162. {
  163. isRetryPendingInitial: true,
  164. status: 'ABORTED',
  165. isRetryPending: true,
  166. requestInProgress: true,
  167. title: 'retry request not yet applied'
  168. },
  169. {
  170. isRetryPendingInitial: true,
  171. status: 'UPGRADING',
  172. isRetryPending: false,
  173. requestInProgress: false,
  174. title: 'retry request applied'
  175. },
  176. {
  177. isRetryPendingInitial: false,
  178. status: 'ABORTED',
  179. isRetryPending: false,
  180. requestInProgress: true,
  181. title: 'no retry request sent'
  182. },
  183. {
  184. isRetryPendingInitial: false,
  185. status: 'UPGRADING',
  186. isRetryPending: false,
  187. requestInProgress: true,
  188. title: 'upgrade wasn\'t aborted'
  189. }
  190. ];
  191. beforeEach(function () {
  192. sinon.stub(controller, 'updateUpgradeData', Em.K);
  193. sinon.stub(controller, 'setDBProperty', Em.K);
  194. });
  195. afterEach(function () {
  196. controller.updateUpgradeData.restore();
  197. controller.setDBProperty.restore();
  198. });
  199. it("correct data", function() {
  200. var data = {
  201. "Upgrade": {
  202. "request_status": "UPGRADED"
  203. },
  204. "upgrade_groups": [
  205. {
  206. "UpgradeGroup": {
  207. "id": 1
  208. },
  209. "upgrade_items": []
  210. }
  211. ]};
  212. controller.loadUpgradeDataSuccessCallback(data);
  213. expect(App.get('upgradeState')).to.equal('UPGRADED');
  214. expect(controller.updateUpgradeData.calledOnce).to.be.true;
  215. expect(controller.setDBProperty.calledWith('upgradeState', 'UPGRADED')).to.be.true;
  216. });
  217. it("data is null", function() {
  218. var data = null;
  219. controller.loadUpgradeDataSuccessCallback(data);
  220. expect(controller.updateUpgradeData.called).to.be.false;
  221. expect(controller.setDBProperty.called).to.be.false;
  222. });
  223. retryCases.forEach(function (item) {
  224. it(item.title, function () {
  225. var data = {
  226. "Upgrade": {
  227. "request_status": item.status
  228. }
  229. };
  230. controller.setProperties({
  231. isRetryPending: item.isRetryPendingInitial,
  232. requestInProgress: true
  233. });
  234. controller.loadUpgradeDataSuccessCallback(data);
  235. expect(controller.getProperties(['isRetryPending', 'requestInProgress'])).to.eql({
  236. isRetryPending: item.isRetryPending,
  237. requestInProgress: item.requestInProgress
  238. });
  239. });
  240. });
  241. });
  242. describe("#getUpgradeItem()", function() {
  243. it("default callback", function() {
  244. var item = Em.Object.create({
  245. request_id: 1,
  246. group_id: 2,
  247. stage_id: 3
  248. });
  249. controller.getUpgradeItem(item);
  250. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
  251. expect(args[0]).to.exists;
  252. expect(args[0].sender).to.be.eql(controller);
  253. expect(args[0].success).to.be.equal('getUpgradeItemSuccessCallback');
  254. expect(args[0].data).to.be.eql({
  255. upgradeId: 1,
  256. groupId: 2,
  257. stageId: 3
  258. });
  259. });
  260. it("custom callback", function() {
  261. var item = Em.Object.create({
  262. request_id: 1,
  263. group_id: 2,
  264. stage_id: 3
  265. });
  266. controller.getUpgradeItem(item, 'customCallback');
  267. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
  268. expect(args[0]).to.exists;
  269. expect(args[0].sender).to.be.eql(controller);
  270. expect(args[0].success).to.be.equal('customCallback');
  271. expect(args[0].data).to.be.eql({
  272. upgradeId: 1,
  273. groupId: 2,
  274. stageId: 3
  275. });
  276. });
  277. });
  278. describe("#openUpgradeDialog()", function () {
  279. before(function () {
  280. sinon.stub(App.router, 'transitionTo', Em.K);
  281. });
  282. after(function () {
  283. App.router.transitionTo.restore();
  284. });
  285. it("should open dialog", function () {
  286. controller.openUpgradeDialog();
  287. expect(App.router.transitionTo.calledWith('admin.stackUpgrade')).to.be.true;
  288. });
  289. });
  290. describe("#runPreUpgradeCheck()", function() {
  291. it("make ajax call", function() {
  292. controller.runPreUpgradeCheck(Em.Object.create({
  293. repositoryVersion: '2.2',
  294. displayName: 'HDP-2.2',
  295. upgradeType: 'ROLLING',
  296. skipComponentFailures: false,
  297. skipSCFailures: false
  298. }));
  299. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.pre_upgrade_check');
  300. expect(args[0]).to.exists;
  301. expect(args[0].sender).to.be.eql(controller);
  302. expect(args[0].data).to.be.eql({
  303. value: '2.2',
  304. label: 'HDP-2.2',
  305. type: 'ROLLING',
  306. skipComponentFailures: 'false',
  307. skipSCFailures: 'false'
  308. });
  309. });
  310. });
  311. describe("#runPreUpgradeCheckSuccess()", function () {
  312. var cases = [
  313. {
  314. check: {
  315. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  316. "status": "FAIL",
  317. "reason": "FAIL",
  318. "failed_on": [],
  319. "check_type": "SERVICE"
  320. },
  321. showClusterCheckPopupCalledCount: 1,
  322. upgradeCalledCount: 0,
  323. title: 'popup is displayed if fails are present'
  324. },
  325. {
  326. check: {
  327. "check": "Configuration Merge Check",
  328. "status": "WARNING",
  329. "reason": "Conflict",
  330. "failed_on": [],
  331. "failed_detail": [
  332. {
  333. type: 't0',
  334. property: 'p0',
  335. current: 'c0',
  336. new_stack_value: 'n0',
  337. result_value: 'n0'
  338. },
  339. {
  340. type: 't1',
  341. property: 'p1',
  342. current: 'c1',
  343. new_stack_value: null,
  344. result_value: 'c1'
  345. },
  346. {
  347. type: 't2',
  348. property: 'p2',
  349. current: 'c2',
  350. new_stack_value: null,
  351. result_value: null
  352. }
  353. ],
  354. "check_type": "CLUSTER",
  355. "id": "CONFIG_MERGE"
  356. },
  357. showClusterCheckPopupCalledCount: 1,
  358. upgradeCalledCount: 0,
  359. configs: [
  360. {
  361. type: 't0',
  362. name: 'p0',
  363. currentValue: 'c0',
  364. recommendedValue: 'n0',
  365. resultingValue: 'n0',
  366. isDeprecated: false,
  367. willBeRemoved: false
  368. },
  369. {
  370. type: 't1',
  371. name: 'p1',
  372. currentValue: 'c1',
  373. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  374. resultingValue: 'c1',
  375. isDeprecated: true,
  376. willBeRemoved: false
  377. },
  378. {
  379. type: 't2',
  380. name: 'p2',
  381. currentValue: 'c2',
  382. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  383. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  384. isDeprecated: true,
  385. willBeRemoved: true
  386. }
  387. ],
  388. title: 'popup is displayed if warnings are present; configs merge conflicts'
  389. },
  390. {
  391. check: {
  392. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  393. "status": "PASS",
  394. "reason": "OK",
  395. "failed_on": [],
  396. "check_type": "SERVICE"
  397. },
  398. showClusterCheckPopupCalledCount: 0,
  399. upgradeCalledCount: 1,
  400. title: 'upgrade is started if fails and warnings are absent'
  401. }
  402. ];
  403. beforeEach(function () {
  404. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  405. sinon.stub(controller, 'upgrade', Em.K);
  406. });
  407. afterEach(function () {
  408. App.showClusterCheckPopup.restore();
  409. controller.upgrade.restore();
  410. });
  411. cases.forEach(function (item) {
  412. it(item.title, function () {
  413. controller.runPreUpgradeCheckSuccess(
  414. {
  415. items: [
  416. {
  417. UpgradeChecks: item.check
  418. }
  419. ]
  420. }, null, {
  421. label: 'name'
  422. }
  423. );
  424. expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
  425. expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
  426. if (item.check.id === 'CONFIG_MERGE') {
  427. expect(App.showClusterCheckPopup.firstCall.args[2]).to.eql(item.configs);
  428. }
  429. });
  430. });
  431. });
  432. describe("#initDBProperties()", function() {
  433. before(function () {
  434. this.mock = sinon.stub(controller, 'getDBProperties');
  435. });
  436. after(function () {
  437. this.mock.restore();
  438. });
  439. it("set string properties", function () {
  440. this.mock.returns({prop: 'string'});
  441. controller.initDBProperties();
  442. expect(controller.get('prop')).to.equal('string');
  443. });
  444. it("set number properties", function () {
  445. this.mock.returns({prop: 0});
  446. controller.initDBProperties();
  447. expect(controller.get('prop')).to.equal(0);
  448. });
  449. it("set boolean properties", function () {
  450. this.mock.returns({prop: false});
  451. controller.initDBProperties();
  452. expect(controller.get('prop')).to.be.false;
  453. });
  454. it("set undefined properties", function () {
  455. this.mock.returns({prop: undefined});
  456. controller.set('prop', 'value');
  457. controller.initDBProperties();
  458. expect(controller.get('prop')).to.equal('value');
  459. });
  460. it("set null properties", function () {
  461. this.mock.returns({prop: null});
  462. controller.set('prop', 'value');
  463. controller.initDBProperties();
  464. expect(controller.get('prop')).to.equal('value');
  465. });
  466. });
  467. describe("#init()", function() {
  468. before(function () {
  469. sinon.stub(controller, 'initDBProperties', Em.K);
  470. });
  471. after(function () {
  472. controller.initDBProperties.restore();
  473. });
  474. it("call initDBProperties", function () {
  475. controller.init();
  476. expect(controller.initDBProperties.calledOnce).to.be.true;
  477. });
  478. });
  479. describe("#upgrade()", function() {
  480. var callArgs;
  481. beforeEach(function () {
  482. sinon.stub(controller, 'setDBProperty', Em.K);
  483. controller.set('currentVersion', {
  484. repository_version: '2.2'
  485. });
  486. controller.upgrade({
  487. value: '2.2',
  488. label: 'HDP-2.2'
  489. });
  490. callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.start')[0];
  491. });
  492. afterEach(function () {
  493. controller.setDBProperty.restore();
  494. });
  495. it("request-data is valid", function() {
  496. expect(callArgs.data).to.eql({"value": '2.2', "label": 'HDP-2.2'});
  497. });
  498. it('request-name is valid', function () {
  499. expect(callArgs.name).to.equal('admin.upgrade.start');
  500. });
  501. it('request-sender is valid', function () {
  502. expect(callArgs.sender).to.eql(controller);
  503. });
  504. it('callback is valid', function () {
  505. expect(callArgs.success).to.equal('upgradeSuccessCallback');
  506. });
  507. it('callback is called', function () {
  508. expect(callArgs.callback).to.be.called;
  509. });
  510. it('setDBProperty is called with valid data', function () {
  511. expect(controller.setDBProperty.calledWith('currentVersion', {
  512. repository_version: '2.2'
  513. })).to.be.true;
  514. });
  515. });
  516. describe("#upgradeSuccessCallback()", function() {
  517. beforeEach(function () {
  518. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  519. sinon.stub(controller, 'openUpgradeDialog', Em.K);
  520. sinon.stub(controller, 'setDBProperties', Em.K);
  521. sinon.stub(controller, 'load', Em.K);
  522. var data = {
  523. resources: [
  524. {
  525. Upgrade: {
  526. request_id: 1
  527. }
  528. }
  529. ]
  530. };
  531. controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
  532. });
  533. afterEach(function () {
  534. App.clusterStatus.setClusterStatus.restore();
  535. controller.openUpgradeDialog.restore();
  536. controller.setDBProperties.restore();
  537. controller.load.restore();
  538. });
  539. it('load is called ocne', function() {
  540. expect(controller.load.calledOnce).to.be.true;
  541. });
  542. it('upgradeVersion is HDP-2.2.1', function() {
  543. expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
  544. });
  545. it('upgradeData is null', function() {
  546. expect(controller.get('upgradeData')).to.be.null;
  547. });
  548. it('isDowngrade is true', function() {
  549. expect(controller.get('isDowngrade')).to.be.true;
  550. });
  551. it('App.clusterStatus.setClusterStatus is called once', function() {
  552. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  553. });
  554. it('controller.openUpgradeDialog is called once', function() {
  555. expect(controller.openUpgradeDialog.calledOnce).to.be.true;
  556. });
  557. });
  558. describe("#updateUpgradeData()", function() {
  559. beforeEach(function () {
  560. sinon.stub(controller, 'initUpgradeData', Em.K);
  561. });
  562. afterEach(function () {
  563. controller.initUpgradeData.restore();
  564. });
  565. it("data loaded first time", function() {
  566. controller.set('upgradeData', null);
  567. controller.updateUpgradeData({});
  568. expect(controller.initUpgradeData.calledWith({})).to.be.true;
  569. });
  570. describe('upgradeData exists', function () {
  571. var groups;
  572. beforeEach(function() {
  573. var oldData = Em.Object.create({
  574. upgradeGroups: [
  575. Em.Object.create({
  576. group_id: 1,
  577. upgradeItems: [
  578. Em.Object.create({
  579. stage_id: 1
  580. })
  581. ]
  582. }),
  583. Em.Object.create({
  584. group_id: 2,
  585. upgradeItems: [
  586. Em.Object.create({
  587. stage_id: 2
  588. }),
  589. Em.Object.create({
  590. stage_id: 3
  591. })
  592. ]
  593. })
  594. ]
  595. });
  596. var newData = {
  597. Upgrade: {
  598. request_id: 1
  599. },
  600. upgrade_groups: [
  601. {
  602. UpgradeGroup: {
  603. group_id: 1,
  604. status: 'COMPLETED',
  605. display_status: 'COMPLETED',
  606. progress_percent: 100,
  607. completed_task_count: 3
  608. },
  609. upgrade_items: [
  610. {
  611. UpgradeItem: {
  612. stage_id: 1,
  613. status: 'COMPLETED',
  614. display_status: 'COMPLETED',
  615. progress_percent: 100
  616. }
  617. }
  618. ]
  619. },
  620. {
  621. UpgradeGroup: {
  622. group_id: 2,
  623. status: 'ABORTED',
  624. display_status: 'ABORTED',
  625. progress_percent: 50,
  626. completed_task_count: 1
  627. },
  628. upgrade_items: [
  629. {
  630. UpgradeItem: {
  631. stage_id: 2,
  632. status: 'ABORTED',
  633. display_status: 'ABORTED',
  634. progress_percent: 99
  635. }
  636. },
  637. {
  638. UpgradeItem: {
  639. stage_id: 3,
  640. status: 'PENDING',
  641. display_status: 'PENDING',
  642. progress_percent: 0
  643. }
  644. }
  645. ]
  646. }
  647. ]
  648. };
  649. controller.set('upgradeData', oldData);
  650. controller.updateUpgradeData(newData);
  651. groups = controller.get('upgradeData.upgradeGroups');
  652. });
  653. describe("checking 1st group", function() {
  654. it('status is COMPLETED', function () {
  655. expect(groups[0].get('status')).to.equal('COMPLETED');
  656. });
  657. it('display_status is COMPLETED', function () {
  658. expect(groups[0].get('display_status')).to.equal('COMPLETED');
  659. });
  660. it('progress_percent is 100', function () {
  661. expect(groups[0].get('progress_percent')).to.equal(100);
  662. });
  663. it('completed_task_count = 3', function () {
  664. expect(groups[0].get('completed_task_count')).to.equal(3);
  665. });
  666. it('upgradeItems.0.status is COMPLETED', function () {
  667. expect(groups[0].get('upgradeItems')[0].get('status')).to.equal('COMPLETED');
  668. });
  669. it('upgradeItems.0.display_status is COMPLETED', function () {
  670. expect(groups[0].get('upgradeItems')[0].get('display_status')).to.equal('COMPLETED');
  671. });
  672. it('upgradeItems.0.progress_percent is 100', function () {
  673. expect(groups[0].get('upgradeItems')[0].get('progress_percent')).to.equal(100);
  674. });
  675. it('hasExpandableItems is true', function () {
  676. expect(groups[0].get('hasExpandableItems')).to.be.true;
  677. });
  678. });
  679. describe('checking 2nd group', function () {
  680. it('status is ABORTED', function () {
  681. expect(groups[1].get('status')).to.equal('ABORTED');
  682. });
  683. it('display_status is ABORTED', function () {
  684. expect(groups[1].get('display_status')).to.equal('ABORTED');
  685. });
  686. it('progress_percent is 50', function () {
  687. expect(groups[1].get('progress_percent')).to.equal(50);
  688. });
  689. it('completed_task_count = 1', function () {
  690. expect(groups[1].get('completed_task_count')).to.equal(1);
  691. });
  692. it('upgradeItems.[].status = ["ABORTED", "PENDING"]', function () {
  693. expect(groups[1].get('upgradeItems').mapProperty('status')).to.eql(['ABORTED', 'PENDING']);
  694. });
  695. it('upgradeItems.[].display_status = ["ABORTED", "PENDING"]', function () {
  696. expect(groups[1].get('upgradeItems').mapProperty('display_status')).to.eql(['ABORTED', 'PENDING']);
  697. });
  698. it('upgradeItems.[].progress_percent = [99, 0]', function () {
  699. expect(groups[1].get('upgradeItems').mapProperty('progress_percent')).to.eql([99, 0]);
  700. });
  701. it('hasExpandableItems is false', function () {
  702. expect(groups[1].get('hasExpandableItems')).to.be.false;
  703. });
  704. });
  705. });
  706. });
  707. describe("#initUpgradeData()", function() {
  708. beforeEach(function () {
  709. sinon.stub(controller, 'setDBProperty');
  710. var newData = {
  711. Upgrade: {
  712. request_id: 1,
  713. downgrade_allowed: false
  714. },
  715. upgrade_groups: [
  716. {
  717. UpgradeGroup: {
  718. group_id: 1
  719. },
  720. upgrade_items: [
  721. {
  722. UpgradeItem: {
  723. stage_id: 1,
  724. status: 'IN_PROGRESS'
  725. }
  726. },
  727. {
  728. UpgradeItem: {
  729. stage_id: 2
  730. }
  731. }
  732. ]
  733. },
  734. {
  735. UpgradeGroup: {
  736. group_id: 2
  737. },
  738. upgrade_items: []
  739. },
  740. {
  741. UpgradeGroup: {
  742. group_id: 3
  743. },
  744. upgrade_items: [
  745. {
  746. UpgradeItem: {
  747. stage_id: 3,
  748. status: 'ABORTED'
  749. }
  750. },
  751. {
  752. UpgradeItem: {
  753. stage_id: 4,
  754. status: 'PENDING'
  755. }
  756. }
  757. ]
  758. }
  759. ]
  760. };
  761. controller.initUpgradeData(newData);
  762. });
  763. afterEach(function () {
  764. controller.setDBProperty.restore();
  765. });
  766. it("setDBProperty called with valid arguments", function() {
  767. expect(controller.setDBProperty.calledWith('downgradeAllowed', false)).to.be.true;
  768. });
  769. it('downgradeAllowed is false', function () {
  770. expect(controller.get('downgradeAllowed')).to.be.false;
  771. });
  772. it('upgradeData.Upgrade.request_id is 1', function () {
  773. expect(controller.get('upgradeData.Upgrade.request_id')).to.equal(1);
  774. });
  775. it('upgradeData.upgradeGroups contain valid data', function () {
  776. var groups = controller.get('upgradeData.upgradeGroups');
  777. expect(groups.mapProperty('group_id')).to.eql([3,2,1]);
  778. expect(groups[2].get('upgradeItems').mapProperty('stage_id')).to.eql([2,1]);
  779. expect(groups.mapProperty('hasExpandableItems')).to.eql([false, false, true]);
  780. });
  781. });
  782. describe.skip("#finish()", function() {
  783. before(function () {
  784. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  785. sinon.stub(controller, 'setDBProperty', Em.K);
  786. });
  787. after(function () {
  788. App.clusterStatus.setClusterStatus.restore();
  789. controller.setDBProperty.restore();
  790. });
  791. it("upgradeState is not COMPLETED", function() {
  792. App.set('upgradeState', 'UPGRADING');
  793. controller.finish();
  794. expect(App.clusterStatus.setClusterStatus.called).to.be.false;
  795. });
  796. it("upgradeState is COMPLETED", function() {
  797. App.set('upgradeState', 'COMPLETED');
  798. controller.finish();
  799. expect(controller.setDBProperty.calledWith('upgradeId', undefined)).to.be.true;
  800. expect(controller.setDBProperty.calledWith('upgradeVersion', undefined)).to.be.true;
  801. expect(controller.setDBProperty.calledWith('upgradeState', 'INIT')).to.be.true;
  802. expect(controller.setDBProperty.calledWith('currentVersion', undefined)).to.be.true;
  803. expect(App.get('upgradeState')).to.equal('INIT');
  804. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  805. });
  806. });
  807. describe("#confirmDowngrade()", function() {
  808. before(function () {
  809. sinon.spy(App, 'showConfirmationPopup');
  810. sinon.stub(controller, 'downgrade', Em.K);
  811. });
  812. after(function () {
  813. App.showConfirmationPopup.restore();
  814. controller.downgrade.restore();
  815. });
  816. it("show confirmation popup", function() {
  817. controller.set('currentVersion', Em.Object.create({
  818. repository_version: '2.2',
  819. repository_name: 'HDP-2.2'
  820. }));
  821. var popup = controller.confirmDowngrade();
  822. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  823. popup.onPrimary();
  824. expect(controller.downgrade.calledWith(Em.Object.create({
  825. repository_version: '2.2',
  826. repository_name: 'HDP-2.2'
  827. }))).to.be.true;
  828. });
  829. });
  830. describe("#upgradeOptions()", function() {
  831. var version = Em.Object.create({displayName: 'HDP-2.2'});
  832. beforeEach(function () {
  833. sinon.spy(App.ModalPopup, 'show');
  834. sinon.spy(App, 'showConfirmationFeedBackPopup');
  835. sinon.stub(controller, 'getSupportedUpgradeTypes').returns({
  836. done: function (callback) {
  837. callback([1]);
  838. return {
  839. always: function (alwaysCallback) {
  840. alwaysCallback();
  841. return {};
  842. }
  843. };
  844. }
  845. });
  846. sinon.stub(controller, 'runPreUpgradeCheck', Em.K);
  847. sinon.stub(App.RepositoryVersion, 'find').returns([
  848. Em.Object.create({
  849. status: 'CURRENT'
  850. })
  851. ]);
  852. controller.get('runningCheckRequests').clear();
  853. });
  854. afterEach(function () {
  855. App.ModalPopup.show.restore();
  856. App.showConfirmationFeedBackPopup.restore();
  857. controller.runPreUpgradeCheck.restore();
  858. controller.getSupportedUpgradeTypes.restore();
  859. controller.get('upgradeMethods').setEach('selected', false);
  860. App.RepositoryVersion.find.restore();
  861. });
  862. describe("show confirmation popup", function() {
  863. beforeEach(function () {
  864. controller.set('isDowngrade', false);
  865. this.popup = controller.upgradeOptions(false, version);
  866. });
  867. it('popup is shown', function () {
  868. expect(App.ModalPopup.show.calledOnce).to.be.true;
  869. });
  870. it('all upgradeMethods have isCheckRequestInProgress = true', function () {
  871. expect(controller.get('upgradeMethods').everyProperty('isCheckRequestInProgress')).to.be.true;
  872. });
  873. it('upgradeMethods no one is selected', function () {
  874. expect(controller.get('upgradeMethods').someProperty('selected')).to.be.false;
  875. });
  876. describe('#popup.onPrimary', function () {
  877. beforeEach(function () {
  878. controller.get('upgradeMethods')[0].set('selected', true);
  879. this.confirmPopup = this.popup.onPrimary();
  880. });
  881. it('showConfirmationFeedBackPopup is called once', function () {
  882. expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
  883. });
  884. describe('#confirmPopup.onPrimary', function () {
  885. beforeEach(function () {
  886. this.confirmPopup.onPrimary();
  887. });
  888. it('runPreUpgradeCheck is called with correct version', function () {
  889. expect(controller.runPreUpgradeCheck.calledWith(version)).to.be.true;
  890. });
  891. it('runningCheckRequests has 1 item', function () {
  892. expect(controller.get('runningCheckRequests')).to.have.length(1);
  893. });
  894. });
  895. });
  896. });
  897. describe("NOT show confirmation popup on Downgrade", function() {
  898. beforeEach(function () {
  899. controller.set('isDowngrade', true);
  900. controller.upgradeOptions(false, version);
  901. });
  902. it('runningCheckRequests has 1 item', function () {
  903. expect( controller.get('runningCheckRequests')).to.have.length(1);
  904. });
  905. });
  906. });
  907. describe("#confirmUpgrade()", function() {
  908. before(function () {
  909. sinon.stub(controller, 'upgradeOptions', Em.K);
  910. });
  911. after(function () {
  912. controller.upgradeOptions.restore();
  913. });
  914. it("show show upgrade options popup window", function() {
  915. var version = Em.Object.create({displayName: 'HDP-2.2'});
  916. controller.confirmUpgrade(version);
  917. expect(controller.upgradeOptions.calledWith(false, version)).to.be.true;
  918. });
  919. });
  920. describe("#downgrade()", function() {
  921. beforeEach(function () {
  922. sinon.stub(controller, 'abortUpgrade');
  923. sinon.stub(App.RepositoryVersion, 'find').returns([
  924. Em.Object.create({
  925. displayName: 'HDP-2.3',
  926. repositoryVersion: '2.3'
  927. })
  928. ]);
  929. controller.set('upgradeVersion', 'HDP-2.3');
  930. controller.set('upgradeType', 'NON_ROLLING');
  931. controller.downgrade(Em.Object.create({
  932. repository_version: '2.2',
  933. repository_name: 'HDP-2.2'
  934. }), {context: 'context'});
  935. this.callArgs = testHelpers.findAjaxRequest('name', 'admin.downgrade.start')[0];
  936. });
  937. afterEach(function () {
  938. controller.abortUpgrade.restore();
  939. App.RepositoryVersion.find.restore();
  940. });
  941. it('abortUpgrade is called once', function() {
  942. expect(controller.abortUpgrade.calledOnce).to.be.true;
  943. });
  944. it('request-data is valid', function () {
  945. expect(this.callArgs.data).to.eql({
  946. from: '2.3',
  947. value: '2.2',
  948. label: 'HDP-2.2',
  949. isDowngrade: true,
  950. upgradeType: "NON_ROLLING"
  951. });
  952. });
  953. it('request-name is valid', function () {
  954. expect(this.callArgs.name).to.be.equal('admin.downgrade.start');
  955. });
  956. it('request-sender is valid', function () {
  957. expect(this.callArgs.sender).to.be.eql(controller);
  958. });
  959. it('callback is valid', function () {
  960. expect(this.callArgs.success).to.be.equal('upgradeSuccessCallback');
  961. });
  962. it('callback is called', function () {
  963. expect(this.callArgs.callback).to.be.called;
  964. });
  965. });
  966. describe("#installRepoVersionConfirmation()", function () {
  967. before(function () {
  968. sinon.stub(controller, 'installRepoVersion', Em.K);
  969. });
  970. after(function () {
  971. controller.installRepoVersion.restore();
  972. });
  973. it("show popup", function () {
  974. var repo = Em.Object.create({'displayName': 'HDP-2.2'});
  975. var popup = controller.installRepoVersionConfirmation(repo);
  976. popup.onPrimary();
  977. expect(controller.installRepoVersion.calledWith(repo)).to.be.true;
  978. });
  979. });
  980. describe("#installRepoVersion()", function () {
  981. it("make ajax call", function () {
  982. var repo = Em.Object.create({
  983. stackVersionType: 'HDP',
  984. stackVersionNumber: '2.2',
  985. repositoryVersion: '2.2.1',
  986. repoId: 1
  987. });
  988. controller.installRepoVersion(repo);
  989. var args = testHelpers.findAjaxRequest('name', 'admin.stack_version.install.repo_version');
  990. expect(args).to.exists;
  991. });
  992. });
  993. describe("#installRepoVersionSuccess()", function() {
  994. var mock = Em.Object.create({
  995. id: 1,
  996. defaultStatus: 'INIT',
  997. stackVersion: {}
  998. });
  999. beforeEach(function () {
  1000. sinon.spy(mock, 'set');
  1001. sinon.stub(App.db, 'set', Em.K);
  1002. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1003. sinon.stub(App.RepositoryVersion, 'find').returns(mock);
  1004. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  1005. });
  1006. afterEach(function () {
  1007. App.db.set.restore();
  1008. App.clusterStatus.setClusterStatus.restore();
  1009. App.RepositoryVersion.find.restore();
  1010. mock.set.restore();
  1011. });
  1012. it("data sdtored to the local db", function() {
  1013. expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
  1014. });
  1015. it('clusterStatus is updated', function () {
  1016. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1017. });
  1018. it('App.RepositoryVersion models have valid states', function () {
  1019. expect(App.RepositoryVersion.find.calledWith(1)).to.be.true;
  1020. expect(App.RepositoryVersion.find(1).get('defaultStatus')).to.equal('INSTALLING');
  1021. expect(App.RepositoryVersion.find(1).get('stackVersion.state')).to.equal('INSTALLING');
  1022. });
  1023. });
  1024. describe("#setUpgradeItemStatus()", function () {
  1025. var item;
  1026. beforeEach(function () {
  1027. item = Em.Object.create({
  1028. request_id: 1,
  1029. stage_id: 1,
  1030. group_id: 1
  1031. });
  1032. controller.setUpgradeItemStatus(item, 'PENDING');
  1033. this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0];
  1034. });
  1035. it('request-data is valid', function () {
  1036. expect(this.callArgs.data).to.be.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
  1037. });
  1038. it('request-name is valid', function () {
  1039. expect(this.callArgs.name).to.be.equal('admin.upgrade.upgradeItem.setState');
  1040. });
  1041. it('request-sendeer is valid', function () {
  1042. expect(this.callArgs.sender).to.be.eql(controller);
  1043. });
  1044. it('callback is called', function () {
  1045. expect(this.callArgs.callback).to.be.called;
  1046. });
  1047. it('item.status is PENDING', function () {
  1048. expect(item.get('status')).to.equal('PENDING');
  1049. });
  1050. });
  1051. describe("#prepareRepoForSaving()", function () {
  1052. it("prepare date for saving", function () {
  1053. var repo = Em.Object.create({
  1054. operatingSystems: [
  1055. Em.Object.create({
  1056. osType: "redhat6",
  1057. isDisabled: Em.computed.not('isSelected'),
  1058. repositories: [Em.Object.create({
  1059. "baseUrl": "111121",
  1060. "repoId": "HDP-2.2",
  1061. "repoName": "HDP",
  1062. hasError: false
  1063. }),
  1064. Em.Object.create({
  1065. "baseUrl": "1",
  1066. "repoId": "HDP-UTILS-1.1.0.20",
  1067. "repoName": "HDP-UTILS",
  1068. hasError: false
  1069. })]
  1070. })
  1071. ]
  1072. });
  1073. var result = {
  1074. "operating_systems": [
  1075. {
  1076. "OperatingSystems": {
  1077. "os_type": "redhat6"
  1078. },
  1079. "repositories": [
  1080. {
  1081. "Repositories": {
  1082. "base_url": "111121",
  1083. "repo_id": "HDP-2.2",
  1084. "repo_name": "HDP"
  1085. }
  1086. },
  1087. {
  1088. "Repositories": {
  1089. "base_url": "1",
  1090. "repo_id": "HDP-UTILS-1.1.0.20",
  1091. "repo_name": "HDP-UTILS"
  1092. }
  1093. }
  1094. ]
  1095. }
  1096. ]};
  1097. expect(controller.prepareRepoForSaving(repo)).to.eql(result);
  1098. });
  1099. });
  1100. describe("#getStackVersionNumber()", function(){
  1101. it("get stack version number", function(){
  1102. var repo = Em.Object.create({
  1103. "stackVersionType": 'HDP',
  1104. "stackVersion": '2.3',
  1105. "repositoryVersion": '2.2.1'
  1106. });
  1107. var stackVersion = controller.getStackVersionNumber(repo);
  1108. expect(stackVersion).to.equal('2.3');
  1109. });
  1110. it("get default stack version number", function(){
  1111. App.set('currentStackVersion', '1.2.3');
  1112. var repo = Em.Object.create({
  1113. "stackVersionType": 'HDP',
  1114. "repositoryVersion": '2.2.1'
  1115. });
  1116. var stackVersion = controller.getStackVersionNumber(repo);
  1117. expect(stackVersion).to.equal('1.2.3');
  1118. });
  1119. });
  1120. describe("#saveRepoOS()", function() {
  1121. before(function(){
  1122. this.mock = sinon.stub(controller, 'validateRepoVersions');
  1123. sinon.stub(controller, 'prepareRepoForSaving', Em.K);
  1124. });
  1125. after(function(){
  1126. this.mock.restore();
  1127. controller.prepareRepoForSaving.restore();
  1128. });
  1129. describe("validation errors present", function() {
  1130. beforeEach(function () {
  1131. this.mock.returns({
  1132. done: function(callback) {callback([1]);}
  1133. });
  1134. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1135. this.args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.edit.repo');
  1136. });
  1137. it('validateRepoVersions is called with valid arguments', function () {
  1138. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1139. });
  1140. it('prepareRepoForSaving is not called', function () {
  1141. expect(controller.prepareRepoForSaving.called).to.be.false;
  1142. });
  1143. it('no requests are sent', function () {
  1144. expect(this.args).to.not.exists;
  1145. });
  1146. });
  1147. describe("no validation errors", function() {
  1148. beforeEach(function () {
  1149. this.mock.returns({
  1150. done: function(callback) {callback([]);}
  1151. });
  1152. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1153. });
  1154. it('validateRepoVersions is called with valid arguments', function () {
  1155. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1156. });
  1157. it('prepareRepoForSaving is called with valid arguments', function () {
  1158. expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
  1159. });
  1160. });
  1161. });
  1162. describe("#validateRepoVersions()", function () {
  1163. it("skip validation", function () {
  1164. controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
  1165. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1166. expect(args).to.not.exists;
  1167. });
  1168. it("do validation", function () {
  1169. var repo = Em.Object.create({
  1170. repoVersionId: 1,
  1171. operatingSystems: [
  1172. Em.Object.create({
  1173. isSelected: true,
  1174. repositories: [
  1175. Em.Object.create()
  1176. ]
  1177. })
  1178. ]
  1179. });
  1180. controller.validateRepoVersions(repo, false);
  1181. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1182. expect(args[0]).to.exists;
  1183. });
  1184. });
  1185. describe("#getUrl()", function() {
  1186. beforeEach(function(){
  1187. controller.reopen({
  1188. realStackUrl: 'realStackUrl',
  1189. realRepoUrl: 'realRepoUrl',
  1190. realUpdateUrl: 'realUpdateUrl'
  1191. });
  1192. });
  1193. it("full load is true, stack is null", function() {
  1194. expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
  1195. });
  1196. it("full load is true, stack is valid", function() {
  1197. expect(controller.getUrl({}, true)).to.equal('realStackUrl');
  1198. });
  1199. it("full load is false, stack is valid", function() {
  1200. expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
  1201. });
  1202. });
  1203. describe("#loadStackVersionsToModel()", function () {
  1204. before(function () {
  1205. sinon.stub(App.HttpClient, 'get');
  1206. });
  1207. after(function () {
  1208. App.HttpClient.get.restore();
  1209. });
  1210. it("HttpClient did get-request", function () {
  1211. controller.loadStackVersionsToModel();
  1212. expect(App.HttpClient.get.calledOnce).to.be.true;
  1213. });
  1214. });
  1215. describe("#loadRepoVersionsToModel()", function () {
  1216. before(function () {
  1217. sinon.stub(App.HttpClient, 'get');
  1218. });
  1219. after(function () {
  1220. App.HttpClient.get.restore();
  1221. });
  1222. it("HttpClient did get-request", function () {
  1223. controller.loadRepoVersionsToModel();
  1224. expect(App.HttpClient.get.calledOnce).to.be.true;
  1225. });
  1226. });
  1227. describe('#currentVersionObserver()', function () {
  1228. var cases = [
  1229. {
  1230. stackVersionType: 'HDP',
  1231. repoVersion: '2.2.1.1.0-1',
  1232. isStormMetricsSupported: false,
  1233. title: 'HDP < 2.2.2'
  1234. },
  1235. {
  1236. stackVersionType: 'HDP',
  1237. repoVersion: '2.2.2.1.0-1',
  1238. isStormMetricsSupported: true,
  1239. title: 'HDP 2.2.2'
  1240. },
  1241. {
  1242. stackVersionType: 'HDP',
  1243. repoVersion: '2.2.3.1.0-1',
  1244. isStormMetricsSupported: true,
  1245. title: 'HDP > 2.2.2'
  1246. },
  1247. {
  1248. stackVersionType: 'BIGTOP',
  1249. repoVersion: '0.8.1.1.0-1',
  1250. isStormMetricsSupported: true,
  1251. title: 'not HDP'
  1252. }
  1253. ];
  1254. afterEach(function () {
  1255. App.RepositoryVersion.find.restore();
  1256. });
  1257. cases.forEach(function (item) {
  1258. describe(item.title, function () {
  1259. beforeEach(function () {
  1260. sinon.stub(App.RepositoryVersion, 'find').returns([
  1261. Em.Object.create({
  1262. status: 'CURRENT',
  1263. stackVersionType: item.stackVersionType
  1264. })
  1265. ]);
  1266. controller.set('currentVersion', {
  1267. repository_version: item.repoVersion
  1268. });
  1269. });
  1270. it('isStormMetricsSupported is ' + (item.isStormMetricsSupported ? '' : 'not') + ' supported', function () {
  1271. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  1272. });
  1273. });
  1274. });
  1275. });
  1276. describe('#updateFinalize', function () {
  1277. beforeEach(function() {
  1278. controller.set('isFinalizeItem', true);
  1279. this.stub = sinon.stub(App, 'get');
  1280. });
  1281. afterEach(function () {
  1282. this.stub.restore();
  1283. });
  1284. describe('should do ajax-request', function () {
  1285. beforeEach(function () {
  1286. this.stub.withArgs('upgradeState').returns('HOLDING');
  1287. controller.updateFinalize();
  1288. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1289. });
  1290. it('request is sent', function () {
  1291. expect(this.args[0]).to.exists;
  1292. });
  1293. });
  1294. describe('shouldn\'t do ajax-request', function () {
  1295. beforeEach(function () {
  1296. this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
  1297. controller.updateFinalize();
  1298. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1299. });
  1300. it('request is not sent', function () {
  1301. expect(this.args).to.not.exists;
  1302. });
  1303. it('isFinalizeItem is false', function () {
  1304. expect(controller.get('isFinalizeItem')).to.be.false;
  1305. });
  1306. });
  1307. });
  1308. describe('#updateFinalizeSuccessCallback', function () {
  1309. it('data exists and Finalize should be true', function() {
  1310. var data = {
  1311. items: [
  1312. {
  1313. upgrade_groups: [
  1314. {
  1315. upgrade_items: [
  1316. {
  1317. UpgradeItem: {
  1318. context: controller.get('finalizeContext'),
  1319. status: "HOLDING"
  1320. }
  1321. }
  1322. ]
  1323. }
  1324. ]
  1325. }
  1326. ]
  1327. };
  1328. controller.set('isFinalizeItem', false);
  1329. controller.updateFinalizeSuccessCallback(data);
  1330. expect(controller.get('isFinalizeItem')).to.be.true;
  1331. });
  1332. it('data exists and Finalize should be false', function() {
  1333. var data = {
  1334. upgrade_groups: [
  1335. {
  1336. upgrade_items: [
  1337. {
  1338. UpgradeItem: {
  1339. context: '!@#$%^&',
  1340. status: "HOLDING"
  1341. }
  1342. }
  1343. ]
  1344. }
  1345. ]
  1346. };
  1347. controller.set('isFinalizeItem', true);
  1348. controller.updateFinalizeSuccessCallback(data);
  1349. expect(controller.get('isFinalizeItem')).to.be.false;
  1350. });
  1351. it('data doesn\'t exist', function() {
  1352. var data = null;
  1353. controller.set('isFinalizeItem', true);
  1354. controller.updateFinalizeSuccessCallback(data);
  1355. expect(controller.get('isFinalizeItem')).to.be.false;
  1356. });
  1357. });
  1358. describe('#updateFinalizeErrorCallback', function () {
  1359. it('should set isFinalizeItem to false', function () {
  1360. controller.set('isFinalizeItem', true);
  1361. controller.updateFinalizeErrorCallback();
  1362. expect(controller.get('isFinalizeItem')).to.be.false;
  1363. });
  1364. });
  1365. describe("#suspendUpgrade()", function() {
  1366. beforeEach(function () {
  1367. sinon.stub(controller, 'abortUpgrade').returns({
  1368. done: Em.clb
  1369. });
  1370. sinon.stub(controller, 'setDBProperty', Em.K);
  1371. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1372. controller.suspendUpgrade();
  1373. });
  1374. afterEach(function () {
  1375. controller.abortUpgrade.restore();
  1376. controller.setDBProperty.restore();
  1377. App.clusterStatus.setClusterStatus.restore();
  1378. });
  1379. it("upgrade aborted", function() {
  1380. expect(controller.abortUpgrade.calledOnce).to.be.true;
  1381. });
  1382. it('App.upgradeState is ABORTED', function () {
  1383. expect(App.get('upgradeState')).to.equal('ABORTED');
  1384. });
  1385. it('new upgradeState is saved to the localDB', function () {
  1386. expect(controller.setDBProperty.calledWith('upgradeState', 'ABORTED')).to.be.true;
  1387. });
  1388. it('clusterStatus is updated', function () {
  1389. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1390. });
  1391. });
  1392. describe("#resumeUpgrade()", function() {
  1393. beforeEach(function () {
  1394. sinon.stub(controller, 'retryUpgrade').returns({
  1395. done: Em.clb
  1396. });
  1397. sinon.stub(controller, 'setDBProperty', Em.K);
  1398. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1399. controller.resumeUpgrade();
  1400. });
  1401. afterEach(function () {
  1402. controller.retryUpgrade.restore();
  1403. controller.setDBProperty.restore();
  1404. App.clusterStatus.setClusterStatus.restore();
  1405. });
  1406. it("Upgrade is retrying", function() {
  1407. expect(controller.retryUpgrade.calledOnce).to.be.true;
  1408. });
  1409. it('App.upgradeState is PENDING', function () {
  1410. expect(App.get('upgradeState')).to.equal('PENDING');
  1411. });
  1412. it('new upgradeState is saved to the localDB', function () {
  1413. expect(controller.setDBProperty.calledWith('upgradeState', 'PENDING')).to.be.true;
  1414. });
  1415. it('clusterStatus is updated', function () {
  1416. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1417. });
  1418. });
  1419. describe("#runUpgradeMethodChecks()", function() {
  1420. beforeEach(function () {
  1421. sinon.stub(controller, 'runPreUpgradeCheckOnly');
  1422. });
  1423. afterEach(function () {
  1424. controller.runPreUpgradeCheckOnly.restore();
  1425. controller.get('upgradeMethods').setEach('allowed', true);
  1426. });
  1427. it("no allowed upgrade methods", function () {
  1428. controller.get('upgradeMethods').setEach('allowed', false);
  1429. controller.runUpgradeMethodChecks();
  1430. expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
  1431. });
  1432. it("Rolling method allowed", function () {
  1433. controller.get('upgradeMethods').setEach('allowed', true);
  1434. controller.runUpgradeMethodChecks(Em.Object.create({
  1435. repositoryVersion: 'v1',
  1436. displayName: 'V1'
  1437. }));
  1438. expect(controller.runPreUpgradeCheckOnly.calledWith({
  1439. value: 'v1',
  1440. label: 'V1',
  1441. type: 'ROLLING'
  1442. })).to.be.true;
  1443. });
  1444. });
  1445. describe("#restoreLastUpgrade()", function () {
  1446. var data = {
  1447. Upgrade: {
  1448. request_id: 1,
  1449. direction: 'UPGRADE',
  1450. request_status: 'PENDING',
  1451. upgrade_type: 'ROLLING',
  1452. downgrade_allowed: true,
  1453. skip_failures: true,
  1454. skip_service_check_failures: true,
  1455. to_version: '1'
  1456. }
  1457. };
  1458. beforeEach(function () {
  1459. sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
  1460. repositoryVersion: '1',
  1461. displayName: 'HDP-1'
  1462. })]);
  1463. sinon.stub(controller, 'setDBProperties');
  1464. sinon.stub(controller, 'loadRepoVersionsToModel', function () {
  1465. return {
  1466. done: function (callback) {
  1467. callback();
  1468. }
  1469. }
  1470. });
  1471. sinon.stub(controller, 'setDBProperty');
  1472. sinon.stub(controller, 'initDBProperties');
  1473. sinon.stub(controller, 'loadUpgradeData');
  1474. controller.restoreLastUpgrade(data);
  1475. });
  1476. afterEach(function () {
  1477. App.RepositoryVersion.find.restore();
  1478. controller.setDBProperties.restore();
  1479. controller.loadRepoVersionsToModel.restore();
  1480. controller.setDBProperty.restore();
  1481. controller.initDBProperties.restore();
  1482. controller.loadUpgradeData.restore();
  1483. });
  1484. it('proper data is saved to the localDB', function () {
  1485. expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
  1486. upgradeId: 1,
  1487. isDowngrade: false,
  1488. upgradeState: 'PENDING',
  1489. upgradeType: "ROLLING",
  1490. downgradeAllowed: true,
  1491. upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
  1492. failuresTolerance: Em.Object.create({
  1493. skipComponentFailures: true,
  1494. skipSCFailures: true
  1495. })
  1496. });
  1497. });
  1498. it('models are saved', function () {
  1499. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  1500. });
  1501. it('correct upgradeVersion is saved to the DB', function () {
  1502. expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
  1503. });
  1504. it('initDBProperties is called', function () {
  1505. expect(controller.initDBProperties.calledOnce).to.be.true;
  1506. });
  1507. it('loadUpgradeData called with valid arguments', function () {
  1508. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  1509. });
  1510. });
  1511. describe("#getServiceCheckItemSuccessCallback()", function() {
  1512. var testCases = [
  1513. {
  1514. title: 'no tasks',
  1515. data: {
  1516. tasks: []
  1517. },
  1518. expected: {
  1519. slaveComponentStructuredInfo: null,
  1520. serviceCheckFailuresServicenames: []
  1521. }
  1522. },
  1523. {
  1524. title: 'no structured_out property',
  1525. data: {
  1526. tasks: [
  1527. {
  1528. Tasks: {}
  1529. }
  1530. ]
  1531. },
  1532. expected: {
  1533. slaveComponentStructuredInfo: null,
  1534. serviceCheckFailuresServicenames: []
  1535. }
  1536. },
  1537. {
  1538. title: 'no failures',
  1539. data: {
  1540. tasks: [
  1541. {
  1542. Tasks: {
  1543. structured_out: {}
  1544. }
  1545. }
  1546. ]
  1547. },
  1548. expected: {
  1549. slaveComponentStructuredInfo: null,
  1550. serviceCheckFailuresServicenames: []
  1551. }
  1552. },
  1553. {
  1554. title: 'service check failures',
  1555. data: {
  1556. tasks: [
  1557. {
  1558. Tasks: {
  1559. structured_out: {
  1560. failures: {
  1561. service_check: ['HDSF', 'YARN']
  1562. }
  1563. }
  1564. }
  1565. }
  1566. ]
  1567. },
  1568. expected: {
  1569. slaveComponentStructuredInfo: {
  1570. hosts: [],
  1571. host_detail: {}
  1572. },
  1573. serviceCheckFailuresServicenames: ['HDSF', 'YARN']
  1574. }
  1575. },
  1576. {
  1577. title: 'host-component failures',
  1578. data: {
  1579. tasks: [
  1580. {
  1581. Tasks: {
  1582. structured_out: {
  1583. failures: {
  1584. service_check: ['HDSF'],
  1585. host_component: {
  1586. "host1": [
  1587. {
  1588. component: "DATANODE",
  1589. service: 'HDFS'
  1590. }
  1591. ]
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. ]
  1598. },
  1599. expected: {
  1600. slaveComponentStructuredInfo: {
  1601. hosts: ['host1'],
  1602. host_detail: {
  1603. "host1": [
  1604. {
  1605. component: "DATANODE",
  1606. service: 'HDFS'
  1607. }
  1608. ]
  1609. }
  1610. },
  1611. serviceCheckFailuresServicenames: ['HDSF']
  1612. }
  1613. }
  1614. ];
  1615. testCases.forEach(function(test) {
  1616. it(test.title, function() {
  1617. controller.set('slaveComponentStructuredInfo', null);
  1618. controller.set('serviceCheckFailuresServicenames', []);
  1619. controller.getServiceCheckItemSuccessCallback(test.data);
  1620. expect(controller.get('serviceCheckFailuresServicenames')).eql(test.expected.serviceCheckFailuresServicenames);
  1621. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1622. });
  1623. });
  1624. });
  1625. describe("#getSlaveComponentItemSuccessCallback()", function () {
  1626. var testCases = [
  1627. {
  1628. title: 'no tasks',
  1629. data: {
  1630. tasks: []
  1631. },
  1632. expected: {
  1633. slaveComponentStructuredInfo: null
  1634. }
  1635. },
  1636. {
  1637. title: 'structured_out property absent',
  1638. data: {
  1639. tasks: [
  1640. {
  1641. Tasks: {}
  1642. }
  1643. ]
  1644. },
  1645. expected: {
  1646. slaveComponentStructuredInfo: null
  1647. }
  1648. },
  1649. {
  1650. title: 'structured_out property present',
  1651. data: {
  1652. tasks: [
  1653. {
  1654. Tasks: {
  1655. "structured_out" : {
  1656. "hosts" : [
  1657. "host1"
  1658. ],
  1659. "host_detail" : {
  1660. "host1" : [
  1661. {
  1662. "service" : "FLUME",
  1663. "component" : "FLUME_HANDLER"
  1664. }
  1665. ]
  1666. }
  1667. }
  1668. }
  1669. }
  1670. ]
  1671. },
  1672. expected: {
  1673. slaveComponentStructuredInfo: {
  1674. "hosts" : [
  1675. "host1"
  1676. ],
  1677. "host_detail" : {
  1678. "host1" : [
  1679. {
  1680. "service" : "FLUME",
  1681. "component" : "FLUME_HANDLER"
  1682. }
  1683. ]
  1684. }
  1685. }
  1686. }
  1687. }
  1688. ];
  1689. testCases.forEach(function (test) {
  1690. it(test.title, function () {
  1691. controller.set('slaveComponentStructuredInfo', null);
  1692. controller.getSlaveComponentItemSuccessCallback(test.data);
  1693. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1694. });
  1695. });
  1696. });
  1697. describe('#getConfigsWarnings', function () {
  1698. var cases = [
  1699. {
  1700. configs: [],
  1701. title: 'no warning'
  1702. },
  1703. {
  1704. configsMergeWarning: {},
  1705. configs: [],
  1706. title: 'empty data'
  1707. },
  1708. {
  1709. configsMergeWarning: {
  1710. UpgradeChecks: {}
  1711. },
  1712. configs: [],
  1713. title: 'incomplete data'
  1714. },
  1715. {
  1716. configsMergeWarning: {
  1717. UpgradeChecks: {
  1718. failed_detail: {}
  1719. }
  1720. },
  1721. configs: [],
  1722. title: 'invalid data'
  1723. },
  1724. {
  1725. configsMergeWarning: {
  1726. UpgradeChecks: {
  1727. failed_detail: []
  1728. }
  1729. },
  1730. configs: [],
  1731. title: 'empty configs array'
  1732. },
  1733. {
  1734. configsMergeWarning: {
  1735. UpgradeChecks: {
  1736. status: 'FAIL',
  1737. failed_detail: [
  1738. {
  1739. type: 't0',
  1740. property: 'p0',
  1741. current: 'c0',
  1742. new_stack_value: 'n0',
  1743. result_value: 'r0'
  1744. },
  1745. {
  1746. type: 't1',
  1747. property: 'p1',
  1748. current: 'c1',
  1749. new_stack_value: 'n1'
  1750. },
  1751. {
  1752. type: 't2',
  1753. property: 'p2',
  1754. current: 'c2',
  1755. result_value: 'r2'
  1756. }
  1757. ]
  1758. }
  1759. },
  1760. configs: [],
  1761. title: 'not a warning'
  1762. },
  1763. {
  1764. configsMergeWarning: {
  1765. UpgradeChecks: {
  1766. status: 'WARNING',
  1767. failed_detail: [
  1768. {
  1769. type: 't0',
  1770. property: 'p0',
  1771. current: 'c0',
  1772. new_stack_value: 'n0',
  1773. result_value: 'r0'
  1774. },
  1775. {
  1776. type: 't1',
  1777. property: 'p1',
  1778. current: 'c1',
  1779. new_stack_value: 'n1'
  1780. },
  1781. {
  1782. type: 't2',
  1783. property: 'p2',
  1784. current: 'c2',
  1785. result_value: 'r2'
  1786. }
  1787. ]
  1788. }
  1789. },
  1790. configs: [
  1791. {
  1792. type: 't0',
  1793. name: 'p0',
  1794. currentValue: 'c0',
  1795. recommendedValue: 'n0',
  1796. isDeprecated: false,
  1797. resultingValue: 'r0',
  1798. willBeRemoved: false
  1799. },
  1800. {
  1801. type: 't1',
  1802. name: 'p1',
  1803. currentValue: 'c1',
  1804. recommendedValue: 'n1',
  1805. isDeprecated: false,
  1806. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  1807. willBeRemoved: true
  1808. },
  1809. {
  1810. type: 't2',
  1811. name: 'p2',
  1812. currentValue: 'c2',
  1813. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  1814. isDeprecated: true,
  1815. resultingValue: 'r2',
  1816. willBeRemoved: false
  1817. }
  1818. ],
  1819. title: 'normal case'
  1820. }
  1821. ];
  1822. cases.forEach(function (item) {
  1823. it(item.title, function () {
  1824. expect(controller.getConfigsWarnings(item.configsMergeWarning)).to.eql(item.configs);
  1825. });
  1826. });
  1827. });
  1828. describe('#runPreUpgradeCheckOnly', function () {
  1829. var appGetMock,
  1830. upgradeMethods = controller.get('upgradeMethods'),
  1831. cases = [
  1832. {
  1833. supportsPreUpgradeCheck: false,
  1834. ru: {
  1835. isCheckComplete: true,
  1836. isCheckRequestInProgress: false,
  1837. action: 'a'
  1838. },
  1839. eu: {
  1840. isCheckComplete: true,
  1841. isCheckRequestInProgress: false,
  1842. action: 'a'
  1843. },
  1844. ajaxCallCount: 0,
  1845. runningCheckRequestsLength: 0,
  1846. title: 'pre-upgrade checks not supported'
  1847. },
  1848. {
  1849. supportsPreUpgradeCheck: true,
  1850. ru: {
  1851. isCheckComplete: false,
  1852. isCheckRequestInProgress: true,
  1853. action: ''
  1854. },
  1855. eu: {
  1856. isCheckComplete: true,
  1857. isCheckRequestInProgress: false,
  1858. action: 'a'
  1859. },
  1860. ajaxCallCount: 1,
  1861. type: 'ROLLING',
  1862. runningCheckRequestsLength: 1,
  1863. title: 'rolling upgrade'
  1864. },
  1865. {
  1866. supportsPreUpgradeCheck: true,
  1867. ru: {
  1868. isCheckComplete: true,
  1869. isCheckRequestInProgress: false,
  1870. action: 'a'
  1871. },
  1872. eu: {
  1873. isCheckComplete: false,
  1874. isCheckRequestInProgress: true,
  1875. action: ''
  1876. },
  1877. ajaxCallCount: 1,
  1878. type: 'NON_ROLLING',
  1879. runningCheckRequestsLength: 1,
  1880. title: 'express upgrade'
  1881. }
  1882. ];
  1883. beforeEach(function () {
  1884. appGetMock = sinon.stub(App, 'get');
  1885. controller.get('runningCheckRequests').clear();
  1886. upgradeMethods.forEach(function (method) {
  1887. method.setProperties({
  1888. isCheckComplete: true,
  1889. isCheckRequestInProgress: false,
  1890. action: 'a'
  1891. });
  1892. });
  1893. App.ajax.send.restore();
  1894. sinon.stub(App.ajax, 'send').returns({});
  1895. });
  1896. afterEach(function () {
  1897. appGetMock.restore();
  1898. });
  1899. cases.forEach(function (item) {
  1900. describe(item.title, function () {
  1901. var runningCheckRequests;
  1902. beforeEach(function () {
  1903. runningCheckRequests = controller.get('runningCheckRequests');
  1904. appGetMock.returns(item.supportsPreUpgradeCheck);
  1905. controller.runPreUpgradeCheckOnly({
  1906. type: item.type
  1907. });
  1908. this.ajaxCalls = testHelpers.filterAjaxRequests('name', 'admin.upgrade.pre_upgrade_check');
  1909. });
  1910. it('ROLLING properties', function () {
  1911. expect(upgradeMethods.findProperty('type', 'ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.ru);
  1912. });
  1913. it('NON_ROLLING properties', function () {
  1914. expect(upgradeMethods.findProperty('type', 'NON_ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.eu);
  1915. });
  1916. it(item.ajaxCallCount + ' requests sent', function () {
  1917. expect(this.ajaxCalls.length).to.be.equal(item.ajaxCallCount);
  1918. });
  1919. it('runningCheckRequests length is ' + item.runningCheckRequestsLength, function () {
  1920. expect(runningCheckRequests).to.have.length(item.runningCheckRequestsLength);
  1921. });
  1922. if (item.runningCheckRequestsLength) {
  1923. it('runningCheckRequests.type is ' + item.type, function () {
  1924. expect(runningCheckRequests[0].type).to.equal(item.type);
  1925. });
  1926. }
  1927. });
  1928. });
  1929. });
  1930. describe("#openConfigsInNewWindow()", function () {
  1931. var mock = {
  1932. document: {
  1933. write: function () {}
  1934. },
  1935. focus: function () {}
  1936. };
  1937. beforeEach(function(){
  1938. sinon.stub(window, 'open', function () {
  1939. return mock;
  1940. });
  1941. sinon.spy(mock.document, 'write');
  1942. sinon.spy(mock, 'focus');
  1943. controller.openConfigsInNewWindow({
  1944. context: [
  1945. {
  1946. type: 'type1',
  1947. name: 'name1',
  1948. currentValue: 'currentValue1',
  1949. recommendedValue: 'recommendedValue1',
  1950. resultingValue: 'resultingValue1'
  1951. },
  1952. {
  1953. type: 'type2',
  1954. name: 'name2',
  1955. currentValue: 'currentValue2',
  1956. recommendedValue: 'recommendedValue2',
  1957. resultingValue: 'resultingValue2'
  1958. }
  1959. ]
  1960. });
  1961. });
  1962. afterEach(function(){
  1963. window.open.restore();
  1964. mock.document.write.restore();
  1965. mock.focus.restore();
  1966. });
  1967. it('new window is open', function () {
  1968. expect(window.open.calledOnce).to.be.true;
  1969. });
  1970. it('new window content is valid', function () {
  1971. /*eslint-disable no-useless-concat */
  1972. expect(mock.document.write.calledWith('<table style="text-align: left;"><thead><tr>' +
  1973. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.configType') + '</th>' +
  1974. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.propertyName') + '</th>' +
  1975. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.currentValue') + '</th>' +
  1976. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.recommendedValue') + '</th>' +
  1977. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.resultingValue') + '</th>' +
  1978. '</tr></thead><tbody>' +
  1979. '<tr>' +
  1980. '<td>' + 'type1' + '</td>' +
  1981. '<td>' + 'name1' + '</td>' +
  1982. '<td>' + 'currentValue1' + '</td>' +
  1983. '<td>' + 'recommendedValue1' + '</td>' +
  1984. '<td>' + 'resultingValue1' + '</td>' +
  1985. '</tr>' +
  1986. '<tr>' +
  1987. '<td>' + 'type2' + '</td>' +
  1988. '<td>' + 'name2' + '</td>' +
  1989. '<td>' + 'currentValue2' + '</td>' +
  1990. '<td>' + 'recommendedValue2' + '</td>' +
  1991. '<td>' + 'resultingValue2' + '</td>' +
  1992. '</tr></tbody></table>')).to.be.true;
  1993. /*eslint-enable no-useless-concat */
  1994. });
  1995. it('document.focus is called once', function () {
  1996. expect(mock.focus.calledOnce).to.be.true;
  1997. });
  1998. });
  1999. });