stack_and_upgrade_controller_test.js 64 KB

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