stack_and_upgrade_controller_test.js 64 KB

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