stack_and_upgrade_controller_test.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. describe("#realRepoUrl", function() {
  27. before(function () {
  28. this.mock = sinon.stub(App, 'get');
  29. });
  30. after(function () {
  31. this.mock.restore();
  32. });
  33. it("", function() {
  34. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  35. this.mock.withArgs('stackVersionURL').returns('stackVersionURL');
  36. controller.propertyDidChange('realRepoUrl');
  37. expect(controller.get('realRepoUrl')).to.equal('apiPrefixstackVersionURL/compatible_repository_versions?fields=*,operating_systems/*,operating_systems/repositories/*');
  38. });
  39. });
  40. describe("#realStackUrl", function() {
  41. before(function () {
  42. this.mock = sinon.stub(App, 'get');
  43. });
  44. after(function () {
  45. this.mock.restore();
  46. });
  47. it("", function() {
  48. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  49. this.mock.withArgs('clusterName').returns('clusterName');
  50. controller.propertyDidChange('realStackUrl');
  51. expect(controller.get('realStackUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=*,repository_versions/*,repository_versions/operating_systems/repositories/*');
  52. });
  53. });
  54. describe("#realUpdateUrl", function() {
  55. before(function () {
  56. this.mock = sinon.stub(App, 'get');
  57. });
  58. after(function () {
  59. this.mock.restore();
  60. });
  61. it("", function() {
  62. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  63. this.mock.withArgs('clusterName').returns('clusterName');
  64. controller.propertyDidChange('realUpdateUrl');
  65. expect(controller.get('realUpdateUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=ClusterStackVersions/*');
  66. });
  67. });
  68. describe("#load()", function() {
  69. before(function(){
  70. sinon.stub(controller, 'loadUpgradeData').returns({
  71. done: function(callback) {callback();}
  72. });
  73. sinon.stub(controller, 'loadStackVersionsToModel').returns({
  74. done: function(callback) {callback();}
  75. });
  76. sinon.stub(controller, 'loadRepoVersionsToModel').returns({
  77. done: function(callback) {callback();}
  78. });
  79. sinon.stub(App.StackVersion, 'find').returns([Em.Object.create({
  80. state: 'CURRENT',
  81. repositoryVersion: {
  82. repositoryVersion: '2.2',
  83. displayName: 'HDP-2.2'
  84. }
  85. })]);
  86. });
  87. after(function(){
  88. controller.loadUpgradeData.restore();
  89. controller.loadStackVersionsToModel.restore();
  90. controller.loadRepoVersionsToModel.restore();
  91. App.StackVersion.find.restore();
  92. });
  93. it("", function() {
  94. controller.load();
  95. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  96. expect(controller.loadStackVersionsToModel.calledWith(true)).to.be.true;
  97. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  98. expect(controller.get('currentVersion')).to.eql({
  99. "repository_version": "2.2",
  100. "repository_name": "HDP-2.2"
  101. });
  102. });
  103. });
  104. describe("#loadUpgradeData()", function() {
  105. beforeEach(function () {
  106. sinon.stub(App.ajax, 'send').returns({
  107. then: Em.K
  108. });
  109. });
  110. afterEach(function () {
  111. App.ajax.send.restore();
  112. });
  113. it("get entire data", function() {
  114. controller.set('upgradeId', 1);
  115. controller.loadUpgradeData();
  116. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  117. name: 'admin.upgrade.data',
  118. sender: controller,
  119. data: {
  120. id: 1
  121. },
  122. success: 'loadUpgradeDataSuccessCallback'
  123. })
  124. });
  125. it("get only state", function() {
  126. controller.set('upgradeId', 1);
  127. controller.loadUpgradeData(true);
  128. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  129. name: 'admin.upgrade.state',
  130. sender: controller,
  131. data: {
  132. id: 1
  133. },
  134. success: 'loadUpgradeDataSuccessCallback'
  135. })
  136. });
  137. it("upgrade id is null", function() {
  138. controller.set('upgradeId', null);
  139. controller.loadUpgradeData();
  140. expect(App.ajax.send.called).to.be.false;
  141. });
  142. });
  143. describe("#loadUpgradeDataSuccessCallback()", function() {
  144. beforeEach(function () {
  145. sinon.stub(controller, 'updateUpgradeData', Em.K);
  146. sinon.stub(controller, 'setDBProperty', Em.K);
  147. });
  148. afterEach(function () {
  149. controller.updateUpgradeData.restore();
  150. controller.setDBProperty.restore();
  151. });
  152. it("correct data", function() {
  153. var data = {
  154. "Upgrade": {
  155. "request_status": "UPGRADED"
  156. },
  157. "upgrade_groups": [
  158. {
  159. "UpgradeGroup": {
  160. "id": 1
  161. },
  162. "upgrade_items": []
  163. }
  164. ]};
  165. controller.loadUpgradeDataSuccessCallback(data);
  166. expect(App.get('upgradeState')).to.equal('UPGRADED');
  167. expect(controller.updateUpgradeData.calledOnce).to.be.true;
  168. expect(controller.setDBProperty.calledWith('upgradeState', 'UPGRADED')).to.be.true;
  169. });
  170. it("data is null", function() {
  171. var data = null;
  172. controller.loadUpgradeDataSuccessCallback(data);
  173. expect(controller.updateUpgradeData.called).to.be.false;
  174. expect(controller.setDBProperty.called).to.be.false;
  175. });
  176. });
  177. describe("#getUpgradeItem()", function() {
  178. beforeEach(function () {
  179. sinon.stub(App.ajax, 'send', Em.K);
  180. });
  181. afterEach(function () {
  182. App.ajax.send.restore();
  183. });
  184. it("", function() {
  185. var item = Em.Object.create({
  186. request_id: 1,
  187. group_id: 2,
  188. stage_id: 3
  189. });
  190. controller.getUpgradeItem(item);
  191. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  192. name: 'admin.upgrade.upgrade_item',
  193. sender: controller,
  194. data: {
  195. upgradeId: 1,
  196. groupId: 2,
  197. stageId: 3
  198. },
  199. success: 'getUpgradeItemSuccessCallback'
  200. });
  201. });
  202. });
  203. describe("#openUpgradeDialog()", function () {
  204. before(function () {
  205. sinon.stub(App.router, 'transitionTo', Em.K);
  206. });
  207. after(function () {
  208. App.router.transitionTo.restore();
  209. });
  210. it("should open dialog", function () {
  211. controller.openUpgradeDialog();
  212. expect(App.router.transitionTo.calledWith('admin.stackUpgrade')).to.be.true;
  213. });
  214. });
  215. describe("#runPreUpgradeCheck()", function() {
  216. before(function () {
  217. sinon.stub(App.ajax, 'send', Em.K);
  218. });
  219. after(function () {
  220. App.ajax.send.restore();
  221. });
  222. it("make ajax call", function() {
  223. controller.runPreUpgradeCheck(Em.Object.create({
  224. repositoryVersion: '2.2',
  225. displayName: 'HDP-2.2'
  226. }));
  227. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  228. name: "admin.rolling_upgrade.pre_upgrade_check",
  229. sender: controller,
  230. data: {
  231. value: '2.2',
  232. label: 'HDP-2.2'
  233. },
  234. success: "runPreUpgradeCheckSuccess",
  235. error: "runPreUpgradeCheckError"
  236. });
  237. });
  238. });
  239. describe("#runPreUpgradeCheckSuccess()", function () {
  240. var cases = [
  241. {
  242. check: {
  243. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  244. "status": "FAIL",
  245. "reason": "FAIL",
  246. "failed_on": [],
  247. "check_type": "SERVICE"
  248. },
  249. showClusterCheckPopupCalledCount: 1,
  250. showUpgradeConfigsMergePopupCalledCount: 0,
  251. upgradeCalledCount: 0,
  252. title: 'error popup is displayed is errors are present'
  253. },
  254. {
  255. check: {
  256. "check": "Configuration Merge Check",
  257. "status": "WARNING",
  258. "reason": "Conflict",
  259. "failed_on": [],
  260. "failed_detail": [],
  261. "check_type": "CLUSTER",
  262. "id": "CONFIG_MERGE"
  263. },
  264. showClusterCheckPopupCalledCount: 0,
  265. showUpgradeConfigsMergePopupCalledCount: 1,
  266. upgradeCalledCount: 0,
  267. title: 'warnings popup is displayed is configs merge conflicts are present'
  268. },
  269. {
  270. check: {
  271. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  272. "status": "PASS",
  273. "reason": "OK",
  274. "failed_on": [],
  275. "check_type": "SERVICE"
  276. },
  277. showClusterCheckPopupCalledCount: 0,
  278. showUpgradeConfigsMergePopupCalledCount: 0,
  279. upgradeCalledCount: 1,
  280. title: 'upgrade is started if errors and configs merge conflicts are absent'
  281. }
  282. ];
  283. beforeEach(function () {
  284. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  285. sinon.stub(App, 'showUpgradeConfigsMergePopup', Em.K);
  286. sinon.stub(controller, 'upgrade', Em.K);
  287. });
  288. afterEach(function () {
  289. App.showClusterCheckPopup.restore();
  290. App.showUpgradeConfigsMergePopup.restore();
  291. controller.upgrade.restore();
  292. });
  293. cases.forEach(function (item) {
  294. it(item.title, function () {
  295. controller.runPreUpgradeCheckSuccess(
  296. {
  297. items: [
  298. {
  299. UpgradeChecks: item.check
  300. }
  301. ]
  302. }, null, {
  303. label: 'name'
  304. }
  305. );
  306. expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
  307. expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
  308. expect(App.showUpgradeConfigsMergePopup.callCount).to.equal(item.showUpgradeConfigsMergePopupCalledCount);
  309. });
  310. });
  311. });
  312. describe("#initDBProperties()", function() {
  313. before(function () {
  314. sinon.stub(controller, 'getDBProperty', function (prop) {
  315. return prop;
  316. });
  317. });
  318. after(function () {
  319. controller.getDBProperty.restore();
  320. });
  321. it("set properties", function () {
  322. controller.set('wizardStorageProperties', ['prop1']);
  323. controller.initDBProperties();
  324. expect(controller.get('prop1')).to.equal('prop1');
  325. });
  326. });
  327. describe("#init()", function() {
  328. before(function () {
  329. sinon.stub(controller, 'initDBProperties', Em.K);
  330. });
  331. after(function () {
  332. controller.initDBProperties.restore();
  333. });
  334. it("call initDBProperties", function () {
  335. controller.init();
  336. expect(controller.initDBProperties.calledOnce).to.be.true;
  337. });
  338. });
  339. describe("#upgrade()", function() {
  340. before(function () {
  341. sinon.stub(App.ajax, 'send', Em.K);
  342. sinon.stub(controller, 'setDBProperty', Em.K);
  343. });
  344. after(function () {
  345. App.ajax.send.restore();
  346. controller.setDBProperty.restore();
  347. });
  348. it("make ajax call", function() {
  349. controller.set('currentVersion', {
  350. repository_version: '2.2'
  351. });
  352. controller.upgrade({
  353. value: '2.2',
  354. label: 'HDP-2.2'
  355. });
  356. expect(App.ajax.send.getCall(0).args[0].data).to.eql({"value": '2.2', "label": 'HDP-2.2'});
  357. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.upgrade.start');
  358. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  359. expect(App.ajax.send.getCall(0).args[0].success).to.eql('upgradeSuccessCallback');
  360. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  361. expect(controller.setDBProperty.calledWith('currentVersion', {
  362. repository_version: '2.2'
  363. })).to.be.true;
  364. });
  365. });
  366. describe("#upgradeSuccessCallback()", function() {
  367. before(function () {
  368. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  369. sinon.stub(controller, 'openUpgradeDialog', Em.K);
  370. sinon.stub(controller, 'setDBProperty', Em.K);
  371. sinon.stub(controller, 'load', Em.K);
  372. });
  373. after(function () {
  374. App.clusterStatus.setClusterStatus.restore();
  375. controller.openUpgradeDialog.restore();
  376. controller.setDBProperty.restore();
  377. controller.load.restore();
  378. });
  379. it("open upgrade dialog", function() {
  380. var data = {
  381. resources: [
  382. {
  383. Upgrade: {
  384. request_id: 1
  385. }
  386. }
  387. ]
  388. };
  389. controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
  390. expect(controller.setDBProperty.calledWith('upgradeId', 1)).to.be.true;
  391. expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-2.2.1')).to.be.true;
  392. expect(controller.setDBProperty.calledWith('isDowngrade', true)).to.be.true;
  393. expect(controller.load.calledOnce).to.be.true;
  394. expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
  395. expect(controller.get('upgradeData')).to.be.null;
  396. expect(controller.get('isDowngrade')).to.be.true;
  397. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  398. expect(controller.openUpgradeDialog.calledOnce).to.be.true;
  399. });
  400. });
  401. describe("#updateUpgradeData()", function() {
  402. beforeEach(function () {
  403. sinon.stub(controller, 'initUpgradeData', Em.K);
  404. });
  405. afterEach(function () {
  406. controller.initUpgradeData.restore();
  407. });
  408. it("data loaded first time", function() {
  409. controller.set('upgradeData', null);
  410. controller.updateUpgradeData({});
  411. expect(controller.initUpgradeData.calledWith({})).to.be.true;
  412. });
  413. it("update loaded data", function() {
  414. var oldData = Em.Object.create({
  415. upgradeGroups: [
  416. Em.Object.create({
  417. group_id: 1,
  418. upgradeItems: [
  419. Em.Object.create({
  420. stage_id: 1
  421. })
  422. ]
  423. })
  424. ]
  425. });
  426. var newData = {
  427. Upgrade: {
  428. request_id: 1
  429. },
  430. upgrade_groups: [
  431. {
  432. UpgradeGroup: {
  433. group_id: 1,
  434. status: 'COMPLETED',
  435. progress_percent: 100,
  436. completed_task_count: 3
  437. },
  438. upgrade_items: [
  439. {
  440. UpgradeItem: {
  441. stage_id: 1,
  442. status: 'COMPLETED',
  443. progress_percent: 100
  444. }
  445. }
  446. ]
  447. }
  448. ]
  449. };
  450. controller.set('upgradeData', oldData);
  451. controller.updateUpgradeData(newData);
  452. expect(controller.get('upgradeData.upgradeGroups')[0].get('status')).to.equal('COMPLETED');
  453. expect(controller.get('upgradeData.upgradeGroups')[0].get('progress_percent')).to.equal(100);
  454. expect(controller.get('upgradeData.upgradeGroups')[0].get('completed_task_count')).to.equal(3);
  455. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('status')).to.equal('COMPLETED');
  456. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('progress_percent')).to.equal(100);
  457. });
  458. });
  459. describe("#initUpgradeData()", function() {
  460. it("", function() {
  461. var newData = {
  462. Upgrade: {
  463. request_id: 1
  464. },
  465. upgrade_groups: [
  466. {
  467. UpgradeGroup: {
  468. group_id: 1
  469. },
  470. upgrade_items: [
  471. {
  472. UpgradeItem: {
  473. stage_id: 1
  474. }
  475. },
  476. {
  477. UpgradeItem: {
  478. stage_id: 2
  479. }
  480. }
  481. ]
  482. },
  483. {
  484. UpgradeGroup: {
  485. group_id: 2
  486. },
  487. upgrade_items: []
  488. }
  489. ]
  490. };
  491. controller.initUpgradeData(newData);
  492. expect(controller.get('upgradeData.Upgrade.request_id')).to.equal(1);
  493. expect(controller.get('upgradeData.upgradeGroups')[0].get('group_id')).to.equal(2);
  494. expect(controller.get('upgradeData.upgradeGroups')[1].get('group_id')).to.equal(1);
  495. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[0].get('stage_id')).to.equal(2);
  496. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[1].get('stage_id')).to.equal(1);
  497. });
  498. });
  499. describe.skip("#finish()", function() {
  500. before(function () {
  501. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  502. sinon.stub(controller, 'setDBProperty', Em.K);
  503. });
  504. after(function () {
  505. App.clusterStatus.setClusterStatus.restore();
  506. controller.setDBProperty.restore();
  507. });
  508. it("upgradeState is not COMPLETED", function() {
  509. App.set('upgradeState', 'UPGRADING');
  510. controller.finish();
  511. expect(App.clusterStatus.setClusterStatus.called).to.be.false;
  512. });
  513. it("upgradeState is COMPLETED", function() {
  514. App.set('upgradeState', 'COMPLETED');
  515. controller.finish();
  516. expect(controller.setDBProperty.calledWith('upgradeId', undefined)).to.be.true;
  517. expect(controller.setDBProperty.calledWith('upgradeVersion', undefined)).to.be.true;
  518. expect(controller.setDBProperty.calledWith('upgradeState', 'INIT')).to.be.true;
  519. expect(controller.setDBProperty.calledWith('currentVersion', undefined)).to.be.true;
  520. expect(App.get('upgradeState')).to.equal('INIT');
  521. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  522. });
  523. });
  524. describe("#confirmDowngrade()", function() {
  525. before(function () {
  526. sinon.spy(App, 'showConfirmationPopup');
  527. sinon.stub(controller, 'downgrade', Em.K);
  528. });
  529. after(function () {
  530. App.showConfirmationPopup.restore();
  531. controller.downgrade.restore();
  532. });
  533. it("show confirmation popup", function() {
  534. controller.set('currentVersion', Em.Object.create({
  535. repository_version: '2.2',
  536. repository_name: 'HDP-2.2'
  537. }));
  538. var popup = controller.confirmDowngrade();
  539. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  540. popup.onPrimary();
  541. expect(controller.downgrade.calledWith(Em.Object.create({
  542. repository_version: '2.2',
  543. repository_name: 'HDP-2.2'
  544. }))).to.be.true;
  545. });
  546. });
  547. describe("#confirmUpgrade()", function() {
  548. before(function () {
  549. sinon.spy(App, 'showConfirmationPopup');
  550. sinon.stub(controller, 'runPreUpgradeCheck', Em.K);
  551. });
  552. after(function () {
  553. App.showConfirmationPopup.restore();
  554. controller.runPreUpgradeCheck.restore();
  555. });
  556. it("show confirmation popup", function() {
  557. var version = Em.Object.create({displayName: 'HDP-2.2'});
  558. var popup = controller.confirmUpgrade(version);
  559. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  560. popup.onPrimary();
  561. expect(controller.runPreUpgradeCheck.calledWith(version)).to.be.true;
  562. });
  563. });
  564. describe("#downgrade()", function() {
  565. before(function () {
  566. sinon.stub(App.ajax, 'send', Em.K);
  567. sinon.stub(controller, 'abortUpgrade');
  568. });
  569. after(function () {
  570. App.ajax.send.restore();
  571. controller.abortUpgrade.restore();
  572. });
  573. it("make ajax call", function() {
  574. controller.downgrade(Em.Object.create({
  575. repository_version: '2.2',
  576. repository_name: 'HDP-2.2'
  577. }), {context: 'context'});
  578. expect(controller.abortUpgrade.calledOnce).to.be.true;
  579. expect(App.ajax.send.getCall(0).args[0].data).to.eql({"value": '2.2', "label": 'HDP-2.2', isDowngrade: true});
  580. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.downgrade.start');
  581. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  582. expect(App.ajax.send.getCall(0).args[0].success).to.eql('upgradeSuccessCallback');
  583. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  584. });
  585. });
  586. describe("#installRepoVersionConfirmation()", function () {
  587. before(function () {
  588. sinon.stub(controller, 'installRepoVersion', Em.K);
  589. });
  590. after(function () {
  591. controller.installRepoVersion.restore();
  592. });
  593. it("show popup", function () {
  594. var repo = Em.Object.create({'displayName': 'HDP-2.2'});
  595. var popup = controller.installRepoVersionConfirmation(repo);
  596. popup.onPrimary();
  597. expect(controller.installRepoVersion.calledWith(repo)).to.be.true;
  598. });
  599. });
  600. describe("#installRepoVersion()", function () {
  601. before(function () {
  602. sinon.stub(App.ajax, 'send', Em.K);
  603. });
  604. after(function () {
  605. App.ajax.send.restore();
  606. });
  607. it("make ajax call", function () {
  608. var repo = Em.Object.create({
  609. stackVersionType: 'HDP',
  610. stackVersionNumber: '2.2',
  611. repositoryVersion: '2.2.1',
  612. repoId: 1
  613. });
  614. controller.installRepoVersion(repo);
  615. expect(App.ajax.send.calledOnce).to.be.true;
  616. });
  617. });
  618. describe("#installRepoVersionSuccess()", function() {
  619. var mock = Em.Object.create({
  620. id: 1,
  621. defaultStatus: 'INIT',
  622. stackVersion: {}
  623. });
  624. before(function () {
  625. sinon.spy(mock, 'set');
  626. sinon.stub(App.db, 'set', Em.K);
  627. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  628. sinon.stub(App.RepositoryVersion, 'find').returns(mock);
  629. });
  630. after(function () {
  631. App.db.set.restore();
  632. App.clusterStatus.setClusterStatus.restore();
  633. App.RepositoryVersion.find.restore();
  634. });
  635. it("", function() {
  636. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  637. expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
  638. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  639. expect(App.RepositoryVersion.find.calledWith(1)).to.be.true;
  640. expect(App.RepositoryVersion.find(1).get('defaultStatus')).to.equal('INSTALLING');
  641. expect(App.RepositoryVersion.find(1).get('stackVersion.state')).to.equal('INSTALLING');
  642. });
  643. });
  644. describe("#setUpgradeItemStatus()", function () {
  645. before(function () {
  646. sinon.stub(App.ajax, 'send', function () {
  647. return {
  648. done: function (callback) {
  649. callback();
  650. }
  651. }
  652. });
  653. });
  654. after(function () {
  655. App.ajax.send.restore();
  656. });
  657. it("", function () {
  658. var item = Em.Object.create({
  659. request_id: 1,
  660. stage_id: 1,
  661. group_id: 1
  662. });
  663. controller.setUpgradeItemStatus(item, 'PENDING');
  664. expect(App.ajax.send.getCall(0).args[0].data).to.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
  665. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.upgrade.upgradeItem.setState');
  666. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  667. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  668. expect(item.get('status')).to.equal('PENDING');
  669. });
  670. });
  671. describe("#prepareRepoForSaving()", function () {
  672. it("prepare date for saving", function () {
  673. var repo = Em.Object.create({
  674. operatingSystems: [
  675. Em.Object.create({
  676. osType: "redhat6",
  677. isDisabled: Ember.computed.not('isSelected'),
  678. repositories: [Em.Object.create({
  679. "baseUrl": "111121",
  680. "repoId": "HDP-2.2",
  681. "repoName": "HDP",
  682. hasError: false
  683. }),
  684. Em.Object.create({
  685. "baseUrl": "1",
  686. "repoId": "HDP-UTILS-1.1.0.20",
  687. "repoName": "HDP-UTILS",
  688. hasError: false
  689. })]
  690. })
  691. ]
  692. });
  693. var result = {
  694. "operating_systems": [
  695. {
  696. "OperatingSystems": {
  697. "os_type": "redhat6"
  698. },
  699. "repositories": [
  700. {
  701. "Repositories": {
  702. "base_url": "111121",
  703. "repo_id": "HDP-2.2",
  704. "repo_name": "HDP"
  705. }
  706. },
  707. {
  708. "Repositories": {
  709. "base_url": "1",
  710. "repo_id": "HDP-UTILS-1.1.0.20",
  711. "repo_name": "HDP-UTILS"
  712. }
  713. }
  714. ]
  715. }
  716. ]};
  717. expect(controller.prepareRepoForSaving(repo)).to.eql(result);
  718. });
  719. });
  720. describe("#saveRepoOS()", function() {
  721. before(function(){
  722. this.mock = sinon.stub(controller, 'validateRepoVersions');
  723. sinon.stub(controller, 'prepareRepoForSaving', Em.K);
  724. sinon.stub(App.ajax, 'send').returns({success: Em.K});
  725. });
  726. after(function(){
  727. this.mock.restore();
  728. controller.prepareRepoForSaving.restore();
  729. App.ajax.send.restore();
  730. });
  731. it("validation errors present", function() {
  732. this.mock.returns({
  733. done: function(callback) {callback([1]);}
  734. });
  735. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  736. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  737. expect(controller.prepareRepoForSaving.called).to.be.false;
  738. expect(App.ajax.send.called).to.be.false;
  739. });
  740. it("no validation errors", function() {
  741. this.mock.returns({
  742. done: function(callback) {callback([]);}
  743. });
  744. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  745. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  746. expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
  747. expect(App.ajax.send.calledOnce).to.be.true;
  748. });
  749. });
  750. describe("#validateRepoVersions()", function () {
  751. before(function () {
  752. sinon.stub(App.ajax, 'send').returns({success: Em.K, error: Em.K});
  753. });
  754. after(function () {
  755. App.ajax.send.restore();
  756. });
  757. it("skip validation", function () {
  758. controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
  759. expect(App.ajax.send.called).to.be.false;
  760. });
  761. it("do validation", function () {
  762. var repo = Em.Object.create({
  763. repoVersionId: 1,
  764. operatingSystems: [
  765. Em.Object.create({
  766. isSelected: true,
  767. repositories: [
  768. Em.Object.create()
  769. ]
  770. })
  771. ]
  772. });
  773. controller.validateRepoVersions(repo, false);
  774. expect(App.ajax.send.calledOnce).to.be.true;
  775. });
  776. });
  777. describe("#showProgressPopup()", function () {
  778. var mock = {
  779. initPopup: Em.K
  780. };
  781. before(function () {
  782. sinon.stub(App.router, 'get').withArgs('highAvailabilityProgressPopupController').returns(mock);
  783. sinon.spy(mock, 'initPopup');
  784. });
  785. after(function () {
  786. App.router.get.restore();
  787. mock.initPopup.restore();
  788. });
  789. it("", function () {
  790. controller.showProgressPopup(Em.Object.create());
  791. expect(mock.initPopup.calledOnce).to.be.true;
  792. });
  793. });
  794. describe("#getUrl()", function() {
  795. beforeEach(function(){
  796. controller.reopen({
  797. realStackUrl: 'realStackUrl',
  798. realRepoUrl: 'realRepoUrl',
  799. realUpdateUrl: 'realUpdateUrl'
  800. });
  801. });
  802. it("full load is true, stack is null", function() {
  803. expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
  804. });
  805. it("full load is true, stack is valid", function() {
  806. expect(controller.getUrl({}, true)).to.equal('realStackUrl');
  807. });
  808. it("full load is false, stack is valid", function() {
  809. expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
  810. });
  811. });
  812. describe("#loadStackVersionsToModel()", function () {
  813. before(function () {
  814. sinon.stub(App.HttpClient, 'get');
  815. });
  816. after(function () {
  817. App.HttpClient.get.restore();
  818. });
  819. it("", function () {
  820. controller.loadStackVersionsToModel();
  821. expect(App.HttpClient.get.calledOnce).to.be.true;
  822. });
  823. });
  824. describe("#loadRepoVersionsToModel()", function () {
  825. before(function () {
  826. sinon.stub(App.HttpClient, 'get');
  827. });
  828. after(function () {
  829. App.HttpClient.get.restore();
  830. });
  831. it("", function () {
  832. controller.loadRepoVersionsToModel();
  833. expect(App.HttpClient.get.calledOnce).to.be.true;
  834. });
  835. });
  836. describe('#currentVersionObserver()', function () {
  837. var cases = [
  838. {
  839. stackVersionType: 'HDP',
  840. repoVersion: '2.2.1.1.0-1',
  841. isStormMetricsSupported: false,
  842. title: 'HDP < 2.2.2'
  843. },
  844. {
  845. stackVersionType: 'HDP',
  846. repoVersion: '2.2.2.1.0-1',
  847. isStormMetricsSupported: true,
  848. title: 'HDP 2.2.2'
  849. },
  850. {
  851. stackVersionType: 'HDP',
  852. repoVersion: '2.2.3.1.0-1',
  853. isStormMetricsSupported: true,
  854. title: 'HDP > 2.2.2'
  855. },
  856. {
  857. stackVersionType: 'BIGTOP',
  858. repoVersion: '0.8.1.1.0-1',
  859. isStormMetricsSupported: true,
  860. title: 'not HDP'
  861. }
  862. ];
  863. afterEach(function () {
  864. App.RepositoryVersion.find.restore();
  865. });
  866. cases.forEach(function (item) {
  867. it(item.title, function () {
  868. sinon.stub(App.RepositoryVersion, 'find').returns([
  869. Em.Object.create({
  870. status: 'CURRENT',
  871. stackVersionType: item.stackVersionType
  872. })
  873. ]);
  874. controller.set('currentVersion', {
  875. repository_version: item.repoVersion
  876. });
  877. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  878. });
  879. });
  880. });
  881. });