step3_test.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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. var s;
  398. var installer = {launchBootstrap: Em.K};
  399. beforeEach(function () {
  400. sinon.spy(installer, "launchBootstrap");
  401. s = sinon.stub(App.router, 'get', function () {
  402. return installer;
  403. });
  404. sinon.stub(c, 'doBootstrap', Em.K);
  405. });
  406. afterEach(function () {
  407. c.doBootstrap.restore();
  408. s.restore();
  409. installer.launchBootstrap.restore();
  410. });
  411. it('should set numPolls to 0', function () {
  412. c.set('content', {installOptions: {}});
  413. c.set('numPolls', 123);
  414. c.retryHosts(Em.A([]));
  415. expect(c.get('numPolls')).to.equal(0);
  416. });
  417. it('should set registrationStartedAt to null', function () {
  418. c.set('content', {installOptions: {}});
  419. c.retryHosts(Em.A([]));
  420. expect(c.get('registrationStartedAt')).to.be.null;
  421. });
  422. it('should startRegistration if installOptions.manualInstall is true', function () {
  423. sinon.spy(c, 'startRegistration');
  424. c.set('content', {installOptions: {manualInstall: true}});
  425. c.retryHosts(Em.A([]));
  426. expect(c.startRegistration.calledOnce).to.equal(true);
  427. c.startRegistration.restore();
  428. });
  429. it('should launchBootstrap if installOptions.manualInstall is false', function () {
  430. c.set('content', {installOptions: {manualInstall: false}});
  431. c.retryHosts(Em.A([]));
  432. expect(installer.launchBootstrap.calledOnce).to.be.true;
  433. });
  434. });
  435. describe('#retryHost', function() {
  436. it('should callretryHosts with array as arg', function() {
  437. var host = {n: 'c'}, s = sinon.stub(App.router, 'get', function() {
  438. return {launchBootstrap: Em.K}
  439. });
  440. sinon.spy(c, 'retryHosts');
  441. c.set('content', {installOptions: {}});
  442. c.set('doBootstrap', Em.K);
  443. c.retryHost(host);
  444. expect(c.retryHosts.calledWith([host])).to.equal(true);
  445. c.retryHosts.restore();
  446. s.restore();
  447. });
  448. });
  449. describe('#retrySelectedHosts', function() {
  450. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  451. c.set('isRetryDisabled', true);
  452. sinon.spy(c, 'retryHosts');
  453. c.retrySelectedHosts();
  454. expect(c.retryHosts.called).to.equal(false);
  455. c.retryHosts.restore();
  456. });
  457. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  458. var s = sinon.stub(App.router, 'get', function() {
  459. return {launchBootstrap: Em.K}
  460. });
  461. c = App.WizardStep3Controller.create({
  462. wizardController: App.InstallerController.create(),
  463. isRetryDisabled: false,
  464. bootHosts: Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]),
  465. content: {installOptions: {}},
  466. doBootstrap: Em.K
  467. });
  468. sinon.spy(c, 'retryHosts');
  469. c.retrySelectedHosts();
  470. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  471. expect(c.get('isRetryDisabled')).to.equal(true);
  472. c.retryHosts.restore();
  473. s.restore();
  474. });
  475. });
  476. describe('#startBootstrap', function() {
  477. it('should drop numPolls and registrationStartedAt', function() {
  478. c.set('numPolls', 123);
  479. c.set('registrationStartedAt', 1234);
  480. c.set('doBootstrap', Em.K);
  481. c.startBootstrap();
  482. expect(c.get('numPolls')).to.equal(0);
  483. expect(c.get('registrationStartedAt')).to.be.null;
  484. });
  485. it('should drop numPolls and registrationStartedAt', function() {
  486. var hosts = Em.A([{name: 'c1'}, {name: 'c2'}]);
  487. c = App.WizardStep3Controller.create({
  488. wizardController: App.InstallerController.create(),
  489. doBootstrap: Em.K,
  490. setRegistrationInProgressOnce: Em.K,
  491. hosts: hosts
  492. });
  493. c.startBootstrap();
  494. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  495. });
  496. });
  497. describe('#setRegistrationInProgressOnce', function() {
  498. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  499. sinon.spy(Em.run, 'once');
  500. c.setRegistrationInProgressOnce();
  501. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  502. Em.run.once.restore();
  503. });
  504. });
  505. describe('#setRegistrationInProgress', function() {
  506. var tests = Em.A([
  507. {
  508. bootHosts: [],
  509. isLoaded: false,
  510. e: true,
  511. m: 'no bootHosts and isLoaded is false'
  512. },
  513. {
  514. bootHosts: [],
  515. isLoaded: true,
  516. e: false,
  517. m: 'no bootHosts and isLoaded is true'
  518. },
  519. {
  520. bootHosts: [
  521. Em.Object.create({bootStatus: 'RUNNING'}),
  522. Em.Object.create({bootStatus: 'RUNNING'})
  523. ],
  524. isLoaded: true,
  525. e: false,
  526. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  527. },
  528. {
  529. bootHosts: [
  530. Em.Object.create({bootStatus: 'RUNNING'}),
  531. Em.Object.create({bootStatus: 'RUNNING'})
  532. ],
  533. isLoaded: false,
  534. e: true,
  535. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  536. },
  537. {
  538. bootHosts: [
  539. Em.Object.create({bootStatus: 'REGISTERED'}),
  540. Em.Object.create({bootStatus: 'RUNNING'})
  541. ],
  542. isLoaded: false,
  543. e: true,
  544. m: 'bootHosts with one REGISTERED and isLoaded is false'
  545. },
  546. {
  547. bootHosts: [
  548. Em.Object.create({bootStatus: 'FAILED'}),
  549. Em.Object.create({bootStatus: 'RUNNING'})
  550. ],
  551. isLoaded: false,
  552. e: true,
  553. m: 'bootHosts with one FAILED and isLoaded is false'
  554. },
  555. {
  556. bootHosts: [
  557. Em.Object.create({bootStatus: 'REGISTERED'}),
  558. Em.Object.create({bootStatus: 'RUNNING'})
  559. ],
  560. isLoaded: true,
  561. e: false,
  562. m: 'bootHosts with one REGISTERED and isLoaded is true'
  563. },
  564. {
  565. bootHosts: [
  566. Em.Object.create({bootStatus: 'FAILED'}),
  567. Em.Object.create({bootStatus: 'RUNNING'})
  568. ],
  569. isLoaded: true,
  570. e: false,
  571. m: 'bootHosts with one FAILED and isLoaded is true'
  572. }
  573. ]);
  574. tests.forEach(function(test) {
  575. it(test.m, function() {
  576. sinon.stub(c, 'disablePreviousSteps', Em.K);
  577. c.set('bootHosts', test.bootHosts);
  578. c.set('isLoaded', test.isLoaded);
  579. c.setRegistrationInProgress();
  580. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  581. c.disablePreviousSteps.restore();
  582. });
  583. });
  584. });
  585. describe('#doBootstrap', function() {
  586. beforeEach(function() {
  587. sinon.spy(App.ajax, 'send');
  588. });
  589. afterEach(function() {
  590. App.ajax.send.restore();
  591. });
  592. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  593. c.set('stopBootstrap', true);
  594. c.doBootstrap();
  595. expect(App.ajax.send.called).to.equal(false);
  596. });
  597. it('should increment numPolls if stopBootstrap is false', function() {
  598. c.set('stopBootstrap', false);
  599. c.set('numPolls', 0);
  600. c.doBootstrap();
  601. expect(c.get('numPolls')).to.equal(1);
  602. });
  603. it('should do ajax call if stopBootstrap is false', function() {
  604. c.set('stopBootstrap', false);
  605. c.doBootstrap();
  606. expect(App.ajax.send.called).to.equal(true);
  607. });
  608. });
  609. describe('#startRegistration', function() {
  610. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  611. c.set('registrationStartedAt', 1234);
  612. sinon.spy(c, 'isHostsRegistered');
  613. c.startRegistration();
  614. expect(c.isHostsRegistered.called).to.equal(false);
  615. expect(c.get('registrationStartedAt')).to.equal(1234);
  616. c.isHostsRegistered.restore();
  617. });
  618. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  619. c.set('registrationStartedAt', null);
  620. sinon.spy(c, 'isHostsRegistered');
  621. c.startRegistration();
  622. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  623. c.isHostsRegistered.restore();
  624. });
  625. });
  626. describe('#isHostsRegistered', function() {
  627. beforeEach(function() {
  628. sinon.spy(App.ajax, 'send');
  629. });
  630. afterEach(function() {
  631. App.ajax.send.restore();
  632. });
  633. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  634. c.set('stopBootstrap', true);
  635. c.isHostsRegistered();
  636. expect(App.ajax.send.called).to.equal(false);
  637. });
  638. it('should do ajax call if stopBootstrap is false', function() {
  639. c.set('stopBootstrap', false);
  640. c.isHostsRegistered();
  641. expect(App.ajax.send.called).to.equal(true);
  642. });
  643. });
  644. describe('#isHostsRegisteredSuccessCallback', function() {
  645. var tests = Em.A([
  646. {
  647. bootHosts: Em.A([
  648. Em.Object.create({bootStatus: 'DONE'})
  649. ]),
  650. data: {items:[]},
  651. m: 'one host DONE',
  652. e: {
  653. bs: 'REGISTERING',
  654. getHostInfoCalled: false
  655. }
  656. },
  657. {
  658. bootHosts: Em.A([
  659. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  660. ]),
  661. data: {items:[{Hosts: {host_name: 'c1'}}]},
  662. m: ' one host REGISTERING',
  663. e: {
  664. bs: 'FAILED',
  665. getHostInfoCalled: false
  666. }
  667. },
  668. {
  669. bootHosts: Em.A([
  670. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  671. ]),
  672. data: {items:[{Hosts: {host_name: 'c2'}}]},
  673. m: 'one host REGISTERING but data without info about it',
  674. e: {
  675. bs: 'FAILED',
  676. getHostInfoCalled: false
  677. }
  678. },
  679. {
  680. bootHosts: Em.A([
  681. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  682. ]),
  683. data: {items:[{Hosts: {host_name: 'c1'}}]},
  684. m: ' one host RUNNING',
  685. e: {
  686. bs: 'RUNNING',
  687. getHostInfoCalled: false
  688. }
  689. }
  690. ]);
  691. tests.forEach(function(test) {
  692. it(test.m, function() {
  693. sinon.spy(c, 'getHostInfo');
  694. c.set('bootHosts', test.bootHosts);
  695. c.isHostsRegisteredSuccessCallback(test.data);
  696. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  697. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  698. c.getHostInfo.restore();
  699. });
  700. });
  701. });
  702. describe('#getAllRegisteredHosts', function() {
  703. it('should call App.ajax.send', function() {
  704. sinon.spy(App.ajax, 'send');
  705. c.getAllRegisteredHosts();
  706. expect(App.ajax.send.calledOnce).to.equal(true);
  707. App.ajax.send.restore();
  708. });
  709. });
  710. describe('#getAllRegisteredHostsCallback', function() {
  711. var tests = Em.A([
  712. {
  713. hostsInCluster: ['c3'],
  714. bootHosts: [{name:'c1'},{name:'c2'}],
  715. hosts: Em.A([
  716. {Hosts: {host_name:'c1'}},
  717. {Hosts: {host_name:'c2'}}
  718. ]),
  719. m: 'No registered hosts',
  720. e: {
  721. hasMoreRegisteredHosts: false,
  722. registeredHosts: ''
  723. }
  724. },
  725. {
  726. hostsInCluster: ['c4'],
  727. bootHosts: [{name:'c3'},{name:'c5'}],
  728. hosts: Em.A([
  729. {Hosts: {host_name:'c1'}},
  730. {Hosts: {host_name:'c2'}}
  731. ]),
  732. m: '2 registered hosts',
  733. e: {
  734. hasMoreRegisteredHosts: true,
  735. registeredHosts: ['c1','c2']
  736. }
  737. },
  738. {
  739. hostsInCluster: ['c4'],
  740. bootHosts: [{name:'c1'},{name:'c5'}],
  741. hosts: Em.A([
  742. {Hosts: {host_name:'c1'}},
  743. {Hosts: {host_name:'c2'}}
  744. ]),
  745. m: '1 registered host',
  746. e: {
  747. hasMoreRegisteredHosts: true,
  748. registeredHosts: ['c2']
  749. }
  750. },
  751. {
  752. hostsInCluster: ['c1'],
  753. bootHosts: [{name:'c3'},{name:'c5'}],
  754. hosts: Em.A([
  755. {Hosts: {host_name:'c1'}},
  756. {Hosts: {host_name:'c2'}}
  757. ]),
  758. m: '1 registered host (2)',
  759. e: {
  760. hasMoreRegisteredHosts: true,
  761. registeredHosts: ['c2']
  762. }
  763. }
  764. ]);
  765. tests.forEach(function(test) {
  766. it(test.m, function() {
  767. c.reopen({hostsInCluster: test.hostsInCluster, setRegistrationInProgress: Em.K});
  768. c.set('bootHosts', test.bootHosts);
  769. c.getAllRegisteredHostsCallback({items:test.hosts});
  770. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  771. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  772. });
  773. });
  774. });
  775. describe('#registerErrPopup', function() {
  776. it('should call App.ModalPopup.show', function() {
  777. sinon.spy(App.ModalPopup, 'show');
  778. c.registerErrPopup();
  779. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  780. App.ModalPopup.show.restore();
  781. });
  782. });
  783. describe('#getHostInfo', function() {
  784. it('should do ajax request', function() {
  785. sinon.spy(App.ajax, 'send');
  786. c.getHostInfo();
  787. expect(App.ajax.send.calledOnce).to.equal(true);
  788. App.ajax.send.restore();
  789. });
  790. });
  791. describe('#getHostInfoErrorCallback', function() {
  792. it('should call registerErrPopup', function() {
  793. sinon.spy(c, 'registerErrPopup');
  794. c.getHostInfoErrorCallback();
  795. expect(c.registerErrPopup.calledOnce).to.equal(true);
  796. c.registerErrPopup.restore();
  797. });
  798. });
  799. describe('#stopRegistration', function() {
  800. var tests = Em.A([
  801. {
  802. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  803. e: {isSubmitDisabled: false, isRetryDisabled: true}
  804. },
  805. {
  806. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  807. e: {isSubmitDisabled: true, isRetryDisabled: false}
  808. },
  809. {
  810. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  811. e: {isSubmitDisabled: false, isRetryDisabled: false}
  812. },
  813. {
  814. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  815. e: {isSubmitDisabled: true, isRetryDisabled: true}
  816. }
  817. ]);
  818. tests.forEach(function(test) {
  819. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  820. c.reopen({bootHosts: test.bootHosts});
  821. c.stopRegistration();
  822. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  823. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  824. });
  825. });
  826. });
  827. describe('#submit', function() {
  828. it('if isHostHaveWarnings should show confirmation popup', function() {
  829. c.reopen({isHostHaveWarnings: true});
  830. sinon.spy(App.ModalPopup, 'show');
  831. c.submit();
  832. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  833. App.ModalPopup.show.restore();
  834. });
  835. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  836. var bootHosts = [{name: 'c1'}];
  837. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  838. c.submit().onPrimary();
  839. expect(c.get('content.hosts')).to.eql(bootHosts);
  840. });
  841. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  842. var bootHosts = [{name: 'c1'}];
  843. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  844. c.submit();
  845. expect(c.get('content.hosts')).to.eql(bootHosts);
  846. });
  847. });
  848. describe('#hostLogPopup', function() {
  849. it('should show App.ModalPopup', function() {
  850. sinon.spy(App.ModalPopup, 'show');
  851. c.hostLogPopup({context:Em.Object.create({})});
  852. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  853. App.ModalPopup.show.restore();
  854. });
  855. });
  856. describe('#rerunChecksSuccessCallback', function() {
  857. beforeEach(function() {
  858. sinon.stub(c, 'parseWarnings', Em.K);
  859. });
  860. afterEach(function() {
  861. c.parseWarnings.restore();
  862. });
  863. it('should set checksUpdateProgress to 100', function() {
  864. c.set('checksUpdateProgress', 0);
  865. c.rerunChecksSuccessCallback({});
  866. expect(c.get('checksUpdateProgress')).to.equal(100);
  867. });
  868. it('should set checksUpdateStatus to SUCCESS', function() {
  869. c.set('checksUpdateStatus', '');
  870. c.rerunChecksSuccessCallback({});
  871. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  872. });
  873. it('should set call parseWarnings', function() {
  874. c.rerunChecksSuccessCallback({});
  875. expect(c.parseWarnings.calledOnce).to.equal(true);
  876. });
  877. });
  878. describe('#rerunChecksErrorCallback', function() {
  879. it('should set checksUpdateProgress to 100', function() {
  880. c.set('checksUpdateProgress', 0);
  881. c.rerunChecksErrorCallback({});
  882. expect(c.get('checksUpdateProgress')).to.equal(100);
  883. });
  884. it('should set checksUpdateStatus to FAILED', function() {
  885. c.set('checksUpdateStatus', '');
  886. c.rerunChecksErrorCallback({});
  887. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  888. });
  889. });
  890. describe('#filterBootHosts', function() {
  891. var tests = Em.A([
  892. {
  893. bootHosts: [
  894. Em.Object.create({name: 'c1'}),
  895. Em.Object.create({name: 'c2'})
  896. ],
  897. data: {
  898. items: [
  899. {Hosts: {host_name: 'c1'}}
  900. ]
  901. },
  902. m: 'one host',
  903. e: ['c1']
  904. },
  905. {
  906. bootHosts: [
  907. Em.Object.create({name: 'c1'}),
  908. Em.Object.create({name: 'c2'})
  909. ],
  910. data: {
  911. items: [
  912. {Hosts: {host_name: 'c3'}}
  913. ]
  914. },
  915. m: 'no hosts',
  916. e: []
  917. },
  918. {
  919. bootHosts: [
  920. Em.Object.create({name: 'c1'}),
  921. Em.Object.create({name: 'c2'})
  922. ],
  923. data: {
  924. items: [
  925. {Hosts: {host_name: 'c1'}},
  926. {Hosts: {host_name: 'c2'}}
  927. ]
  928. },
  929. m: 'many hosts',
  930. e: ['c1', 'c2']
  931. }
  932. ]);
  933. tests.forEach(function(test) {
  934. it(test.m, function() {
  935. c.reopen({bootHosts: test.bootHosts});
  936. var filteredData = c.filterBootHosts(test.data);
  937. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  938. });
  939. });
  940. });
  941. describe('#hostWarningsPopup', function() {
  942. it('should show App.ModalPopup', function() {
  943. sinon.stub(App.ModalPopup, 'show', Em.K);
  944. c.hostWarningsPopup();
  945. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  946. App.ModalPopup.show.restore();
  947. });
  948. it('should clear checksUpdateStatus on primary', function() {
  949. c.set('checksUpdateStatus', 'not null value');
  950. c.hostWarningsPopup().onPrimary();
  951. expect(c.get('checksUpdateStatus')).to.be.null;
  952. });
  953. it('should clear checksUpdateStatus on close', function() {
  954. c.set('checksUpdateStatus', 'not null value');
  955. c.hostWarningsPopup().onClose();
  956. expect(c.get('checksUpdateStatus')).to.be.null;
  957. });
  958. it('should rerunChecks onSecondary', function() {
  959. sinon.stub(c, 'rerunChecks', Em.K);
  960. c.hostWarningsPopup().onSecondary();
  961. expect(c.rerunChecks.calledOnce).to.equal(true);
  962. });
  963. });
  964. describe('#registeredHostsPopup', function() {
  965. it('should show App.ModalPopup', function() {
  966. sinon.spy(App.ModalPopup, 'show');
  967. c.registeredHostsPopup();
  968. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  969. App.ModalPopup.show.restore();
  970. });
  971. });
  972. describe('#parseWarnings', function() {
  973. it('no warnings if last_agent_env isn\'t specified', function() {
  974. c.set('warnings', [{}]);
  975. c.set('warningsByHost', [{},{}]);
  976. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  977. expect(c.get('warnings')).to.eql([]);
  978. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  979. expect(c.get('isWarningsLoaded')).to.equal(true);
  980. });
  981. Em.A([
  982. {
  983. m: 'parse stackFoldersAndFiles',
  984. tests : Em.A([
  985. {
  986. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  987. m: 'empty stackFoldersAndFiles',
  988. e: {
  989. warnings: [],
  990. warningsByHost: [0]
  991. }
  992. },
  993. {
  994. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  995. m: 'not empty stackFoldersAndFiles',
  996. e: {
  997. warnings: [{
  998. name: 'n1',
  999. hosts: ['c1'],
  1000. onSingleHost: true,
  1001. category: 'fileFolders'
  1002. }],
  1003. warningsByHost: [1]
  1004. }
  1005. },
  1006. {
  1007. items: [
  1008. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1009. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1010. ],
  1011. m: 'not empty stackFoldersAndFiles on two hosts',
  1012. e: {
  1013. warnings: [{
  1014. name: 'n1',
  1015. hosts: ['c1', 'c2'],
  1016. onSingleHost: false,
  1017. category: 'fileFolders'
  1018. }],
  1019. warningsByHost: [1]
  1020. }
  1021. }
  1022. ])
  1023. },
  1024. {
  1025. m: 'parse installedPackages',
  1026. tests : Em.A([
  1027. {
  1028. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1029. m: 'empty installedPackages',
  1030. e: {
  1031. warnings: [],
  1032. warningsByHost: [0]
  1033. }
  1034. },
  1035. {
  1036. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1037. m: 'not empty installedPackages',
  1038. e: {
  1039. warnings: [{
  1040. name: 'n1',
  1041. hosts: ['c1'],
  1042. onSingleHost: true,
  1043. category: 'packages'
  1044. }],
  1045. warningsByHost: [1]
  1046. }
  1047. },
  1048. {
  1049. items: [
  1050. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1051. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1052. ],
  1053. m: 'not empty installedPackages on two hosts',
  1054. e: {
  1055. warnings: [{
  1056. name: 'n1',
  1057. hosts: ['c1', 'c2'],
  1058. onSingleHost: false,
  1059. category: 'packages'
  1060. }],
  1061. warningsByHost: [1]
  1062. }
  1063. }
  1064. ])
  1065. },
  1066. {
  1067. m: 'parse hostHealth.liveServices',
  1068. tests : Em.A([
  1069. {
  1070. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1071. m: 'empty hostHealth',
  1072. e: {
  1073. warnings: [],
  1074. warningsByHost: [0]
  1075. }
  1076. },
  1077. {
  1078. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1079. m: 'empty liveServices',
  1080. e: {
  1081. warnings: [],
  1082. warningsByHost: [0]
  1083. }
  1084. },
  1085. {
  1086. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1087. m: 'not empty hostHealth.liveServices',
  1088. e: {
  1089. warnings: [{
  1090. name: 'n1',
  1091. hosts: ['c1'],
  1092. onSingleHost: true,
  1093. category: 'services'
  1094. }],
  1095. warningsByHost: [1]
  1096. }
  1097. },
  1098. {
  1099. items: [
  1100. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1101. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1102. ],
  1103. m: 'not empty hostHealth.liveServices on two hosts',
  1104. e: {
  1105. warnings: [{
  1106. name: 'n1',
  1107. hosts: ['c1', 'c2'],
  1108. onSingleHost: false,
  1109. category: 'services'
  1110. }],
  1111. warningsByHost: [1, 1]
  1112. }
  1113. }
  1114. ])
  1115. },
  1116. {
  1117. m: 'parse existingUsers',
  1118. tests : Em.A([
  1119. {
  1120. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1121. m: 'empty existingUsers',
  1122. e: {
  1123. warnings: [],
  1124. warningsByHost: [0]
  1125. }
  1126. },
  1127. {
  1128. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1129. m: 'not empty existingUsers',
  1130. e: {
  1131. warnings: [{
  1132. name: 'n1',
  1133. hosts: ['c1'],
  1134. onSingleHost: true,
  1135. category: 'users'
  1136. }],
  1137. warningsByHost: [1]
  1138. }
  1139. },
  1140. {
  1141. items: [
  1142. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1143. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1144. ],
  1145. m: 'not empty existingUsers on two hosts',
  1146. e: {
  1147. warnings: [{
  1148. name: 'n1',
  1149. hosts: ['c1', 'c2'],
  1150. onSingleHost: false,
  1151. category: 'users'
  1152. }],
  1153. warningsByHost: [1, 1]
  1154. }
  1155. }
  1156. ])
  1157. },
  1158. {
  1159. m: 'parse alternatives',
  1160. tests : Em.A([
  1161. {
  1162. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1163. m: 'empty alternatives',
  1164. e: {
  1165. warnings: [],
  1166. warningsByHost: [0]
  1167. }
  1168. },
  1169. {
  1170. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1171. m: 'not empty alternatives',
  1172. e: {
  1173. warnings: [{
  1174. name: 'n1',
  1175. hosts: ['c1'],
  1176. onSingleHost: true,
  1177. category: 'alternatives'
  1178. }],
  1179. warningsByHost: [1]
  1180. }
  1181. },
  1182. {
  1183. items: [
  1184. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1185. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1186. ],
  1187. m: 'not empty alternatives on two hosts',
  1188. e: {
  1189. warnings: [{
  1190. name: 'n1',
  1191. hosts: ['c1', 'c2'],
  1192. onSingleHost: false,
  1193. category: 'alternatives'
  1194. }],
  1195. warningsByHost: [1, 1]
  1196. }
  1197. }
  1198. ])
  1199. },
  1200. {
  1201. m: 'parse hostHealth.activeJavaProcs',
  1202. tests : Em.A([
  1203. {
  1204. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1205. m: 'empty hostHealth',
  1206. e: {
  1207. warnings: [],
  1208. warningsByHost: [0]
  1209. }
  1210. },
  1211. {
  1212. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1213. m: 'empty activeJavaProcs',
  1214. e: {
  1215. warnings: [],
  1216. warningsByHost: [0]
  1217. }
  1218. },
  1219. {
  1220. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1221. m: 'not empty hostHealth.activeJavaProcs',
  1222. e: {
  1223. warnings: [{
  1224. pid: 'n1',
  1225. hosts: ['c1'],
  1226. onSingleHost: true,
  1227. category: 'processes'
  1228. }],
  1229. warningsByHost: [1]
  1230. }
  1231. },
  1232. {
  1233. items: [
  1234. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1235. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1236. ],
  1237. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1238. e: {
  1239. warnings: [{
  1240. pid: 'n1',
  1241. hosts: ['c1', 'c2'],
  1242. onSingleHost: false,
  1243. category: 'processes'
  1244. }],
  1245. warningsByHost: [1, 1]
  1246. }
  1247. }
  1248. ])
  1249. }
  1250. ]).forEach(function(category) {
  1251. describe(category.m, function() {
  1252. category.tests.forEach(function(test) {
  1253. it(test.m, function() {
  1254. c.parseWarnings({items: test.items});
  1255. c.get('warnings').forEach(function(w, i) {
  1256. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1257. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1258. });
  1259. });
  1260. for(var i in test.e.warningsByHost) {
  1261. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1262. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1263. }
  1264. }
  1265. });
  1266. });
  1267. });
  1268. });
  1269. });
  1270. describe('#hostsInCluster', function() {
  1271. it('should load data from App.Host model', function() {
  1272. var hosts = [
  1273. Em.Object.create({hostName: 'h1'}),
  1274. Em.Object.create({hostName: 'h2'}),
  1275. Em.Object.create({hostName: 'h3'})
  1276. ], expected = ['h1', 'h2', 'h3'];
  1277. sinon.stub(App.Host, 'find', function() {
  1278. return hosts;
  1279. });
  1280. expect(c.get('hostsInCluster')).to.eql(expected);
  1281. App.Host.find.restore();
  1282. });
  1283. });
  1284. describe('#navigateStep', function() {
  1285. Em.A([
  1286. {
  1287. isLoaded: true,
  1288. manualInstall: false,
  1289. bootStatus: false,
  1290. m: 'should call startBootstrap',
  1291. e: true
  1292. },
  1293. {
  1294. isLoaded: true,
  1295. manualInstall: false,
  1296. bootStatus: true,
  1297. m: 'shouldn\'t call startBootstrap (1)',
  1298. e: false
  1299. },
  1300. {
  1301. isLoaded: false,
  1302. manualInstall: false,
  1303. bootStatus: false,
  1304. m: 'shouldn\'t call startBootstrap (2)',
  1305. e: false
  1306. },
  1307. {
  1308. isLoaded: false,
  1309. manualInstall: true,
  1310. bootStatus: false,
  1311. m: 'shouldn\'t call startBootstrap (3)',
  1312. e: false
  1313. }
  1314. ]).forEach(function(test) {
  1315. it(test.m, function() {
  1316. c.reopen({
  1317. isLoaded: test.isLoaded,
  1318. content: {
  1319. installOptions: {
  1320. manualInstall: test.manualInstall
  1321. }
  1322. },
  1323. wizardController: Em.Object.create({
  1324. getDBProperty: function() {
  1325. return test.bootStatus
  1326. }
  1327. })
  1328. });
  1329. sinon.stub(c, 'startBootstrap', Em.K);
  1330. c.navigateStep();
  1331. if(test.e) {
  1332. expect(c.startBootstrap.calledOnce).to.equal(true);
  1333. }
  1334. else {
  1335. expect(c.startBootstrap.called).to.equal(false);
  1336. }
  1337. c.startBootstrap.restore();
  1338. });
  1339. });
  1340. it('should set test data if testMode is true', function() {
  1341. c.reopen({
  1342. isLoaded: true,
  1343. hosts: [{}, {}, {}],
  1344. content: {
  1345. installOptions: {
  1346. manualInstall: true
  1347. }
  1348. },
  1349. setRegistrationInProgress: Em.K
  1350. });
  1351. sinon.stub(App, 'get', function(k) {
  1352. if('testMode' === k) return true;
  1353. return Em.get(App, k);
  1354. });
  1355. c.navigateStep();
  1356. App.get.restore();
  1357. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1358. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1359. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1360. expect(c.get('isSubmitDisabled')).to.equal(false);
  1361. });
  1362. it('should start registration', function() {
  1363. c.reopen({
  1364. isLoaded: true,
  1365. hosts: [{}, {}, {}],
  1366. content: {
  1367. installOptions: {
  1368. manualInstall: true
  1369. }
  1370. },
  1371. setRegistrationInProgress: Em.K,
  1372. startRegistration: Em.K
  1373. });
  1374. sinon.spy(c, 'startRegistration');
  1375. sinon.stub(App, 'get', function(k) {
  1376. if('testMode' === k) return false;
  1377. return Em.get(App, k);
  1378. });
  1379. c.navigateStep();
  1380. App.get.restore();
  1381. expect(c.startRegistration.calledOnce).to.equal(true);
  1382. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1383. expect(c.get('registrationStartedAt')).to.be.null;
  1384. c.startRegistration.restore();
  1385. });
  1386. });
  1387. describe('#checkHostDiskSpace', function() {
  1388. Em.A([
  1389. {
  1390. diskInfo: [
  1391. {
  1392. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1393. mountpoint: '/'
  1394. }
  1395. ],
  1396. m: 'available less than App.minDiskSpace',
  1397. e: false
  1398. },
  1399. {
  1400. diskInfo: [
  1401. {
  1402. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1403. mountpoint: '/usr'
  1404. }
  1405. ],
  1406. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1407. e: false
  1408. },
  1409. {
  1410. diskInfo: [
  1411. {
  1412. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1413. mountpoint: '/usr/lib'
  1414. }
  1415. ],
  1416. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1417. e: false
  1418. },
  1419. {
  1420. diskInfo: [
  1421. {
  1422. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1423. mountpoint: '/'
  1424. }
  1425. ],
  1426. m: 'available greater than App.minDiskSpace',
  1427. e: true
  1428. },
  1429. {
  1430. diskInfo: [
  1431. {
  1432. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1433. mountpoint: '/usr'
  1434. }
  1435. ],
  1436. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1437. e: true
  1438. },
  1439. {
  1440. diskInfo: [
  1441. {
  1442. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1443. mountpoint: '/usr/lib'
  1444. }
  1445. ],
  1446. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1447. e: true
  1448. },
  1449. {
  1450. diskInfo: [
  1451. {
  1452. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1453. mountpoint: '/home/tdk'
  1454. }
  1455. ],
  1456. m: 'mount point without free space checks',
  1457. e: true
  1458. }
  1459. ]).forEach(function (test) {
  1460. it(test.m, function () {
  1461. var r = c.checkHostDiskSpace('', test.diskInfo);
  1462. expect(Em.isEmpty(r)).to.equal(test.e);
  1463. });
  1464. });
  1465. });
  1466. describe('#checkHostOSType', function() {
  1467. it('should return empty string if no stacks provided', function() {
  1468. c.reopen({content: {stacks: null}});
  1469. expect(c.checkHostOSType()).to.equal('');
  1470. });
  1471. it('os type is valid', function() {
  1472. var osType = 'redhat6';
  1473. c.reopen({
  1474. content: {
  1475. stacks: [
  1476. Em.Object.create({isSelected: true, operatingSystems: [{selected: true, osType: osType}]})
  1477. ]
  1478. }
  1479. });
  1480. expect(c.checkHostOSType(osType, '')).to.equal('');
  1481. });
  1482. it('os type is invalid', function() {
  1483. var osType = 'os2';
  1484. c.reopen({
  1485. content: {
  1486. stacks: [
  1487. Em.Object.create({isSelected: true, operatingSystems: [{selected: true, osType: 'os1'}]})
  1488. ]
  1489. }
  1490. });
  1491. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1492. });
  1493. });
  1494. describe('#getHostInfoSuccessCallback', function() {
  1495. beforeEach(function() {
  1496. sinon.stub(c, 'parseWarnings', Em.K);
  1497. sinon.stub(c, 'stopRegistration', Em.K);
  1498. });
  1499. afterEach(function() {
  1500. c.parseWarnings.restore();
  1501. c.stopRegistration.restore();
  1502. });
  1503. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1504. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1505. sinon.stub(App, 'get', function(k) {
  1506. if ('skipBootstrap' === k) return true;
  1507. return Em.get(App, k);
  1508. });
  1509. c.reopen({
  1510. bootHosts: [Em.Object.create({name: 'h1'})]
  1511. });
  1512. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1513. c.getHostInfoSuccessCallback(jsonData);
  1514. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1515. App.get.restore();
  1516. c._setHostDataWithSkipBootstrap.restore();
  1517. });
  1518. it('should add repo warnings', function() {
  1519. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1520. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1521. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1522. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1523. sinon.stub(App, 'get', function(k) {
  1524. if ('skipBootstrap' === k) return false;
  1525. return Em.get(App, k);
  1526. });
  1527. c.reopen({
  1528. bootHosts: [Em.Object.create({name: 'h1'})]
  1529. });
  1530. c.getHostInfoSuccessCallback(jsonData);
  1531. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1532. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1533. c.checkHostOSType.restore();
  1534. c.checkHostDiskSpace.restore();
  1535. c._setHostDataFromLoadedHostInfo.restore();
  1536. App.get.restore();
  1537. });
  1538. it('should add disk warnings', function() {
  1539. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1540. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1541. sinon.stub(c, 'checkHostOSType', Em.K);
  1542. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1543. sinon.stub(App, 'get', function(k) {
  1544. if ('skipBootstrap' === k) return false;
  1545. return Em.get(App, k);
  1546. });
  1547. c.reopen({
  1548. bootHosts: [Em.Object.create({name: 'h1'})]
  1549. });
  1550. c.getHostInfoSuccessCallback(jsonData);
  1551. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1552. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1553. c.checkHostOSType.restore();
  1554. c.checkHostDiskSpace.restore();
  1555. c._setHostDataFromLoadedHostInfo.restore();
  1556. App.get.restore();
  1557. });
  1558. });
  1559. describe('#_setHostDataWithSkipBootstrap', function() {
  1560. it('should set mock-data', function() {
  1561. var host = Em.Object.create({});
  1562. c._setHostDataWithSkipBootstrap(host);
  1563. expect(host.get('cpu')).to.equal(2);
  1564. expect(host.get('memory')).to.equal('2000000.00');
  1565. expect(host.get('disk_info.length')).to.equal(4);
  1566. });
  1567. });
  1568. describe('#_setHostDataFromLoadedHostInfo', function() {
  1569. it('should set data from hostInfo', function() {
  1570. var host = Em.Object.create(),
  1571. hostInfo = {
  1572. Hosts: {
  1573. cpu_count: 2,
  1574. total_mem: 12345,
  1575. os_type: 't1',
  1576. os_arch: 'os1',
  1577. ip: '0.0.0.0',
  1578. disk_info: [
  1579. {mountpoint: '/boot'},
  1580. {mountpoint: '/usr'},
  1581. {mountpoint: '/no-boot'},
  1582. {mountpoint: '/boot'}
  1583. ]
  1584. }
  1585. };
  1586. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1587. expect(host.get('cpu')).to.equal(2);
  1588. expect(host.get('os_type')).to.equal('t1');
  1589. expect(host.get('os_arch')).to.equal('os1');
  1590. expect(host.get('ip')).to.equal('0.0.0.0');
  1591. expect(host.get('memory')).to.equal('12345.00');
  1592. expect(host.get('disk_info.length')).to.equal(2);
  1593. });
  1594. });
  1595. });