step3_test.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  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 Ember = require('ember');
  19. var App = require('app');
  20. var c;
  21. require('utils/http_client');
  22. require('models/host');
  23. require('controllers/wizard/step3_controller');
  24. describe('App.WizardStep3Controller', function () {
  25. beforeEach(function() {
  26. c = App.WizardStep3Controller.create({
  27. wizardController: App.InstallerController.create(),
  28. disablePreviousSteps: Em.K
  29. });
  30. });
  31. describe('#getAllRegisteredHostsCallback', function () {
  32. it('One host is already in the cluster, one host is registered', function() {
  33. var controller = App.WizardStep3Controller.create({
  34. hostsInCluster: [{
  35. hostName: 'wst3_host1'
  36. }],
  37. bootHosts: [
  38. {name:'wst3_host1'},
  39. {name:'wst3_host2'}
  40. ]
  41. });
  42. var test_data = {
  43. items: [
  44. {
  45. Hosts: {
  46. host_name: 'wst3_host1'
  47. }
  48. },
  49. {
  50. Hosts: {
  51. host_name: 'wst3_host2'
  52. }
  53. },
  54. {
  55. Hosts: {
  56. host_name: 'wst3_host3'
  57. }
  58. }
  59. ]
  60. };
  61. controller.getAllRegisteredHostsCallback(test_data);
  62. expect(controller.get('hasMoreRegisteredHosts')).to.equal(true);
  63. expect(controller.get('registeredHosts').length).to.equal(1);
  64. });
  65. it('All hosts are new', function() {
  66. var controller = App.WizardStep3Controller.create({
  67. hostsInCluster: [{
  68. hostName: 'wst3_host1'
  69. }],
  70. bootHosts: [
  71. {name:'wst3_host3'},
  72. {name:'wst3_host4'}
  73. ]
  74. });
  75. var test_data = {
  76. items: [
  77. {
  78. Hosts: {
  79. host_name: 'wst3_host3'
  80. }
  81. },
  82. {
  83. Hosts: {
  84. host_name: 'wst3_host4'
  85. }
  86. }
  87. ]
  88. };
  89. controller.getAllRegisteredHostsCallback(test_data);
  90. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  91. expect(controller.get('registeredHosts')).to.equal('');
  92. });
  93. it('No new hosts', function() {
  94. var controller = App.WizardStep3Controller.create({
  95. hostsInCluster: [{
  96. hostName: 'wst3_host1'
  97. }],
  98. bootHosts: [
  99. {name:'wst3_host1'}
  100. ]
  101. });
  102. var test_data = {
  103. items: [
  104. {
  105. Hosts: {
  106. host_name: 'wst3_host1'
  107. }
  108. }
  109. ]
  110. };
  111. controller.getAllRegisteredHostsCallback(test_data);
  112. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  113. expect(controller.get('registeredHosts')).to.equal('');
  114. });
  115. });
  116. describe('#registrationTimeoutSecs', function() {
  117. it('Manual install', function() {
  118. var controller = App.WizardStep3Controller.create({
  119. content: {
  120. installOptions: {
  121. manualInstall: true
  122. }
  123. }
  124. });
  125. expect(controller.get('registrationTimeoutSecs')).to.equal(15);
  126. });
  127. it('Not manual install', function() {
  128. var controller = App.WizardStep3Controller.create({
  129. content: {
  130. installOptions: {
  131. manualInstall: false
  132. }
  133. }
  134. });
  135. expect(controller.get('registrationTimeoutSecs')).to.equal(120);
  136. });
  137. });
  138. describe('#isHostHaveWarnings', function() {
  139. var tests = [
  140. {
  141. warnings: [{},{}],
  142. m: 'Warnings exist',
  143. e: true
  144. },
  145. {
  146. warnings: [],
  147. m: 'Warnings don\'t exist',
  148. e: false
  149. }
  150. ];
  151. tests.forEach(function(test) {
  152. var controller = App.WizardStep3Controller.create();
  153. controller.set('warnings', test.warnings);
  154. it(test.m, function() {
  155. expect(controller.get('isHostHaveWarnings')).to.equal(test.e);
  156. });
  157. });
  158. });
  159. describe('#isWarningsBoxVisible', function() {
  160. it('for testMode should be always true', function() {
  161. App.testMode = true;
  162. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  163. App.testMode = false;
  164. });
  165. it('for "real" mode should be based on isRegistrationInProgress', function() {
  166. c.set('disablePreviousSteps', Em.K);
  167. App.testMode = false;
  168. c.set('isRegistrationInProgress', false);
  169. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  170. c.set('isRegistrationInProgress', true);
  171. expect(c.get('isWarningsBoxVisible')).to.equal(false);
  172. App.testMode = true;
  173. });
  174. });
  175. describe('#clearStep', function() {
  176. it('should clear hosts', function() {
  177. c.set('hosts', [{}, {}]);
  178. c.clearStep();
  179. expect(c.get('hosts')).to.eql([]);
  180. });
  181. it('should clear bootHosts', function() {
  182. c.set('bootHosts', [{}, {}]);
  183. c.clearStep();
  184. expect(c.get('bootHosts').length).to.equal(0);
  185. });
  186. it('should set stopBootstrap to false', function() {
  187. c.set('stopBootstrap', true);
  188. c.clearStep();
  189. expect(c.get('stopBootstrap')).to.equal(false);
  190. });
  191. it('should set wizardController DBProperty bootStatus to false', function() {
  192. c.get('wizardController').setDBProperty('bootStatus', true);
  193. c.clearStep();
  194. expect(c.get('wizardController').getDBProperty('bootStatus')).to.equal(false);
  195. });
  196. it('should set isSubmitDisabled to true', function() {
  197. c.set('isSubmitDisabled', false);
  198. c.clearStep();
  199. expect(c.get('isSubmitDisabled')).to.equal(true);
  200. });
  201. it('should set isSubmitDisabled to true', function() {
  202. c.set('isRetryDisabled', false);
  203. c.clearStep();
  204. expect(c.get('isRetryDisabled')).to.equal(true);
  205. });
  206. });
  207. describe('#loadStep', function() {
  208. it('should set registrationStartedAt to null', function() {
  209. c.set('disablePreviousSteps', Em.K);
  210. c.set('registrationStartedAt', {});
  211. c.loadStep();
  212. expect(c.get('registrationStartedAt')).to.be.null;
  213. });
  214. it('should set isLoaded to false', function() {
  215. c.set('disablePreviousSteps', Em.K);
  216. c.set('clearStep', Em.K);
  217. c.set('loadHosts', Em.K);
  218. c.set('isLoaded', true);
  219. c.loadStep();
  220. expect(c.get('isLoaded')).to.equal(false);
  221. });
  222. it('should call clearStep', function() {
  223. c.set('disablePreviousSteps', Em.K);
  224. c.set('loadHosts', Em.K);
  225. sinon.spy(c, 'clearStep');
  226. c.loadStep();
  227. expect(c.get('clearStep').calledOnce).to.equal(true);
  228. c.clearStep.restore();
  229. });
  230. it('should call loadHosts', function() {
  231. c.set('disablePreviousSteps', Em.K);
  232. c.set('loadHosts', Em.K);
  233. sinon.spy(c, 'loadHosts');
  234. c.loadStep();
  235. expect(c.get('loadHosts').calledOnce).to.equal(true);
  236. c.loadHosts.restore();
  237. });
  238. it('should call disablePreviousSteps', function() {
  239. c.set('disablePreviousSteps', Em.K);
  240. c.set('loadHosts', Em.K);
  241. sinon.spy(c, 'disablePreviousSteps');
  242. c.loadStep();
  243. expect(c.get('disablePreviousSteps').calledOnce).to.equal(true);
  244. c.disablePreviousSteps.restore();
  245. });
  246. });
  247. describe('#loadHosts', function() {
  248. it('should set isLoaded to true', function() {
  249. c.set('navigateStep', Em.K);
  250. c.set('content', {hosts: {}});
  251. c.loadHosts();
  252. expect(c.get('isLoaded')).to.equal(true);
  253. });
  254. it('should set bootStatus REGISTERED on testMode', function() {
  255. App.testMode = true;
  256. c.set('navigateStep', Em.K);
  257. c.set('content', {hosts: {c: {name: 'name'}}});
  258. c.loadHosts();
  259. expect(c.get('hosts').everyProperty('bootStatus', 'REGISTERED')).to.equal(true);
  260. });
  261. it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function() {
  262. App.testMode = false;
  263. c.set('navigateStep', Em.K);
  264. c.set('content', {installOptions:{manualInstall: true}, hosts: {c: {name: 'name'}}});
  265. c.loadHosts();
  266. expect(c.get('hosts').everyProperty('bootStatus', 'DONE')).to.equal(true);
  267. App.testMode = true;
  268. });
  269. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  270. App.testMode = false;
  271. c.set('navigateStep', Em.K);
  272. c.set('content', {installOptions:{manualInstall: false}, hosts: {c: {name: 'name'}}});
  273. c.loadHosts();
  274. expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
  275. App.testMode = true;
  276. });
  277. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  278. c.set('navigateStep', Em.K);
  279. c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
  280. c.loadHosts();
  281. expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
  282. });
  283. });
  284. describe('#parseHostInfo', function() {
  285. var tests = Em.A([
  286. {
  287. bootHosts: Em.A([
  288. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  289. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  290. Em.Object.create({name: 'c3', bootStatus: 'RUNNING', bootLog: ''})
  291. ]),
  292. hostsStatusFromServer: Em.A([
  293. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  294. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  295. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  296. ]),
  297. m: 'bootHosts not empty, hostsStatusFromServer not empty, one is RUNNING',
  298. e: {
  299. c: true,
  300. r: true
  301. }
  302. },
  303. {
  304. bootHosts: Em.A([]),
  305. hostsStatusFromServer: Em.A([
  306. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  307. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  308. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  309. ]),
  310. m: 'bootHosts is empty',
  311. e: {
  312. c: false,
  313. r: false
  314. }
  315. },
  316. {
  317. bootHosts: Em.A([
  318. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  319. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  320. Em.Object.create({name: 'c3', bootStatus: 'REGISTERED', bootLog: ''})
  321. ]),
  322. hostsStatusFromServer: Em.A([
  323. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  324. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  325. {hostName: 'c3', status: 'REGISTERED', log: 'c3'}
  326. ]),
  327. m: 'bootHosts not empty, hostsStatusFromServer not empty, no one is RUNNING',
  328. e: {
  329. c: true,
  330. r: false
  331. }
  332. }
  333. ]);
  334. tests.forEach(function(test) {
  335. it(test.m, function() {
  336. c.set('bootHosts', test.bootHosts);
  337. var r = c.parseHostInfo(test.hostsStatusFromServer);
  338. expect(r).to.equal(test.e.r);
  339. if (test.e.c) {
  340. test.hostsStatusFromServer.forEach(function(h) {
  341. var r = c.get('bootHosts').findProperty('name', h.hostName);
  342. if (!['REGISTERED', 'REGISTERING'].contains(r.get('bootStatus'))) {
  343. expect(r.get('bootStatus')).to.equal(h.status);
  344. expect(r.get('bootLog')).to.equal(h.log);
  345. }
  346. });
  347. }
  348. });
  349. });
  350. });
  351. describe('#removeHosts', function() {
  352. it('should call App.showConfirmationPopup', function() {
  353. sinon.spy(App, 'showConfirmationPopup');
  354. c.removeHosts(Em.A([]));
  355. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  356. App.showConfirmationPopup.restore();
  357. });
  358. it('primary should disable Submit if no more hosts', function() {
  359. var hosts = [{}];
  360. c.set('hosts', hosts);
  361. var popup = c.removeHosts(hosts);
  362. popup.onPrimary();
  363. expect(c.get('isSubmitDisabled')).to.equal(true);
  364. });
  365. });
  366. describe('#removeHost', function() {
  367. it('should call removeHosts with array as arg', function() {
  368. var host = {a:''};
  369. sinon.spy(c, 'removeHosts');
  370. c.removeHost(host);
  371. expect(c.removeHosts.calledWith([host]));
  372. c.removeHosts.restore();
  373. });
  374. });
  375. describe('#removeSelectedHosts', function() {
  376. it('should remove selected hosts', function() {
  377. c = App.WizardStep3Controller.create({
  378. wizardController: App.InstallerController.create(),
  379. hosts: [
  380. {isChecked: true, name: 'c1'},
  381. {isChecked: false, name: 'c2'}
  382. ]
  383. });
  384. c.removeSelectedHosts().onPrimary();
  385. expect(c.get('hosts').mapProperty('name')).to.eql(['c2']);
  386. });
  387. });
  388. describe('#selectedHostsPopup', function() {
  389. it('should show App.ModalPopup', function() {
  390. sinon.spy(App.ModalPopup, 'show');
  391. c.selectedHostsPopup();
  392. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  393. App.ModalPopup.show.restore();
  394. });
  395. });
  396. describe('#retryHosts', function() {
  397. it('should set numPolls to 0', function() {
  398. var s = sinon.stub(App.router, 'get', function() {
  399. return {launchBootstrap: Em.K}
  400. });
  401. c.set('content', {installOptions: {}});
  402. c.set('doBootstrap', Em.K);
  403. c.set('numPolls', 123);
  404. c.retryHosts(Em.A([]));
  405. expect(c.get('numPolls')).to.equal(0);
  406. s.restore();
  407. });
  408. it('should set registrationStartedAt to null', function() {
  409. var s = sinon.stub(App.router, 'get', function() {
  410. return {launchBootstrap: Em.K}
  411. });
  412. c.set('content', {installOptions: {}});
  413. c.set('doBootstrap', Em.K);
  414. c.retryHosts(Em.A([]));
  415. expect(c.get('registrationStartedAt')).to.be.null;
  416. s.restore();
  417. });
  418. it('should startRegistration if installOptions.manualInstall is true', function() {
  419. var s = sinon.stub(App.router, 'get', function() {
  420. return {launchBootstrap: Em.K}
  421. });
  422. sinon.spy(c, 'startRegistration');
  423. c.set('content', {installOptions: {manualInstall: true}});
  424. c.set('doBootstrap', Em.K);
  425. c.retryHosts(Em.A([]));
  426. expect(c.startRegistration.calledOnce).to.equal(true);
  427. s.restore();
  428. c.startRegistration.restore();
  429. });
  430. it('should doBootstrap if installOptions.manualInstall is false', function() {
  431. var s = sinon.stub(App.router, 'get', function() {
  432. return {launchBootstrap: Em.K}
  433. });
  434. c.set('content', {installOptions: {manualInstall: false}});
  435. c.set('doBootstrap', Em.K);
  436. sinon.spy(c, 'doBootstrap');
  437. c.retryHosts(Em.A([]));
  438. expect(c.doBootstrap.calledOnce).to.equal(true);
  439. s.restore();
  440. c.doBootstrap.restore();
  441. });
  442. });
  443. describe('#retryHost', function() {
  444. it('should callretryHosts with array as arg', function() {
  445. var host = {n: 'c'}, s = sinon.stub(App.router, 'get', function() {
  446. return {launchBootstrap: Em.K}
  447. });
  448. sinon.spy(c, 'retryHosts');
  449. c.set('content', {installOptions: {}});
  450. c.set('doBootstrap', Em.K);
  451. c.retryHost(host);
  452. expect(c.retryHosts.calledWith([host])).to.equal(true);
  453. c.retryHosts.restore();
  454. s.restore();
  455. });
  456. });
  457. describe('#retrySelectedHosts', function() {
  458. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  459. c.set('isRetryDisabled', true);
  460. sinon.spy(c, 'retryHosts');
  461. c.retrySelectedHosts();
  462. expect(c.retryHosts.called).to.equal(false);
  463. c.retryHosts.restore();
  464. });
  465. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  466. var s = sinon.stub(App.router, 'get', function() {
  467. return {launchBootstrap: Em.K}
  468. });
  469. c = App.WizardStep3Controller.create({
  470. wizardController: App.InstallerController.create(),
  471. bootHosts: Em.A([{name: 'c1', bootStatus: 'FAILED'}, {name: 'c2', bootStatus: 'REGISTERED'}]),
  472. content: {installOptions: {}},
  473. doBootstrap: Em.K
  474. });
  475. sinon.spy(c, 'retryHosts');
  476. c.retrySelectedHosts();
  477. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  478. expect(c.get('isRetryDisabled')).to.equal(true);
  479. c.retryHosts.restore();
  480. s.restore();
  481. });
  482. });
  483. describe('#startBootstrap', function() {
  484. it('should drop numPolls and registrationStartedAt', function() {
  485. c.set('numPolls', 123);
  486. c.set('registrationStartedAt', 1234);
  487. c.set('doBootstrap', Em.K);
  488. c.startBootstrap();
  489. expect(c.get('numPolls')).to.equal(0);
  490. expect(c.get('registrationStartedAt')).to.be.null;
  491. });
  492. it('should drop numPolls and registrationStartedAt', function() {
  493. var hosts = Em.A([{name: 'c1'}, {name: 'c2'}]);
  494. c = App.WizardStep3Controller.create({
  495. wizardController: App.InstallerController.create(),
  496. doBootstrap: Em.K,
  497. setRegistrationInProgressOnce: Em.K,
  498. hosts: hosts
  499. });
  500. c.startBootstrap();
  501. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  502. });
  503. });
  504. describe('#setRegistrationInProgressOnce', function() {
  505. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  506. sinon.spy(Em.run, 'once');
  507. c.setRegistrationInProgressOnce();
  508. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  509. Em.run.once.restore();
  510. });
  511. });
  512. describe('#setRegistrationInProgress', function() {
  513. var tests = Em.A([
  514. {
  515. bootHosts: [],
  516. isLoaded: false,
  517. e: true,
  518. m: 'no bootHosts and isLoaded is false'
  519. },
  520. {
  521. bootHosts: [],
  522. isLoaded: true,
  523. e: false,
  524. m: 'no bootHosts and isLoaded is true'
  525. },
  526. {
  527. bootHosts: [
  528. Em.Object.create({bootStatus: 'RUNNING'}),
  529. Em.Object.create({bootStatus: 'RUNNING'})
  530. ],
  531. isLoaded: true,
  532. e: false,
  533. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  534. },
  535. {
  536. bootHosts: [
  537. Em.Object.create({bootStatus: 'RUNNING'}),
  538. Em.Object.create({bootStatus: 'RUNNING'})
  539. ],
  540. isLoaded: false,
  541. e: true,
  542. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  543. },
  544. {
  545. bootHosts: [
  546. Em.Object.create({bootStatus: 'REGISTERED'}),
  547. Em.Object.create({bootStatus: 'RUNNING'})
  548. ],
  549. isLoaded: false,
  550. e: true,
  551. m: 'bootHosts with one REGISTERED and isLoaded is false'
  552. },
  553. {
  554. bootHosts: [
  555. Em.Object.create({bootStatus: 'FAILED'}),
  556. Em.Object.create({bootStatus: 'RUNNING'})
  557. ],
  558. isLoaded: false,
  559. e: true,
  560. m: 'bootHosts with one FAILED and isLoaded is false'
  561. },
  562. {
  563. bootHosts: [
  564. Em.Object.create({bootStatus: 'REGISTERED'}),
  565. Em.Object.create({bootStatus: 'RUNNING'})
  566. ],
  567. isLoaded: true,
  568. e: false,
  569. m: 'bootHosts with one REGISTERED and isLoaded is true'
  570. },
  571. {
  572. bootHosts: [
  573. Em.Object.create({bootStatus: 'FAILED'}),
  574. Em.Object.create({bootStatus: 'RUNNING'})
  575. ],
  576. isLoaded: true,
  577. e: false,
  578. m: 'bootHosts with one FAILED and isLoaded is true'
  579. }
  580. ]);
  581. tests.forEach(function(test) {
  582. it(test.m, function() {
  583. sinon.stub(c, 'disablePreviousSteps', Em.K);
  584. c.set('bootHosts', test.bootHosts);
  585. c.set('isLoaded', test.isLoaded);
  586. c.setRegistrationInProgress();
  587. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  588. c.disablePreviousSteps.restore();
  589. });
  590. });
  591. });
  592. describe('#doBootstrap', function() {
  593. beforeEach(function() {
  594. sinon.spy(App.ajax, 'send');
  595. });
  596. afterEach(function() {
  597. App.ajax.send.restore();
  598. });
  599. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  600. c.set('stopBootstrap', true);
  601. c.doBootstrap();
  602. expect(App.ajax.send.called).to.equal(false);
  603. });
  604. it('should increment numPolls if stopBootstrap is false', function() {
  605. c.set('stopBootstrap', false);
  606. c.set('numPolls', 0);
  607. c.doBootstrap();
  608. expect(c.get('numPolls')).to.equal(1);
  609. });
  610. it('should do ajax call if stopBootstrap is false', function() {
  611. c.set('stopBootstrap', false);
  612. c.doBootstrap();
  613. expect(App.ajax.send.called).to.equal(true);
  614. });
  615. });
  616. describe('#startRegistration', function() {
  617. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  618. c.set('registrationStartedAt', 1234);
  619. sinon.spy(c, 'isHostsRegistered');
  620. c.startRegistration();
  621. expect(c.isHostsRegistered.called).to.equal(false);
  622. expect(c.get('registrationStartedAt')).to.equal(1234);
  623. c.isHostsRegistered.restore();
  624. });
  625. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  626. c.set('registrationStartedAt', null);
  627. sinon.spy(c, 'isHostsRegistered');
  628. c.startRegistration();
  629. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  630. c.isHostsRegistered.restore();
  631. });
  632. });
  633. describe('#isHostsRegistered', function() {
  634. beforeEach(function() {
  635. sinon.spy(App.ajax, 'send');
  636. });
  637. afterEach(function() {
  638. App.ajax.send.restore();
  639. });
  640. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  641. c.set('stopBootstrap', true);
  642. c.isHostsRegistered();
  643. expect(App.ajax.send.called).to.equal(false);
  644. });
  645. it('should do ajax call if stopBootstrap is false', function() {
  646. c.set('stopBootstrap', false);
  647. c.isHostsRegistered();
  648. expect(App.ajax.send.called).to.equal(true);
  649. });
  650. });
  651. describe('#isHostsRegisteredSuccessCallback', function() {
  652. var tests = Em.A([
  653. {
  654. bootHosts: Em.A([
  655. Em.Object.create({bootStatus: 'DONE'})
  656. ]),
  657. data: {items:[]},
  658. m: 'one host DONE',
  659. e: {
  660. bs: 'REGISTERING',
  661. getHostInfoCalled: false
  662. }
  663. },
  664. {
  665. bootHosts: Em.A([
  666. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  667. ]),
  668. data: {items:[{Hosts: {host_name: 'c1'}}]},
  669. m: ' one host REGISTERING',
  670. e: {
  671. bs: 'FAILED',
  672. getHostInfoCalled: true
  673. }
  674. },
  675. {
  676. bootHosts: Em.A([
  677. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  678. ]),
  679. data: {items:[{Hosts: {host_name: 'c2'}}]},
  680. m: 'one host REGISTERING but data without info about it',
  681. e: {
  682. bs: 'FAILED',
  683. getHostInfoCalled: true
  684. }
  685. },
  686. {
  687. bootHosts: Em.A([
  688. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  689. ]),
  690. data: {items:[{Hosts: {host_name: 'c1'}}]},
  691. m: ' one host RUNNING',
  692. e: {
  693. bs: 'RUNNING',
  694. getHostInfoCalled: false
  695. }
  696. }
  697. ]);
  698. tests.forEach(function(test) {
  699. it(test.m, function() {
  700. sinon.spy(c, 'getHostInfo');
  701. c.set('bootHosts', test.bootHosts);
  702. c.isHostsRegisteredSuccessCallback(test.data);
  703. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  704. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  705. c.getHostInfo.restore();
  706. });
  707. });
  708. });
  709. describe('#getAllRegisteredHosts', function() {
  710. it('should call App.ajax.send', function() {
  711. sinon.spy(App.ajax, 'send');
  712. c.getAllRegisteredHosts();
  713. expect(App.ajax.send.calledOnce).to.equal(true);
  714. App.ajax.send.restore();
  715. });
  716. });
  717. describe('#getAllRegisteredHostsCallback', function() {
  718. var tests = Em.A([
  719. {
  720. hostsInCluster: ['c3'],
  721. bootHosts: [{name:'c1'},{name:'c2'}],
  722. hosts: Em.A([
  723. {Hosts: {host_name:'c1'}},
  724. {Hosts: {host_name:'c2'}}
  725. ]),
  726. m: 'No registered hosts',
  727. e: {
  728. hasMoreRegisteredHosts: false,
  729. registeredHosts: ''
  730. }
  731. },
  732. {
  733. hostsInCluster: ['c4'],
  734. bootHosts: [{name:'c3'},{name:'c5'}],
  735. hosts: Em.A([
  736. {Hosts: {host_name:'c1'}},
  737. {Hosts: {host_name:'c2'}}
  738. ]),
  739. m: '2 registered hosts',
  740. e: {
  741. hasMoreRegisteredHosts: true,
  742. registeredHosts: ['c1','c2']
  743. }
  744. },
  745. {
  746. hostsInCluster: ['c4'],
  747. bootHosts: [{name:'c1'},{name:'c5'}],
  748. hosts: Em.A([
  749. {Hosts: {host_name:'c1'}},
  750. {Hosts: {host_name:'c2'}}
  751. ]),
  752. m: '1 registered host',
  753. e: {
  754. hasMoreRegisteredHosts: true,
  755. registeredHosts: ['c2']
  756. }
  757. },
  758. {
  759. hostsInCluster: ['c1'],
  760. bootHosts: [{name:'c3'},{name:'c5'}],
  761. hosts: Em.A([
  762. {Hosts: {host_name:'c1'}},
  763. {Hosts: {host_name:'c2'}}
  764. ]),
  765. m: '1 registered host (2)',
  766. e: {
  767. hasMoreRegisteredHosts: true,
  768. registeredHosts: ['c2']
  769. }
  770. }
  771. ]);
  772. tests.forEach(function(test) {
  773. it(test.m, function() {
  774. c.reopen({hostsInCluster: test.hostsInCluster, setRegistrationInProgress: Em.K});
  775. c.set('bootHosts', test.bootHosts);
  776. c.getAllRegisteredHostsCallback({items:test.hosts});
  777. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  778. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  779. });
  780. });
  781. });
  782. describe('#registerErrPopup', function() {
  783. it('should call App.ModalPopup.show', function() {
  784. sinon.spy(App.ModalPopup, 'show');
  785. c.registerErrPopup();
  786. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  787. App.ModalPopup.show.restore();
  788. });
  789. });
  790. describe('#getHostInfo', function() {
  791. it('should do ajax request', function() {
  792. sinon.spy(App.ajax, 'send');
  793. c.getHostInfo();
  794. expect(App.ajax.send.calledOnce).to.equal(true);
  795. App.ajax.send.restore();
  796. });
  797. });
  798. describe('#getHostInfoErrorCallback', function() {
  799. it('should call registerErrPopup', function() {
  800. sinon.spy(c, 'registerErrPopup');
  801. c.getHostInfoErrorCallback();
  802. expect(c.registerErrPopup.calledOnce).to.equal(true);
  803. c.registerErrPopup.restore();
  804. });
  805. });
  806. describe('#stopRegistration', function() {
  807. var tests = Em.A([
  808. {
  809. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  810. e: {isSubmitDisabled: false, isRetryDisabled: true}
  811. },
  812. {
  813. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  814. e: {isSubmitDisabled: true, isRetryDisabled: false}
  815. },
  816. {
  817. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  818. e: {isSubmitDisabled: false, isRetryDisabled: false}
  819. },
  820. {
  821. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  822. e: {isSubmitDisabled: true, isRetryDisabled: true}
  823. }
  824. ]);
  825. tests.forEach(function(test) {
  826. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  827. c.reopen({bootHosts: test.bootHosts});
  828. c.stopRegistration();
  829. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  830. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  831. });
  832. });
  833. });
  834. describe('#submit', function() {
  835. it('if isHostHaveWarnings should show confirmation popup', function() {
  836. c.reopen({isHostHaveWarnings: true});
  837. sinon.spy(App.ModalPopup, 'show');
  838. c.submit();
  839. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  840. App.ModalPopup.show.restore();
  841. });
  842. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  843. var bootHosts = [{name: 'c1'}];
  844. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  845. c.submit().onPrimary();
  846. expect(c.get('content.hosts')).to.eql(bootHosts);
  847. });
  848. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  849. var bootHosts = [{name: 'c1'}];
  850. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  851. c.submit();
  852. expect(c.get('content.hosts')).to.eql(bootHosts);
  853. });
  854. });
  855. describe('#hostLogPopup', function() {
  856. it('should show App.ModalPopup', function() {
  857. sinon.spy(App.ModalPopup, 'show');
  858. c.hostLogPopup({context:Em.Object.create({})});
  859. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  860. App.ModalPopup.show.restore();
  861. });
  862. });
  863. describe('#rerunChecksSuccessCallback', function() {
  864. beforeEach(function() {
  865. sinon.stub(c, 'parseWarnings', Em.K);
  866. });
  867. afterEach(function() {
  868. c.parseWarnings.restore();
  869. });
  870. it('should set checksUpdateProgress to 100', function() {
  871. c.set('checksUpdateProgress', 0);
  872. c.rerunChecksSuccessCallback({});
  873. expect(c.get('checksUpdateProgress')).to.equal(100);
  874. });
  875. it('should set checksUpdateStatus to SUCCESS', function() {
  876. c.set('checksUpdateStatus', '');
  877. c.rerunChecksSuccessCallback({});
  878. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  879. });
  880. it('should set call parseWarnings', function() {
  881. c.rerunChecksSuccessCallback({});
  882. expect(c.parseWarnings.calledOnce).to.equal(true);
  883. });
  884. });
  885. describe('#rerunChecksErrorCallback', function() {
  886. it('should set checksUpdateProgress to 100', function() {
  887. c.set('checksUpdateProgress', 0);
  888. c.rerunChecksErrorCallback({});
  889. expect(c.get('checksUpdateProgress')).to.equal(100);
  890. });
  891. it('should set checksUpdateStatus to FAILED', function() {
  892. c.set('checksUpdateStatus', '');
  893. c.rerunChecksErrorCallback({});
  894. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  895. });
  896. });
  897. describe('#filterBootHosts', function() {
  898. var tests = Em.A([
  899. {
  900. bootHosts: [
  901. Em.Object.create({name: 'c1'}),
  902. Em.Object.create({name: 'c2'})
  903. ],
  904. data: {
  905. items: [
  906. {Hosts: {host_name: 'c1'}}
  907. ]
  908. },
  909. m: 'one host',
  910. e: ['c1']
  911. },
  912. {
  913. bootHosts: [
  914. Em.Object.create({name: 'c1'}),
  915. Em.Object.create({name: 'c2'})
  916. ],
  917. data: {
  918. items: [
  919. {Hosts: {host_name: 'c3'}}
  920. ]
  921. },
  922. m: 'no hosts',
  923. e: []
  924. },
  925. {
  926. bootHosts: [
  927. Em.Object.create({name: 'c1'}),
  928. Em.Object.create({name: 'c2'})
  929. ],
  930. data: {
  931. items: [
  932. {Hosts: {host_name: 'c1'}},
  933. {Hosts: {host_name: 'c2'}}
  934. ]
  935. },
  936. m: 'many hosts',
  937. e: ['c1', 'c2']
  938. }
  939. ]);
  940. tests.forEach(function(test) {
  941. it(test.m, function() {
  942. c.reopen({bootHosts: test.bootHosts});
  943. var filteredData = c.filterBootHosts(test.data);
  944. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  945. });
  946. });
  947. });
  948. describe('#hostWarningsPopup', function() {
  949. it('should show App.ModalPopup', function() {
  950. sinon.spy(App.ModalPopup, 'show');
  951. c.hostWarningsPopup();
  952. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  953. App.ModalPopup.show.restore();
  954. });
  955. });
  956. describe('#registeredHostsPopup', function() {
  957. it('should show App.ModalPopup', function() {
  958. sinon.spy(App.ModalPopup, 'show');
  959. c.registeredHostsPopup();
  960. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  961. App.ModalPopup.show.restore();
  962. });
  963. });
  964. describe('#parseWarnings', function() {
  965. it('no warnings if last_agent_env isn\'t specified', function() {
  966. c.set('warnings', [{}]);
  967. c.set('warningsByHost', [{},{}]);
  968. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  969. expect(c.get('warnings')).to.eql([]);
  970. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  971. expect(c.get('isWarningsLoaded')).to.equal(true);
  972. });
  973. Em.A([
  974. {
  975. m: 'parse stackFoldersAndFiles',
  976. tests : Em.A([
  977. {
  978. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  979. m: 'empty stackFoldersAndFiles',
  980. e: {
  981. warnings: [],
  982. warningsByHost: [0]
  983. }
  984. },
  985. {
  986. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  987. m: 'not empty stackFoldersAndFiles',
  988. e: {
  989. warnings: [{
  990. name: 'n1',
  991. hosts: ['c1'],
  992. onSingleHost: true,
  993. category: 'fileFolders'
  994. }],
  995. warningsByHost: [1]
  996. }
  997. },
  998. {
  999. items: [
  1000. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1001. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1002. ],
  1003. m: 'not empty stackFoldersAndFiles on two hosts',
  1004. e: {
  1005. warnings: [{
  1006. name: 'n1',
  1007. hosts: ['c1', 'c2'],
  1008. onSingleHost: false,
  1009. category: 'fileFolders'
  1010. }],
  1011. warningsByHost: [1]
  1012. }
  1013. }
  1014. ])
  1015. },
  1016. {
  1017. m: 'parse installedPackages',
  1018. tests : Em.A([
  1019. {
  1020. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1021. m: 'empty installedPackages',
  1022. e: {
  1023. warnings: [],
  1024. warningsByHost: [0]
  1025. }
  1026. },
  1027. {
  1028. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1029. m: 'not empty installedPackages',
  1030. e: {
  1031. warnings: [{
  1032. name: 'n1',
  1033. hosts: ['c1'],
  1034. onSingleHost: true,
  1035. category: 'packages'
  1036. }],
  1037. warningsByHost: [1]
  1038. }
  1039. },
  1040. {
  1041. items: [
  1042. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1043. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1044. ],
  1045. m: 'not empty installedPackages on two hosts',
  1046. e: {
  1047. warnings: [{
  1048. name: 'n1',
  1049. hosts: ['c1', 'c2'],
  1050. onSingleHost: false,
  1051. category: 'packages'
  1052. }],
  1053. warningsByHost: [1]
  1054. }
  1055. }
  1056. ])
  1057. },
  1058. {
  1059. m: 'parse hostHealth.liveServices',
  1060. tests : Em.A([
  1061. {
  1062. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1063. m: 'empty hostHealth',
  1064. e: {
  1065. warnings: [],
  1066. warningsByHost: [0]
  1067. }
  1068. },
  1069. {
  1070. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1071. m: 'empty liveServices',
  1072. e: {
  1073. warnings: [],
  1074. warningsByHost: [0]
  1075. }
  1076. },
  1077. {
  1078. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1079. m: 'not empty hostHealth.liveServices',
  1080. e: {
  1081. warnings: [{
  1082. name: 'n1',
  1083. hosts: ['c1'],
  1084. onSingleHost: true,
  1085. category: 'services'
  1086. }],
  1087. warningsByHost: [1]
  1088. }
  1089. },
  1090. {
  1091. items: [
  1092. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1093. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1094. ],
  1095. m: 'not empty hostHealth.liveServices on two hosts',
  1096. e: {
  1097. warnings: [{
  1098. name: 'n1',
  1099. hosts: ['c1', 'c2'],
  1100. onSingleHost: false,
  1101. category: 'services'
  1102. }],
  1103. warningsByHost: [1, 1]
  1104. }
  1105. }
  1106. ])
  1107. },
  1108. {
  1109. m: 'parse existingUsers',
  1110. tests : Em.A([
  1111. {
  1112. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1113. m: 'empty existingUsers',
  1114. e: {
  1115. warnings: [],
  1116. warningsByHost: [0]
  1117. }
  1118. },
  1119. {
  1120. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1121. m: 'not empty existingUsers',
  1122. e: {
  1123. warnings: [{
  1124. name: 'n1',
  1125. hosts: ['c1'],
  1126. onSingleHost: true,
  1127. category: 'users'
  1128. }],
  1129. warningsByHost: [1]
  1130. }
  1131. },
  1132. {
  1133. items: [
  1134. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1135. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1136. ],
  1137. m: 'not empty existingUsers on two hosts',
  1138. e: {
  1139. warnings: [{
  1140. name: 'n1',
  1141. hosts: ['c1', 'c2'],
  1142. onSingleHost: false,
  1143. category: 'users'
  1144. }],
  1145. warningsByHost: [1, 1]
  1146. }
  1147. }
  1148. ])
  1149. },
  1150. {
  1151. m: 'parse alternatives',
  1152. tests : Em.A([
  1153. {
  1154. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1155. m: 'empty alternatives',
  1156. e: {
  1157. warnings: [],
  1158. warningsByHost: [0]
  1159. }
  1160. },
  1161. {
  1162. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1163. m: 'not empty alternatives',
  1164. e: {
  1165. warnings: [{
  1166. name: 'n1',
  1167. hosts: ['c1'],
  1168. onSingleHost: true,
  1169. category: 'alternatives'
  1170. }],
  1171. warningsByHost: [1]
  1172. }
  1173. },
  1174. {
  1175. items: [
  1176. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1177. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1178. ],
  1179. m: 'not empty alternatives on two hosts',
  1180. e: {
  1181. warnings: [{
  1182. name: 'n1',
  1183. hosts: ['c1', 'c2'],
  1184. onSingleHost: false,
  1185. category: 'alternatives'
  1186. }],
  1187. warningsByHost: [1, 1]
  1188. }
  1189. }
  1190. ])
  1191. },
  1192. {
  1193. m: 'parse hostHealth.activeJavaProcs',
  1194. tests : Em.A([
  1195. {
  1196. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1197. m: 'empty hostHealth',
  1198. e: {
  1199. warnings: [],
  1200. warningsByHost: [0]
  1201. }
  1202. },
  1203. {
  1204. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1205. m: 'empty activeJavaProcs',
  1206. e: {
  1207. warnings: [],
  1208. warningsByHost: [0]
  1209. }
  1210. },
  1211. {
  1212. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1213. m: 'not empty hostHealth.activeJavaProcs',
  1214. e: {
  1215. warnings: [{
  1216. pid: 'n1',
  1217. hosts: ['c1'],
  1218. onSingleHost: true,
  1219. category: 'processes'
  1220. }],
  1221. warningsByHost: [1]
  1222. }
  1223. },
  1224. {
  1225. items: [
  1226. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1227. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1228. ],
  1229. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1230. e: {
  1231. warnings: [{
  1232. pid: 'n1',
  1233. hosts: ['c1', 'c2'],
  1234. onSingleHost: false,
  1235. category: 'processes'
  1236. }],
  1237. warningsByHost: [1, 1]
  1238. }
  1239. }
  1240. ])
  1241. }
  1242. ]).forEach(function(category) {
  1243. describe(category.m, function() {
  1244. category.tests.forEach(function(test) {
  1245. it(test.m, function() {
  1246. c.parseWarnings({items: test.items});
  1247. c.get('warnings').forEach(function(w, i) {
  1248. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1249. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1250. });
  1251. });
  1252. for(var i in test.e.warningsByHost) {
  1253. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1254. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1255. }
  1256. }
  1257. });
  1258. });
  1259. });
  1260. });
  1261. });
  1262. });