stack_and_upgrade_controller_test.js 65 KB

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