stack_and_upgrade_controller_test.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  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/OperatingSystems/*,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. "ambari_managed_repositories": true
  1093. },
  1094. "repositories": [
  1095. {
  1096. "Repositories": {
  1097. "base_url": "111121",
  1098. "repo_id": "HDP-2.2",
  1099. "repo_name": "HDP"
  1100. }
  1101. },
  1102. {
  1103. "Repositories": {
  1104. "base_url": "1",
  1105. "repo_id": "HDP-UTILS-1.1.0.20",
  1106. "repo_name": "HDP-UTILS"
  1107. }
  1108. }
  1109. ]
  1110. }
  1111. ]};
  1112. expect(controller.prepareRepoForSaving(repo)).to.eql(result);
  1113. });
  1114. });
  1115. describe("#getStackVersionNumber()", function(){
  1116. it("get stack version number", function(){
  1117. var repo = Em.Object.create({
  1118. "stackVersionType": 'HDP',
  1119. "stackVersion": '2.3',
  1120. "repositoryVersion": '2.2.1'
  1121. });
  1122. var stackVersion = controller.getStackVersionNumber(repo);
  1123. expect(stackVersion).to.equal('2.3');
  1124. });
  1125. it("get default stack version number", function(){
  1126. App.set('currentStackVersion', '1.2.3');
  1127. var repo = Em.Object.create({
  1128. "stackVersionType": 'HDP',
  1129. "repositoryVersion": '2.2.1'
  1130. });
  1131. var stackVersion = controller.getStackVersionNumber(repo);
  1132. expect(stackVersion).to.equal('1.2.3');
  1133. });
  1134. });
  1135. describe("#saveRepoOS()", function() {
  1136. before(function(){
  1137. this.mock = sinon.stub(controller, 'validateRepoVersions');
  1138. sinon.stub(controller, 'prepareRepoForSaving', Em.K);
  1139. });
  1140. after(function(){
  1141. this.mock.restore();
  1142. controller.prepareRepoForSaving.restore();
  1143. });
  1144. describe("validation errors present", function() {
  1145. beforeEach(function () {
  1146. this.mock.returns({
  1147. done: function(callback) {callback([1]);}
  1148. });
  1149. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1150. this.args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.edit.repo');
  1151. });
  1152. it('validateRepoVersions is called with valid arguments', function () {
  1153. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1154. });
  1155. it('prepareRepoForSaving is not called', function () {
  1156. expect(controller.prepareRepoForSaving.called).to.be.false;
  1157. });
  1158. it('no requests are sent', function () {
  1159. expect(this.args).to.not.exists;
  1160. });
  1161. });
  1162. describe("no validation errors", function() {
  1163. beforeEach(function () {
  1164. this.mock.returns({
  1165. done: function(callback) {callback([]);}
  1166. });
  1167. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1168. });
  1169. it('validateRepoVersions is called with valid arguments', function () {
  1170. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1171. });
  1172. it('prepareRepoForSaving is called with valid arguments', function () {
  1173. expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
  1174. });
  1175. });
  1176. });
  1177. describe("#validateRepoVersions()", function () {
  1178. it("skip validation", function () {
  1179. controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
  1180. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1181. expect(args).to.not.exists;
  1182. });
  1183. it("do validation", function () {
  1184. var repo = Em.Object.create({
  1185. repoVersionId: 1,
  1186. operatingSystems: [
  1187. Em.Object.create({
  1188. isSelected: true,
  1189. repositories: [
  1190. Em.Object.create()
  1191. ]
  1192. })
  1193. ]
  1194. });
  1195. controller.validateRepoVersions(repo, false);
  1196. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1197. expect(args[0]).to.exists;
  1198. });
  1199. });
  1200. describe("#getUrl()", function() {
  1201. beforeEach(function(){
  1202. controller.reopen({
  1203. realStackUrl: 'realStackUrl',
  1204. realRepoUrl: 'realRepoUrl',
  1205. realUpdateUrl: 'realUpdateUrl'
  1206. });
  1207. });
  1208. it("full load is true, stack is null", function() {
  1209. expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
  1210. });
  1211. it("full load is true, stack is valid", function() {
  1212. expect(controller.getUrl({}, true)).to.equal('realStackUrl');
  1213. });
  1214. it("full load is false, stack is valid", function() {
  1215. expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
  1216. });
  1217. });
  1218. describe("#loadStackVersionsToModel()", function () {
  1219. before(function () {
  1220. sinon.stub(App.HttpClient, 'get');
  1221. });
  1222. after(function () {
  1223. App.HttpClient.get.restore();
  1224. });
  1225. it("HttpClient did get-request", function () {
  1226. controller.loadStackVersionsToModel();
  1227. expect(App.HttpClient.get.calledOnce).to.be.true;
  1228. });
  1229. });
  1230. describe("#loadRepoVersionsToModel()", function () {
  1231. before(function () {
  1232. sinon.stub(App.HttpClient, 'get');
  1233. });
  1234. after(function () {
  1235. App.HttpClient.get.restore();
  1236. });
  1237. it("HttpClient did get-request", function () {
  1238. controller.loadRepoVersionsToModel();
  1239. expect(App.HttpClient.get.calledOnce).to.be.true;
  1240. });
  1241. });
  1242. describe('#currentVersionObserver()', function () {
  1243. var cases = [
  1244. {
  1245. stackVersionType: 'HDP',
  1246. repoVersion: '2.2.1.1.0-1',
  1247. isStormMetricsSupported: false,
  1248. title: 'HDP < 2.2.2'
  1249. },
  1250. {
  1251. stackVersionType: 'HDP',
  1252. repoVersion: '2.2.2.1.0-1',
  1253. isStormMetricsSupported: true,
  1254. title: 'HDP 2.2.2'
  1255. },
  1256. {
  1257. stackVersionType: 'HDP',
  1258. repoVersion: '2.2.3.1.0-1',
  1259. isStormMetricsSupported: true,
  1260. title: 'HDP > 2.2.2'
  1261. },
  1262. {
  1263. stackVersionType: 'BIGTOP',
  1264. repoVersion: '0.8.1.1.0-1',
  1265. isStormMetricsSupported: true,
  1266. title: 'not HDP'
  1267. }
  1268. ];
  1269. afterEach(function () {
  1270. App.RepositoryVersion.find.restore();
  1271. });
  1272. cases.forEach(function (item) {
  1273. describe(item.title, function () {
  1274. beforeEach(function () {
  1275. sinon.stub(App.RepositoryVersion, 'find').returns([
  1276. Em.Object.create({
  1277. status: 'CURRENT',
  1278. stackVersionType: item.stackVersionType
  1279. })
  1280. ]);
  1281. controller.set('currentVersion', {
  1282. repository_version: item.repoVersion
  1283. });
  1284. });
  1285. it('isStormMetricsSupported is ' + (item.isStormMetricsSupported ? '' : 'not') + ' supported', function () {
  1286. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  1287. });
  1288. });
  1289. });
  1290. });
  1291. describe('#updateFinalize', function () {
  1292. beforeEach(function() {
  1293. controller.set('isFinalizeItem', true);
  1294. this.stub = sinon.stub(App, 'get');
  1295. });
  1296. afterEach(function () {
  1297. this.stub.restore();
  1298. });
  1299. describe('should do ajax-request', function () {
  1300. beforeEach(function () {
  1301. this.stub.withArgs('upgradeState').returns('HOLDING');
  1302. controller.updateFinalize();
  1303. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1304. });
  1305. it('request is sent', function () {
  1306. expect(this.args[0]).to.exists;
  1307. });
  1308. });
  1309. describe('shouldn\'t do ajax-request', function () {
  1310. beforeEach(function () {
  1311. this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
  1312. controller.updateFinalize();
  1313. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1314. });
  1315. it('request is not sent', function () {
  1316. expect(this.args).to.not.exists;
  1317. });
  1318. it('isFinalizeItem is false', function () {
  1319. expect(controller.get('isFinalizeItem')).to.be.false;
  1320. });
  1321. });
  1322. });
  1323. describe('#updateFinalizeSuccessCallback', function () {
  1324. it('data exists and Finalize should be true', function() {
  1325. var data = {
  1326. items: [
  1327. {
  1328. upgrade_groups: [
  1329. {
  1330. upgrade_items: [
  1331. {
  1332. UpgradeItem: {
  1333. context: controller.get('finalizeContext'),
  1334. status: "HOLDING"
  1335. }
  1336. }
  1337. ]
  1338. }
  1339. ]
  1340. }
  1341. ]
  1342. };
  1343. controller.set('isFinalizeItem', false);
  1344. controller.updateFinalizeSuccessCallback(data);
  1345. expect(controller.get('isFinalizeItem')).to.be.true;
  1346. });
  1347. it('data exists and Finalize should be false', function() {
  1348. var data = {
  1349. upgrade_groups: [
  1350. {
  1351. upgrade_items: [
  1352. {
  1353. UpgradeItem: {
  1354. context: '!@#$%^&',
  1355. status: "HOLDING"
  1356. }
  1357. }
  1358. ]
  1359. }
  1360. ]
  1361. };
  1362. controller.set('isFinalizeItem', true);
  1363. controller.updateFinalizeSuccessCallback(data);
  1364. expect(controller.get('isFinalizeItem')).to.be.false;
  1365. });
  1366. it('data doesn\'t exist', function() {
  1367. var data = null;
  1368. controller.set('isFinalizeItem', true);
  1369. controller.updateFinalizeSuccessCallback(data);
  1370. expect(controller.get('isFinalizeItem')).to.be.false;
  1371. });
  1372. });
  1373. describe('#updateFinalizeErrorCallback', function () {
  1374. it('should set isFinalizeItem to false', function () {
  1375. controller.set('isFinalizeItem', true);
  1376. controller.updateFinalizeErrorCallback();
  1377. expect(controller.get('isFinalizeItem')).to.be.false;
  1378. });
  1379. });
  1380. describe("#suspendUpgrade()", function() {
  1381. beforeEach(function () {
  1382. sinon.stub(controller, 'abortUpgradeWithSuspend').returns({
  1383. done: Em.clb
  1384. });
  1385. sinon.stub(controller, 'setDBProperty', Em.K);
  1386. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1387. controller.suspendUpgrade();
  1388. });
  1389. afterEach(function () {
  1390. controller.abortUpgradeWithSuspend.restore();
  1391. controller.setDBProperty.restore();
  1392. App.clusterStatus.setClusterStatus.restore();
  1393. });
  1394. it("upgrade aborted", function() {
  1395. expect(controller.abortUpgradeWithSuspend.calledOnce).to.be.true;
  1396. });
  1397. it('App.upgradeState is ABORTED', function () {
  1398. expect(App.get('upgradeState')).to.equal('ABORTED');
  1399. });
  1400. it('new upgradeState is saved to the localDB', function () {
  1401. expect(controller.setDBProperty.calledWith('upgradeState', 'ABORTED')).to.be.true;
  1402. });
  1403. it('clusterStatus is updated', function () {
  1404. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1405. });
  1406. });
  1407. describe("#resumeUpgrade()", function() {
  1408. beforeEach(function () {
  1409. sinon.stub(controller, 'retryUpgrade').returns({
  1410. done: Em.clb
  1411. });
  1412. sinon.stub(controller, 'setDBProperty', Em.K);
  1413. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1414. controller.resumeUpgrade();
  1415. });
  1416. afterEach(function () {
  1417. controller.retryUpgrade.restore();
  1418. controller.setDBProperty.restore();
  1419. App.clusterStatus.setClusterStatus.restore();
  1420. });
  1421. it("Upgrade is retrying", function() {
  1422. expect(controller.retryUpgrade.calledOnce).to.be.true;
  1423. });
  1424. it('App.upgradeState is PENDING', function () {
  1425. expect(App.get('upgradeState')).to.equal('PENDING');
  1426. });
  1427. it('new upgradeState is saved to the localDB', function () {
  1428. expect(controller.setDBProperty.calledWith('upgradeState', 'PENDING')).to.be.true;
  1429. });
  1430. it('clusterStatus is updated', function () {
  1431. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1432. });
  1433. });
  1434. describe("#runUpgradeMethodChecks()", function() {
  1435. beforeEach(function () {
  1436. sinon.stub(controller, 'runPreUpgradeCheckOnly');
  1437. });
  1438. afterEach(function () {
  1439. controller.runPreUpgradeCheckOnly.restore();
  1440. controller.get('upgradeMethods').setEach('allowed', true);
  1441. });
  1442. it("no allowed upgrade methods", function () {
  1443. controller.get('upgradeMethods').setEach('allowed', false);
  1444. controller.runUpgradeMethodChecks();
  1445. expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
  1446. });
  1447. it("Rolling method allowed", function () {
  1448. controller.get('upgradeMethods').setEach('allowed', true);
  1449. controller.runUpgradeMethodChecks(Em.Object.create({
  1450. repositoryVersion: 'v1',
  1451. displayName: 'V1'
  1452. }));
  1453. expect(controller.runPreUpgradeCheckOnly.calledWith({
  1454. value: 'v1',
  1455. label: 'V1',
  1456. type: 'ROLLING'
  1457. })).to.be.true;
  1458. });
  1459. });
  1460. describe("#restoreLastUpgrade()", function () {
  1461. var data = {
  1462. Upgrade: {
  1463. request_id: 1,
  1464. direction: 'UPGRADE',
  1465. request_status: 'PENDING',
  1466. upgrade_type: 'ROLLING',
  1467. downgrade_allowed: true,
  1468. skip_failures: true,
  1469. skip_service_check_failures: true,
  1470. to_version: '1'
  1471. }
  1472. };
  1473. beforeEach(function () {
  1474. sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
  1475. repositoryVersion: '1',
  1476. displayName: 'HDP-1'
  1477. })]);
  1478. sinon.stub(controller, 'setDBProperties');
  1479. sinon.stub(controller, 'loadRepoVersionsToModel', function () {
  1480. return {
  1481. done: function (callback) {
  1482. callback();
  1483. }
  1484. }
  1485. });
  1486. sinon.stub(controller, 'setDBProperty');
  1487. sinon.stub(controller, 'initDBProperties');
  1488. sinon.stub(controller, 'loadUpgradeData');
  1489. controller.restoreLastUpgrade(data);
  1490. });
  1491. afterEach(function () {
  1492. App.RepositoryVersion.find.restore();
  1493. controller.setDBProperties.restore();
  1494. controller.loadRepoVersionsToModel.restore();
  1495. controller.setDBProperty.restore();
  1496. controller.initDBProperties.restore();
  1497. controller.loadUpgradeData.restore();
  1498. });
  1499. it('proper data is saved to the localDB', function () {
  1500. expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
  1501. upgradeId: 1,
  1502. isDowngrade: false,
  1503. upgradeState: 'PENDING',
  1504. upgradeType: "ROLLING",
  1505. downgradeAllowed: true,
  1506. upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
  1507. failuresTolerance: Em.Object.create({
  1508. skipComponentFailures: true,
  1509. skipSCFailures: true
  1510. })
  1511. });
  1512. });
  1513. it('models are saved', function () {
  1514. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  1515. });
  1516. it('correct upgradeVersion is saved to the DB', function () {
  1517. expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
  1518. });
  1519. it('initDBProperties is called', function () {
  1520. expect(controller.initDBProperties.calledOnce).to.be.true;
  1521. });
  1522. it('loadUpgradeData called with valid arguments', function () {
  1523. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  1524. });
  1525. });
  1526. describe("#getServiceCheckItemSuccessCallback()", function() {
  1527. var testCases = [
  1528. {
  1529. title: 'no tasks',
  1530. data: {
  1531. tasks: []
  1532. },
  1533. expected: {
  1534. slaveComponentStructuredInfo: null,
  1535. serviceCheckFailuresServicenames: []
  1536. }
  1537. },
  1538. {
  1539. title: 'no structured_out property',
  1540. data: {
  1541. tasks: [
  1542. {
  1543. Tasks: {}
  1544. }
  1545. ]
  1546. },
  1547. expected: {
  1548. slaveComponentStructuredInfo: null,
  1549. serviceCheckFailuresServicenames: []
  1550. }
  1551. },
  1552. {
  1553. title: 'no failures',
  1554. data: {
  1555. tasks: [
  1556. {
  1557. Tasks: {
  1558. structured_out: {}
  1559. }
  1560. }
  1561. ]
  1562. },
  1563. expected: {
  1564. slaveComponentStructuredInfo: null,
  1565. serviceCheckFailuresServicenames: []
  1566. }
  1567. },
  1568. {
  1569. title: 'service check failures',
  1570. data: {
  1571. tasks: [
  1572. {
  1573. Tasks: {
  1574. structured_out: {
  1575. failures: {
  1576. service_check: ['HDSF', 'YARN']
  1577. }
  1578. }
  1579. }
  1580. }
  1581. ]
  1582. },
  1583. expected: {
  1584. slaveComponentStructuredInfo: {
  1585. hosts: [],
  1586. host_detail: {}
  1587. },
  1588. serviceCheckFailuresServicenames: ['HDSF', 'YARN']
  1589. }
  1590. },
  1591. {
  1592. title: 'host-component failures',
  1593. data: {
  1594. tasks: [
  1595. {
  1596. Tasks: {
  1597. structured_out: {
  1598. failures: {
  1599. service_check: ['HDSF'],
  1600. host_component: {
  1601. "host1": [
  1602. {
  1603. component: "DATANODE",
  1604. service: 'HDFS'
  1605. }
  1606. ]
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. ]
  1613. },
  1614. expected: {
  1615. slaveComponentStructuredInfo: {
  1616. hosts: ['host1'],
  1617. host_detail: {
  1618. "host1": [
  1619. {
  1620. component: "DATANODE",
  1621. service: 'HDFS'
  1622. }
  1623. ]
  1624. }
  1625. },
  1626. serviceCheckFailuresServicenames: ['HDSF']
  1627. }
  1628. }
  1629. ];
  1630. testCases.forEach(function(test) {
  1631. it(test.title, function() {
  1632. controller.set('slaveComponentStructuredInfo', null);
  1633. controller.set('serviceCheckFailuresServicenames', []);
  1634. controller.getServiceCheckItemSuccessCallback(test.data);
  1635. expect(controller.get('serviceCheckFailuresServicenames')).eql(test.expected.serviceCheckFailuresServicenames);
  1636. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1637. });
  1638. });
  1639. });
  1640. describe("#getSlaveComponentItemSuccessCallback()", function () {
  1641. var testCases = [
  1642. {
  1643. title: 'no tasks',
  1644. data: {
  1645. tasks: []
  1646. },
  1647. expected: {
  1648. slaveComponentStructuredInfo: null
  1649. }
  1650. },
  1651. {
  1652. title: 'structured_out property absent',
  1653. data: {
  1654. tasks: [
  1655. {
  1656. Tasks: {}
  1657. }
  1658. ]
  1659. },
  1660. expected: {
  1661. slaveComponentStructuredInfo: null
  1662. }
  1663. },
  1664. {
  1665. title: 'structured_out property present',
  1666. data: {
  1667. tasks: [
  1668. {
  1669. Tasks: {
  1670. "structured_out" : {
  1671. "hosts" : [
  1672. "host1"
  1673. ],
  1674. "host_detail" : {
  1675. "host1" : [
  1676. {
  1677. "service" : "FLUME",
  1678. "component" : "FLUME_HANDLER"
  1679. }
  1680. ]
  1681. }
  1682. }
  1683. }
  1684. }
  1685. ]
  1686. },
  1687. expected: {
  1688. slaveComponentStructuredInfo: {
  1689. "hosts" : [
  1690. "host1"
  1691. ],
  1692. "host_detail" : {
  1693. "host1" : [
  1694. {
  1695. "service" : "FLUME",
  1696. "component" : "FLUME_HANDLER"
  1697. }
  1698. ]
  1699. }
  1700. }
  1701. }
  1702. }
  1703. ];
  1704. testCases.forEach(function (test) {
  1705. it(test.title, function () {
  1706. controller.set('slaveComponentStructuredInfo', null);
  1707. controller.getSlaveComponentItemSuccessCallback(test.data);
  1708. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1709. });
  1710. });
  1711. });
  1712. describe('#getConfigsWarnings', function () {
  1713. var cases = [
  1714. {
  1715. configs: [],
  1716. title: 'no warning'
  1717. },
  1718. {
  1719. configsMergeWarning: {},
  1720. configs: [],
  1721. title: 'empty data'
  1722. },
  1723. {
  1724. configsMergeWarning: {
  1725. UpgradeChecks: {}
  1726. },
  1727. configs: [],
  1728. title: 'incomplete data'
  1729. },
  1730. {
  1731. configsMergeWarning: {
  1732. UpgradeChecks: {
  1733. failed_detail: {}
  1734. }
  1735. },
  1736. configs: [],
  1737. title: 'invalid data'
  1738. },
  1739. {
  1740. configsMergeWarning: {
  1741. UpgradeChecks: {
  1742. failed_detail: []
  1743. }
  1744. },
  1745. configs: [],
  1746. title: 'empty configs array'
  1747. },
  1748. {
  1749. configsMergeWarning: {
  1750. UpgradeChecks: {
  1751. status: 'FAIL',
  1752. failed_detail: [
  1753. {
  1754. type: 't0',
  1755. property: 'p0',
  1756. current: 'c0',
  1757. new_stack_value: 'n0',
  1758. result_value: 'r0'
  1759. },
  1760. {
  1761. type: 't1',
  1762. property: 'p1',
  1763. current: 'c1',
  1764. new_stack_value: 'n1'
  1765. },
  1766. {
  1767. type: 't2',
  1768. property: 'p2',
  1769. current: 'c2',
  1770. result_value: 'r2'
  1771. }
  1772. ]
  1773. }
  1774. },
  1775. configs: [],
  1776. title: 'not a warning'
  1777. },
  1778. {
  1779. configsMergeWarning: {
  1780. UpgradeChecks: {
  1781. status: 'WARNING',
  1782. failed_detail: [
  1783. {
  1784. type: 't0',
  1785. property: 'p0',
  1786. current: 'c0',
  1787. new_stack_value: 'n0',
  1788. result_value: 'r0'
  1789. },
  1790. {
  1791. type: 't1',
  1792. property: 'p1',
  1793. current: 'c1',
  1794. new_stack_value: 'n1'
  1795. },
  1796. {
  1797. type: 't2',
  1798. property: 'p2',
  1799. current: 'c2',
  1800. result_value: 'r2'
  1801. }
  1802. ]
  1803. }
  1804. },
  1805. configs: [
  1806. {
  1807. type: 't0',
  1808. name: 'p0',
  1809. currentValue: 'c0',
  1810. recommendedValue: 'n0',
  1811. isDeprecated: false,
  1812. resultingValue: 'r0',
  1813. willBeRemoved: false
  1814. },
  1815. {
  1816. type: 't1',
  1817. name: 'p1',
  1818. currentValue: 'c1',
  1819. recommendedValue: 'n1',
  1820. isDeprecated: false,
  1821. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  1822. willBeRemoved: true
  1823. },
  1824. {
  1825. type: 't2',
  1826. name: 'p2',
  1827. currentValue: 'c2',
  1828. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  1829. isDeprecated: true,
  1830. resultingValue: 'r2',
  1831. willBeRemoved: false
  1832. }
  1833. ],
  1834. title: 'normal case'
  1835. }
  1836. ];
  1837. cases.forEach(function (item) {
  1838. it(item.title, function () {
  1839. expect(controller.getConfigsWarnings(item.configsMergeWarning)).to.eql(item.configs);
  1840. });
  1841. });
  1842. });
  1843. describe('#runPreUpgradeCheckOnly', function () {
  1844. var appGetMock,
  1845. upgradeMethods = controller.get('upgradeMethods'),
  1846. cases = [
  1847. {
  1848. supportsPreUpgradeCheck: false,
  1849. ru: {
  1850. isCheckComplete: true,
  1851. isCheckRequestInProgress: false,
  1852. action: 'a'
  1853. },
  1854. eu: {
  1855. isCheckComplete: true,
  1856. isCheckRequestInProgress: false,
  1857. action: 'a'
  1858. },
  1859. ajaxCallCount: 0,
  1860. runningCheckRequestsLength: 0,
  1861. title: 'pre-upgrade checks not supported'
  1862. },
  1863. {
  1864. supportsPreUpgradeCheck: true,
  1865. ru: {
  1866. isCheckComplete: false,
  1867. isCheckRequestInProgress: true,
  1868. action: ''
  1869. },
  1870. eu: {
  1871. isCheckComplete: true,
  1872. isCheckRequestInProgress: false,
  1873. action: 'a'
  1874. },
  1875. ajaxCallCount: 1,
  1876. type: 'ROLLING',
  1877. runningCheckRequestsLength: 1,
  1878. title: 'rolling upgrade'
  1879. },
  1880. {
  1881. supportsPreUpgradeCheck: true,
  1882. ru: {
  1883. isCheckComplete: true,
  1884. isCheckRequestInProgress: false,
  1885. action: 'a'
  1886. },
  1887. eu: {
  1888. isCheckComplete: false,
  1889. isCheckRequestInProgress: true,
  1890. action: ''
  1891. },
  1892. ajaxCallCount: 1,
  1893. type: 'NON_ROLLING',
  1894. runningCheckRequestsLength: 1,
  1895. title: 'express upgrade'
  1896. }
  1897. ];
  1898. beforeEach(function () {
  1899. appGetMock = sinon.stub(App, 'get');
  1900. controller.get('runningCheckRequests').clear();
  1901. upgradeMethods.forEach(function (method) {
  1902. method.setProperties({
  1903. isCheckComplete: true,
  1904. isCheckRequestInProgress: false,
  1905. action: 'a'
  1906. });
  1907. });
  1908. App.ajax.send.restore();
  1909. sinon.stub(App.ajax, 'send').returns({});
  1910. });
  1911. afterEach(function () {
  1912. appGetMock.restore();
  1913. });
  1914. cases.forEach(function (item) {
  1915. describe(item.title, function () {
  1916. var runningCheckRequests;
  1917. beforeEach(function () {
  1918. runningCheckRequests = controller.get('runningCheckRequests');
  1919. appGetMock.returns(item.supportsPreUpgradeCheck);
  1920. controller.runPreUpgradeCheckOnly({
  1921. type: item.type
  1922. });
  1923. this.ajaxCalls = testHelpers.filterAjaxRequests('name', 'admin.upgrade.pre_upgrade_check');
  1924. });
  1925. it('ROLLING properties', function () {
  1926. expect(upgradeMethods.findProperty('type', 'ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.ru);
  1927. });
  1928. it('NON_ROLLING properties', function () {
  1929. expect(upgradeMethods.findProperty('type', 'NON_ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.eu);
  1930. });
  1931. it(item.ajaxCallCount + ' requests sent', function () {
  1932. expect(this.ajaxCalls.length).to.be.equal(item.ajaxCallCount);
  1933. });
  1934. it('runningCheckRequests length is ' + item.runningCheckRequestsLength, function () {
  1935. expect(runningCheckRequests).to.have.length(item.runningCheckRequestsLength);
  1936. });
  1937. if (item.runningCheckRequestsLength) {
  1938. it('runningCheckRequests.type is ' + item.type, function () {
  1939. expect(runningCheckRequests[0].type).to.equal(item.type);
  1940. });
  1941. }
  1942. });
  1943. });
  1944. });
  1945. describe("#openConfigsInNewWindow()", function () {
  1946. var mock = {
  1947. document: {
  1948. write: function () {}
  1949. },
  1950. focus: function () {}
  1951. };
  1952. beforeEach(function(){
  1953. sinon.stub(window, 'open', function () {
  1954. return mock;
  1955. });
  1956. sinon.spy(mock.document, 'write');
  1957. sinon.spy(mock, 'focus');
  1958. controller.openConfigsInNewWindow({
  1959. context: [
  1960. {
  1961. type: 'type1',
  1962. name: 'name1',
  1963. currentValue: 'currentValue1',
  1964. recommendedValue: 'recommendedValue1',
  1965. resultingValue: 'resultingValue1'
  1966. },
  1967. {
  1968. type: 'type2',
  1969. name: 'name2',
  1970. currentValue: 'currentValue2',
  1971. recommendedValue: 'recommendedValue2',
  1972. resultingValue: 'resultingValue2'
  1973. }
  1974. ]
  1975. });
  1976. });
  1977. afterEach(function(){
  1978. window.open.restore();
  1979. mock.document.write.restore();
  1980. mock.focus.restore();
  1981. });
  1982. it('new window is open', function () {
  1983. expect(window.open.calledOnce).to.be.true;
  1984. });
  1985. it('new window content is valid', function () {
  1986. /*eslint-disable no-useless-concat */
  1987. expect(mock.document.write.calledWith('<table style="text-align: left;"><thead><tr>' +
  1988. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.configType') + '</th>' +
  1989. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.propertyName') + '</th>' +
  1990. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.currentValue') + '</th>' +
  1991. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.recommendedValue') + '</th>' +
  1992. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.resultingValue') + '</th>' +
  1993. '</tr></thead><tbody>' +
  1994. '<tr>' +
  1995. '<td>' + 'type1' + '</td>' +
  1996. '<td>' + 'name1' + '</td>' +
  1997. '<td>' + 'currentValue1' + '</td>' +
  1998. '<td>' + 'recommendedValue1' + '</td>' +
  1999. '<td>' + 'resultingValue1' + '</td>' +
  2000. '</tr>' +
  2001. '<tr>' +
  2002. '<td>' + 'type2' + '</td>' +
  2003. '<td>' + 'name2' + '</td>' +
  2004. '<td>' + 'currentValue2' + '</td>' +
  2005. '<td>' + 'recommendedValue2' + '</td>' +
  2006. '<td>' + 'resultingValue2' + '</td>' +
  2007. '</tr></tbody></table>')).to.be.true;
  2008. /*eslint-enable no-useless-concat */
  2009. });
  2010. it('document.focus is called once', function () {
  2011. expect(mock.focus.calledOnce).to.be.true;
  2012. });
  2013. });
  2014. });