stack_and_upgrade_controller_test.js 64 KB

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