step3_test.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  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/ajax/ajax');
  22. require('utils/http_client');
  23. require('models/host');
  24. require('controllers/wizard/step3_controller');
  25. describe('App.WizardStep3Controller', function () {
  26. beforeEach(function() {
  27. c = App.WizardStep3Controller.create({
  28. content: Em.Object.create({installedHosts: Em.A([]), installOptions: {}}),
  29. wizardController: App.InstallerController.create(),
  30. disablePreviousSteps: Em.K
  31. });
  32. sinon.stub(App.router, 'send', Em.K);
  33. });
  34. afterEach(function() {
  35. App.router.send.restore();
  36. });
  37. describe('#getAllRegisteredHostsCallback', function () {
  38. it('One host is already in the cluster, one host is registered', function() {
  39. c.get('content.installedHosts').pushObject({
  40. name: 'wst3_host1'
  41. });
  42. c.reopen({
  43. bootHosts: [
  44. {name:'wst3_host1'},
  45. {name:'wst3_host2'}
  46. ]
  47. });
  48. var test_data = {
  49. items: [
  50. {
  51. Hosts: {
  52. host_name: 'wst3_host1'
  53. }
  54. },
  55. {
  56. Hosts: {
  57. host_name: 'wst3_host2'
  58. }
  59. },
  60. {
  61. Hosts: {
  62. host_name: 'wst3_host3'
  63. }
  64. }
  65. ]
  66. };
  67. c.getAllRegisteredHostsCallback(test_data);
  68. expect(c.get('hasMoreRegisteredHosts')).to.equal(true);
  69. expect(c.get('registeredHosts').length).to.equal(1);
  70. });
  71. it('All hosts are new', function() {
  72. c.get('content.installedHosts').pushObject({
  73. name: 'wst3_host1'
  74. });
  75. c.reopen({
  76. bootHosts: [
  77. {name:'wst3_host3'},
  78. {name:'wst3_host4'}
  79. ]
  80. });
  81. var test_data = {
  82. items: [
  83. {
  84. Hosts: {
  85. host_name: 'wst3_host3'
  86. }
  87. },
  88. {
  89. Hosts: {
  90. host_name: 'wst3_host4'
  91. }
  92. }
  93. ]
  94. };
  95. c.getAllRegisteredHostsCallback(test_data);
  96. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  97. expect(c.get('registeredHosts')).to.equal('');
  98. });
  99. it('No new hosts', function() {
  100. c.get('content.installedHosts').pushObject({
  101. name: 'wst3_host1'
  102. });
  103. c.reopen({
  104. bootHosts: [
  105. {name:'wst3_host1'}
  106. ]
  107. });
  108. var test_data = {
  109. items: [
  110. {
  111. Hosts: {
  112. host_name: 'wst3_host1'
  113. }
  114. }
  115. ]
  116. };
  117. c.getAllRegisteredHostsCallback(test_data);
  118. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  119. expect(c.get('registeredHosts')).to.equal('');
  120. });
  121. });
  122. describe('#registrationTimeoutSecs', function() {
  123. it('Manual install', function() {
  124. c.set('content.installOptions.manualInstall', true);
  125. expect(c.get('registrationTimeoutSecs')).to.equal(15);
  126. });
  127. it('Not manual install', function() {
  128. c.set('content.installOptions.manualInstall', false);
  129. expect(c.get('registrationTimeoutSecs')).to.equal(120);
  130. });
  131. });
  132. describe('#isHostHaveWarnings', function() {
  133. var tests = [
  134. {
  135. warnings: [{},{}],
  136. m: 'Warnings exist',
  137. e: true
  138. },
  139. {
  140. warnings: [],
  141. m: 'Warnings don\'t exist',
  142. e: false
  143. }
  144. ];
  145. tests.forEach(function(test) {
  146. it(test.m, function() {
  147. c.set('warnings', test.warnings);
  148. expect(c.get('isHostHaveWarnings')).to.equal(test.e);
  149. });
  150. });
  151. });
  152. describe('#isWarningsBoxVisible', function() {
  153. afterEach(function() {
  154. App.get.restore();
  155. });
  156. it('for testMode should be always true', function() {
  157. sinon.stub(App, 'get', function(k) {
  158. if ('testMode' === k) return true;
  159. return Em.get(App, k);
  160. });
  161. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  162. });
  163. it('for "real" mode should be based on isRegistrationInProgress', function() {
  164. sinon.stub(App, 'get', function(k) {
  165. if ('testMode' === k) return false;
  166. return Em.get(App, k);
  167. });
  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. });
  173. });
  174. describe('#clearStep', function() {
  175. it('should clear hosts', function() {
  176. c.set('hosts', [{}, {}]);
  177. c.clearStep();
  178. expect(c.get('hosts')).to.eql([]);
  179. });
  180. it('should clear bootHosts', function() {
  181. c.set('bootHosts', [{}, {}]);
  182. c.clearStep();
  183. expect(c.get('bootHosts').length).to.equal(0);
  184. });
  185. it('should set stopBootstrap to false', function() {
  186. c.set('stopBootstrap', true);
  187. c.clearStep();
  188. expect(c.get('stopBootstrap')).to.equal(false);
  189. });
  190. it('should set wizardController DBProperty bootStatus to false', function() {
  191. c.get('wizardController').setDBProperty('bootStatus', true);
  192. c.clearStep();
  193. expect(c.get('wizardController').getDBProperty('bootStatus')).to.equal(false);
  194. });
  195. it('should set isSubmitDisabled to true', function() {
  196. c.set('isSubmitDisabled', false);
  197. c.clearStep();
  198. expect(c.get('isSubmitDisabled')).to.equal(true);
  199. });
  200. it('should set isSubmitDisabled to true', function() {
  201. c.set('isRetryDisabled', false);
  202. c.clearStep();
  203. expect(c.get('isRetryDisabled')).to.equal(true);
  204. });
  205. });
  206. describe('#loadStep', function() {
  207. beforeEach(function() {
  208. sinon.stub(App.router, 'get', function(k) {
  209. if ('clusterController' === k) {
  210. return Em.Object.create({
  211. loadAmbariProperties: Em.K
  212. });
  213. }
  214. return Em.get(App.router, k);
  215. });
  216. });
  217. afterEach(function() {
  218. App.router.get.restore();
  219. });
  220. it('should set registrationStartedAt to null', function() {
  221. c.set('disablePreviousSteps', Em.K);
  222. c.set('registrationStartedAt', {});
  223. c.loadStep();
  224. expect(c.get('registrationStartedAt')).to.be.null;
  225. });
  226. it('should call clearStep', function() {
  227. c.set('disablePreviousSteps', Em.K);
  228. c.set('loadHosts', Em.K);
  229. sinon.spy(c, 'clearStep');
  230. c.loadStep();
  231. expect(c.get('clearStep').calledOnce).to.equal(true);
  232. c.clearStep.restore();
  233. });
  234. it('should call loadHosts', function() {
  235. c.set('disablePreviousSteps', Em.K);
  236. c.set('loadHosts', Em.K);
  237. sinon.spy(c, 'loadHosts');
  238. c.loadStep();
  239. expect(c.get('loadHosts').calledOnce).to.equal(true);
  240. c.loadHosts.restore();
  241. });
  242. it('should call disablePreviousSteps', function() {
  243. c.set('disablePreviousSteps', Em.K);
  244. c.set('loadHosts', Em.K);
  245. sinon.spy(c, 'disablePreviousSteps');
  246. c.loadStep();
  247. expect(c.get('disablePreviousSteps').calledOnce).to.equal(true);
  248. c.disablePreviousSteps.restore();
  249. });
  250. });
  251. describe('#loadHosts', function() {
  252. afterEach(function() {
  253. App.get.restore();
  254. });
  255. it('should set isLoaded to true', function() {
  256. sinon.stub(App, 'get', function(k) {
  257. if ('testMode' === k) return true;
  258. return Em.get(App, k);
  259. });
  260. c.set('navigateStep', Em.K);
  261. c.set('content', {hosts: {}});
  262. c.loadHosts();
  263. expect(c.get('isLoaded')).to.equal(true);
  264. });
  265. it('should set bootStatus REGISTERED on testMode', function() {
  266. sinon.stub(App, 'get', function(k) {
  267. if ('testMode' === k) return true;
  268. return Em.get(App, k);
  269. });
  270. c.set('navigateStep', Em.K);
  271. c.set('content', {hosts: {c: {name: 'name'}}});
  272. c.loadHosts();
  273. expect(c.get('hosts').everyProperty('bootStatus', 'REGISTERED')).to.equal(true);
  274. });
  275. it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function() {
  276. sinon.stub(App, 'get', function(k) {
  277. if ('testMode' === k) return false;
  278. return Em.get(App, k);
  279. });
  280. c.set('navigateStep', Em.K);
  281. c.set('content.installOptions', {manualInstall: true});
  282. c.set('content.hosts', {c: {name: 'name'}});
  283. c.loadHosts();
  284. expect(c.get('hosts').everyProperty('bootStatus', 'DONE')).to.equal(true);
  285. });
  286. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  287. sinon.stub(App, 'get', function(k) {
  288. if ('testMode' === k) return false;
  289. return Em.get(App, k);
  290. });
  291. c.set('navigateStep', Em.K);
  292. c.set('content', {installOptions:{manualInstall: false}, hosts: {c: {name: 'name'}}});
  293. c.loadHosts();
  294. expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
  295. });
  296. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  297. sinon.stub(App, 'get', function(k) {
  298. if ('testMode' === k) return true;
  299. return Em.get(App, k);
  300. });
  301. c.set('navigateStep', Em.K);
  302. c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
  303. c.loadHosts();
  304. expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
  305. });
  306. });
  307. describe('#parseHostInfo', function() {
  308. var tests = Em.A([
  309. {
  310. bootHosts: Em.A([
  311. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  312. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  313. Em.Object.create({name: 'c3', bootStatus: 'RUNNING', bootLog: ''})
  314. ]),
  315. hostsStatusFromServer: Em.A([
  316. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  317. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  318. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  319. ]),
  320. m: 'bootHosts not empty, hostsStatusFromServer not empty, one is RUNNING',
  321. e: {
  322. c: true,
  323. r: true
  324. }
  325. },
  326. {
  327. bootHosts: Em.A([]),
  328. hostsStatusFromServer: Em.A([
  329. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  330. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  331. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  332. ]),
  333. m: 'bootHosts is empty',
  334. e: {
  335. c: false,
  336. r: false
  337. }
  338. },
  339. {
  340. bootHosts: Em.A([
  341. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  342. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  343. Em.Object.create({name: 'c3', bootStatus: 'REGISTERED', bootLog: ''})
  344. ]),
  345. hostsStatusFromServer: Em.A([
  346. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  347. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  348. {hostName: 'c3', status: 'REGISTERED', log: 'c3'}
  349. ]),
  350. m: 'bootHosts not empty, hostsStatusFromServer not empty, no one is RUNNING',
  351. e: {
  352. c: true,
  353. r: false
  354. }
  355. }
  356. ]);
  357. tests.forEach(function(test) {
  358. it(test.m, function() {
  359. c.set('bootHosts', test.bootHosts);
  360. var r = c.parseHostInfo(test.hostsStatusFromServer);
  361. expect(r).to.equal(test.e.r);
  362. if (test.e.c) {
  363. test.hostsStatusFromServer.forEach(function(h) {
  364. var r = c.get('bootHosts').findProperty('name', h.hostName);
  365. if (!['REGISTERED', 'REGISTERING'].contains(r.get('bootStatus'))) {
  366. expect(r.get('bootStatus')).to.equal(h.status);
  367. expect(r.get('bootLog')).to.equal(h.log);
  368. }
  369. });
  370. }
  371. });
  372. });
  373. });
  374. describe('#removeHosts', function() {
  375. it('should call App.showConfirmationPopup', function() {
  376. sinon.spy(App, 'showConfirmationPopup');
  377. c.removeHosts(Em.A([]));
  378. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  379. App.showConfirmationPopup.restore();
  380. });
  381. it('primary should disable Submit if no more hosts', function() {
  382. var hosts = [{}];
  383. c.set('hosts', hosts);
  384. var popup = c.removeHosts(hosts);
  385. popup.onPrimary();
  386. expect(c.get('isSubmitDisabled')).to.equal(true);
  387. });
  388. });
  389. describe('#removeHost', function() {
  390. it('should call removeHosts with array as arg', function() {
  391. var host = {a:''};
  392. sinon.spy(c, 'removeHosts');
  393. c.removeHost(host);
  394. expect(c.removeHosts.calledWith([host]));
  395. c.removeHosts.restore();
  396. });
  397. });
  398. describe('#removeSelectedHosts', function() {
  399. it('should remove selected hosts', function() {
  400. c = App.WizardStep3Controller.create({
  401. wizardController: App.InstallerController.create(),
  402. hosts: [
  403. {isChecked: true, name: 'c1'},
  404. {isChecked: false, name: 'c2'}
  405. ]
  406. });
  407. c.removeSelectedHosts().onPrimary();
  408. expect(c.get('hosts').mapProperty('name')).to.eql(['c2']);
  409. });
  410. });
  411. describe('#selectedHostsPopup', function() {
  412. it('should show App.ModalPopup', function() {
  413. sinon.spy(App.ModalPopup, 'show');
  414. c.selectedHostsPopup();
  415. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  416. App.ModalPopup.show.restore();
  417. });
  418. });
  419. describe('#retryHosts', function () {
  420. var s;
  421. var installer = {launchBootstrap: Em.K};
  422. beforeEach(function () {
  423. sinon.spy(installer, "launchBootstrap");
  424. s = sinon.stub(App.router, 'get', function () {
  425. return installer;
  426. });
  427. sinon.stub(c, 'doBootstrap', Em.K);
  428. });
  429. afterEach(function () {
  430. c.doBootstrap.restore();
  431. s.restore();
  432. installer.launchBootstrap.restore();
  433. });
  434. it('should set numPolls to 0', function () {
  435. c.set('content', {installOptions: {}});
  436. c.set('numPolls', 123);
  437. c.retryHosts(Em.A([]));
  438. expect(c.get('numPolls')).to.equal(0);
  439. });
  440. it('should set registrationStartedAt to null', function () {
  441. c.set('content', {installOptions: {}});
  442. c.retryHosts(Em.A([]));
  443. expect(c.get('registrationStartedAt')).to.be.null;
  444. });
  445. it('should startRegistration if installOptions.manualInstall is true', function () {
  446. sinon.spy(c, 'startRegistration');
  447. c.set('content', {installOptions: {manualInstall: true}});
  448. c.retryHosts(Em.A([]));
  449. expect(c.startRegistration.calledOnce).to.equal(true);
  450. c.startRegistration.restore();
  451. });
  452. it('should launchBootstrap if installOptions.manualInstall is false', function () {
  453. c.set('content', {installOptions: {manualInstall: false}});
  454. c.retryHosts(Em.A([]));
  455. expect(installer.launchBootstrap.calledOnce).to.be.true;
  456. });
  457. });
  458. describe('#retryHost', function() {
  459. it('should callretryHosts with array as arg', function() {
  460. var host = {n: 'c'}, s = sinon.stub(App.router, 'get', function() {
  461. return {launchBootstrap: Em.K}
  462. });
  463. sinon.spy(c, 'retryHosts');
  464. c.set('content', {installOptions: {}});
  465. c.set('doBootstrap', Em.K);
  466. c.retryHost(host);
  467. expect(c.retryHosts.calledWith([host])).to.equal(true);
  468. c.retryHosts.restore();
  469. s.restore();
  470. });
  471. });
  472. describe('#retrySelectedHosts', function() {
  473. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  474. c.set('isRetryDisabled', true);
  475. sinon.spy(c, 'retryHosts');
  476. c.retrySelectedHosts();
  477. expect(c.retryHosts.called).to.equal(false);
  478. c.retryHosts.restore();
  479. });
  480. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  481. var s = sinon.stub(App.router, 'get', function() {
  482. return {launchBootstrap: Em.K}
  483. });
  484. c = App.WizardStep3Controller.create({
  485. wizardController: App.InstallerController.create(),
  486. isRetryDisabled: false,
  487. bootHosts: Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]),
  488. content: {installOptions: {}},
  489. doBootstrap: Em.K
  490. });
  491. sinon.spy(c, 'retryHosts');
  492. c.retrySelectedHosts();
  493. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  494. expect(c.get('isRetryDisabled')).to.equal(true);
  495. c.retryHosts.restore();
  496. s.restore();
  497. });
  498. });
  499. describe('#startBootstrap', function() {
  500. it('should drop numPolls and registrationStartedAt', function() {
  501. c.set('numPolls', 123);
  502. c.set('registrationStartedAt', 1234);
  503. c.set('doBootstrap', Em.K);
  504. c.startBootstrap();
  505. expect(c.get('numPolls')).to.equal(0);
  506. expect(c.get('registrationStartedAt')).to.be.null;
  507. });
  508. it('should drop numPolls and registrationStartedAt', function() {
  509. var hosts = Em.A([{name: 'c1'}, {name: 'c2'}]);
  510. c = App.WizardStep3Controller.create({
  511. wizardController: App.InstallerController.create(),
  512. doBootstrap: Em.K,
  513. setRegistrationInProgressOnce: Em.K,
  514. hosts: hosts
  515. });
  516. c.startBootstrap();
  517. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  518. });
  519. });
  520. describe('#setRegistrationInProgressOnce', function() {
  521. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  522. sinon.spy(Em.run, 'once');
  523. c.setRegistrationInProgressOnce();
  524. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  525. Em.run.once.restore();
  526. });
  527. });
  528. describe('#setRegistrationInProgress', function() {
  529. var tests = Em.A([
  530. {
  531. bootHosts: [],
  532. isLoaded: false,
  533. e: true,
  534. m: 'no bootHosts and isLoaded is false'
  535. },
  536. {
  537. bootHosts: [],
  538. isLoaded: true,
  539. e: false,
  540. m: 'no bootHosts and isLoaded is true'
  541. },
  542. {
  543. bootHosts: [
  544. Em.Object.create({bootStatus: 'RUNNING'}),
  545. Em.Object.create({bootStatus: 'RUNNING'})
  546. ],
  547. isLoaded: true,
  548. e: false,
  549. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  550. },
  551. {
  552. bootHosts: [
  553. Em.Object.create({bootStatus: 'RUNNING'}),
  554. Em.Object.create({bootStatus: 'RUNNING'})
  555. ],
  556. isLoaded: false,
  557. e: true,
  558. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  559. },
  560. {
  561. bootHosts: [
  562. Em.Object.create({bootStatus: 'REGISTERED'}),
  563. Em.Object.create({bootStatus: 'RUNNING'})
  564. ],
  565. isLoaded: false,
  566. e: true,
  567. m: 'bootHosts with one REGISTERED and isLoaded is false'
  568. },
  569. {
  570. bootHosts: [
  571. Em.Object.create({bootStatus: 'FAILED'}),
  572. Em.Object.create({bootStatus: 'RUNNING'})
  573. ],
  574. isLoaded: false,
  575. e: true,
  576. m: 'bootHosts with one FAILED and isLoaded is false'
  577. },
  578. {
  579. bootHosts: [
  580. Em.Object.create({bootStatus: 'REGISTERED'}),
  581. Em.Object.create({bootStatus: 'RUNNING'})
  582. ],
  583. isLoaded: true,
  584. e: false,
  585. m: 'bootHosts with one REGISTERED and isLoaded is true'
  586. },
  587. {
  588. bootHosts: [
  589. Em.Object.create({bootStatus: 'FAILED'}),
  590. Em.Object.create({bootStatus: 'RUNNING'})
  591. ],
  592. isLoaded: true,
  593. e: false,
  594. m: 'bootHosts with one FAILED and isLoaded is true'
  595. }
  596. ]);
  597. tests.forEach(function(test) {
  598. it(test.m, function() {
  599. sinon.stub(c, 'disablePreviousSteps', Em.K);
  600. c.set('bootHosts', test.bootHosts);
  601. c.set('isLoaded', test.isLoaded);
  602. c.setRegistrationInProgress();
  603. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  604. c.disablePreviousSteps.restore();
  605. });
  606. });
  607. });
  608. describe('#doBootstrap', function() {
  609. beforeEach(function() {
  610. sinon.spy(App.ajax, 'send');
  611. });
  612. afterEach(function() {
  613. App.ajax.send.restore();
  614. });
  615. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  616. c.set('stopBootstrap', true);
  617. c.doBootstrap();
  618. expect(App.ajax.send.called).to.equal(false);
  619. });
  620. it('should increment numPolls if stopBootstrap is false', function() {
  621. c.set('stopBootstrap', false);
  622. c.set('numPolls', 0);
  623. c.doBootstrap();
  624. expect(c.get('numPolls')).to.equal(1);
  625. });
  626. it('should do ajax call if stopBootstrap is false', function() {
  627. c.set('stopBootstrap', false);
  628. c.doBootstrap();
  629. expect(App.ajax.send.called).to.equal(true);
  630. });
  631. });
  632. describe('#startRegistration', function() {
  633. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  634. c.set('registrationStartedAt', 1234);
  635. sinon.spy(c, 'isHostsRegistered');
  636. c.startRegistration();
  637. expect(c.isHostsRegistered.called).to.equal(false);
  638. expect(c.get('registrationStartedAt')).to.equal(1234);
  639. c.isHostsRegistered.restore();
  640. });
  641. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  642. c.set('registrationStartedAt', null);
  643. sinon.spy(c, 'isHostsRegistered');
  644. c.startRegistration();
  645. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  646. c.isHostsRegistered.restore();
  647. });
  648. });
  649. describe('#isHostsRegistered', function() {
  650. beforeEach(function() {
  651. sinon.stub(App.ajax, 'send', function() {return {retry: function() {return {then: Em.K}}}});
  652. });
  653. afterEach(function() {
  654. App.ajax.send.restore();
  655. });
  656. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  657. c.set('stopBootstrap', true);
  658. c.isHostsRegistered();
  659. expect(App.ajax.send.called).to.equal(false);
  660. });
  661. it('should do ajax call if stopBootstrap is false', function() {
  662. c.set('stopBootstrap', false);
  663. c.isHostsRegistered();
  664. expect(App.ajax.send.called).to.equal(true);
  665. });
  666. });
  667. describe('#isHostsRegisteredSuccessCallback', function() {
  668. var tests = Em.A([
  669. {
  670. bootHosts: Em.A([
  671. Em.Object.create({bootStatus: 'DONE'})
  672. ]),
  673. data: {items:[]},
  674. m: 'one host DONE',
  675. e: {
  676. bs: 'REGISTERING',
  677. getHostInfoCalled: false
  678. }
  679. },
  680. {
  681. bootHosts: Em.A([
  682. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  683. ]),
  684. data: {items:[{Hosts: {host_name: 'c1'}}]},
  685. m: ' one host REGISTERING',
  686. e: {
  687. bs: 'REGISTERED',
  688. getHostInfoCalled: false
  689. }
  690. },
  691. {
  692. bootHosts: Em.A([
  693. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  694. ]),
  695. data: {items:[{Hosts: {host_name: 'c2'}}]},
  696. m: 'one host REGISTERING but data without info about it',
  697. e: {
  698. bs: 'FAILED',
  699. getHostInfoCalled: false
  700. }
  701. },
  702. {
  703. bootHosts: Em.A([
  704. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  705. ]),
  706. data: {items:[{Hosts: {host_name: 'c1'}}]},
  707. m: ' one host RUNNING',
  708. e: {
  709. bs: 'RUNNING',
  710. getHostInfoCalled: false
  711. }
  712. }
  713. ]);
  714. tests.forEach(function(test) {
  715. it(test.m, function() {
  716. sinon.spy(c, 'getHostInfo');
  717. c.set('content.installedHosts', []);
  718. c.set('bootHosts', test.bootHosts);
  719. c.isHostsRegisteredSuccessCallback(test.data);
  720. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  721. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  722. c.getHostInfo.restore();
  723. });
  724. });
  725. });
  726. describe('#getAllRegisteredHosts', function() {
  727. it('should call App.ajax.send', function() {
  728. sinon.spy(App.ajax, 'send');
  729. c.getAllRegisteredHosts();
  730. expect(App.ajax.send.calledOnce).to.equal(true);
  731. App.ajax.send.restore();
  732. });
  733. });
  734. describe('#getAllRegisteredHostsCallback', function() {
  735. var tests = Em.A([
  736. {
  737. hostsInCluster: ['c3'],
  738. bootHosts: [{name:'c1'},{name:'c2'}],
  739. hosts: Em.A([
  740. {Hosts: {host_name:'c1'}},
  741. {Hosts: {host_name:'c2'}}
  742. ]),
  743. m: 'No registered hosts',
  744. e: {
  745. hasMoreRegisteredHosts: false,
  746. registeredHosts: ''
  747. }
  748. },
  749. {
  750. hostsInCluster: ['c4'],
  751. bootHosts: [{name:'c3'},{name:'c5'}],
  752. hosts: Em.A([
  753. {Hosts: {host_name:'c1'}},
  754. {Hosts: {host_name:'c2'}}
  755. ]),
  756. m: '2 registered hosts',
  757. e: {
  758. hasMoreRegisteredHosts: true,
  759. registeredHosts: ['c1','c2']
  760. }
  761. },
  762. {
  763. hostsInCluster: ['c4'],
  764. bootHosts: [{name:'c1'},{name:'c5'}],
  765. hosts: Em.A([
  766. {Hosts: {host_name:'c1'}},
  767. {Hosts: {host_name:'c2'}}
  768. ]),
  769. m: '1 registered host',
  770. e: {
  771. hasMoreRegisteredHosts: true,
  772. registeredHosts: ['c2']
  773. }
  774. },
  775. {
  776. hostsInCluster: ['c1'],
  777. bootHosts: [{name:'c3'},{name:'c5'}],
  778. hosts: Em.A([
  779. {Hosts: {host_name:'c1'}},
  780. {Hosts: {host_name:'c2'}}
  781. ]),
  782. m: '1 registered host (2)',
  783. e: {
  784. hasMoreRegisteredHosts: true,
  785. registeredHosts: ['c2']
  786. }
  787. }
  788. ]);
  789. tests.forEach(function(test) {
  790. it(test.m, function() {
  791. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  792. c.set('bootHosts', test.bootHosts);
  793. c.getAllRegisteredHostsCallback({items:test.hosts});
  794. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  795. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  796. });
  797. });
  798. });
  799. describe('#registerErrPopup', function() {
  800. it('should call App.ModalPopup.show', function() {
  801. sinon.spy(App.ModalPopup, 'show');
  802. c.registerErrPopup();
  803. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  804. App.ModalPopup.show.restore();
  805. });
  806. });
  807. describe('#getHostInfo', function() {
  808. it('should do ajax request', function() {
  809. sinon.spy(App.ajax, 'send');
  810. c.getHostInfo();
  811. expect(App.ajax.send.calledOnce).to.equal(true);
  812. App.ajax.send.restore();
  813. });
  814. });
  815. describe('#getHostInfoErrorCallback', function() {
  816. it('should call registerErrPopup', function() {
  817. sinon.spy(c, 'registerErrPopup');
  818. c.getHostInfoErrorCallback();
  819. expect(c.registerErrPopup.calledOnce).to.equal(true);
  820. c.registerErrPopup.restore();
  821. });
  822. });
  823. describe('#stopRegistration', function() {
  824. var tests = Em.A([
  825. {
  826. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  827. e: {isSubmitDisabled: false, isRetryDisabled: true}
  828. },
  829. {
  830. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  831. e: {isSubmitDisabled: true, isRetryDisabled: false}
  832. },
  833. {
  834. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  835. e: {isSubmitDisabled: false, isRetryDisabled: false}
  836. },
  837. {
  838. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  839. e: {isSubmitDisabled: true, isRetryDisabled: true}
  840. }
  841. ]);
  842. tests.forEach(function(test) {
  843. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  844. c.reopen({bootHosts: test.bootHosts});
  845. c.stopRegistration();
  846. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  847. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  848. });
  849. });
  850. });
  851. describe('#submit', function() {
  852. it('if isHostHaveWarnings should show confirmation popup', function() {
  853. c.reopen({isHostHaveWarnings: true});
  854. sinon.spy(App.ModalPopup, 'show');
  855. c.submit();
  856. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  857. App.ModalPopup.show.restore();
  858. });
  859. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  860. var bootHosts = [{name: 'c1'}];
  861. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  862. c.submit().onPrimary();
  863. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  864. });
  865. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  866. var bootHosts = [{name: 'c1'}];
  867. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  868. c.submit();
  869. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  870. });
  871. });
  872. describe('#hostLogPopup', function() {
  873. it('should show App.ModalPopup', function() {
  874. sinon.spy(App.ModalPopup, 'show');
  875. c.hostLogPopup({context:Em.Object.create({})});
  876. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  877. App.ModalPopup.show.restore();
  878. });
  879. });
  880. describe('#rerunChecksSuccessCallback', function() {
  881. beforeEach(function() {
  882. sinon.stub(c, 'parseWarnings', Em.K);
  883. });
  884. afterEach(function() {
  885. c.parseWarnings.restore();
  886. });
  887. it('should set checksUpdateProgress to 100', function() {
  888. c.set('checksUpdateProgress', 0);
  889. c.rerunChecksSuccessCallback({items: []});
  890. expect(c.get('checksUpdateProgress')).to.equal(100);
  891. });
  892. it('should set checksUpdateStatus to SUCCESS', function() {
  893. c.set('checksUpdateStatus', '');
  894. c.rerunChecksSuccessCallback({items: []});
  895. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  896. });
  897. it('should call parseWarnings', function() {
  898. c.rerunChecksSuccessCallback({items: []});
  899. expect(c.parseWarnings.calledOnce).to.equal(true);
  900. });
  901. });
  902. describe('#rerunChecksErrorCallback', function() {
  903. it('should set checksUpdateProgress to 100', function() {
  904. c.set('checksUpdateProgress', 0);
  905. c.rerunChecksErrorCallback({});
  906. expect(c.get('checksUpdateProgress')).to.equal(100);
  907. });
  908. it('should set checksUpdateStatus to FAILED', function() {
  909. c.set('checksUpdateStatus', '');
  910. c.rerunChecksErrorCallback({});
  911. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  912. });
  913. });
  914. describe('#filterBootHosts', function() {
  915. var tests = Em.A([
  916. {
  917. bootHosts: [
  918. Em.Object.create({name: 'c1'}),
  919. Em.Object.create({name: 'c2'})
  920. ],
  921. data: {
  922. items: [
  923. {Hosts: {host_name: 'c1'}}
  924. ]
  925. },
  926. m: 'one host',
  927. e: ['c1']
  928. },
  929. {
  930. bootHosts: [
  931. Em.Object.create({name: 'c1'}),
  932. Em.Object.create({name: 'c2'})
  933. ],
  934. data: {
  935. items: [
  936. {Hosts: {host_name: 'c3'}}
  937. ]
  938. },
  939. m: 'no hosts',
  940. e: []
  941. },
  942. {
  943. bootHosts: [
  944. Em.Object.create({name: 'c1'}),
  945. Em.Object.create({name: 'c2'})
  946. ],
  947. data: {
  948. items: [
  949. {Hosts: {host_name: 'c1'}},
  950. {Hosts: {host_name: 'c2'}}
  951. ]
  952. },
  953. m: 'many hosts',
  954. e: ['c1', 'c2']
  955. }
  956. ]);
  957. tests.forEach(function(test) {
  958. it(test.m, function() {
  959. c.reopen({bootHosts: test.bootHosts});
  960. var filteredData = c.filterBootHosts(test.data);
  961. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  962. });
  963. });
  964. });
  965. describe('#hostWarningsPopup', function() {
  966. it('should show App.ModalPopup', function() {
  967. sinon.stub(App.ModalPopup, 'show', Em.K);
  968. c.hostWarningsPopup();
  969. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  970. App.ModalPopup.show.restore();
  971. });
  972. it('should clear checksUpdateStatus on primary', function() {
  973. c.set('checksUpdateStatus', 'not null value');
  974. c.hostWarningsPopup().onPrimary();
  975. expect(c.get('checksUpdateStatus')).to.be.null;
  976. });
  977. it('should clear checksUpdateStatus on close', function() {
  978. c.set('checksUpdateStatus', 'not null value');
  979. c.hostWarningsPopup().onClose();
  980. expect(c.get('checksUpdateStatus')).to.be.null;
  981. });
  982. it('should rerunChecks onSecondary', function() {
  983. sinon.stub(c, 'rerunChecks', Em.K);
  984. c.hostWarningsPopup().onSecondary();
  985. expect(c.rerunChecks.calledOnce).to.equal(true);
  986. });
  987. });
  988. describe('#registeredHostsPopup', function() {
  989. it('should show App.ModalPopup', function() {
  990. sinon.spy(App.ModalPopup, 'show');
  991. c.registeredHostsPopup();
  992. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  993. App.ModalPopup.show.restore();
  994. });
  995. });
  996. describe('#parseWarnings', function() {
  997. beforeEach(function() {
  998. sinon.stub(App, 'get', function(k) {
  999. if ('testMode' === k) return false;
  1000. return Em.get(App, k);
  1001. });
  1002. sinon.stub(c, 'filterBootHosts', function(k) {return k;});
  1003. });
  1004. afterEach(function() {
  1005. App.get.restore();
  1006. c.filterBootHosts.restore();
  1007. });
  1008. it('no warnings if last_agent_env isn\'t specified', function() {
  1009. c.set('warnings', [{}]);
  1010. c.set('warningsByHost', [{},{}]);
  1011. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  1012. expect(c.get('warnings')).to.eql([]);
  1013. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1014. });
  1015. Em.A([
  1016. {
  1017. m: 'parse stackFoldersAndFiles',
  1018. tests : Em.A([
  1019. {
  1020. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  1021. m: 'empty stackFoldersAndFiles',
  1022. e: {
  1023. warnings: [],
  1024. warningsByHost: [0]
  1025. }
  1026. },
  1027. {
  1028. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  1029. m: 'not empty stackFoldersAndFiles',
  1030. e: {
  1031. warnings: [{
  1032. name: 'n1',
  1033. hosts: ['c1'],
  1034. onSingleHost: true,
  1035. category: 'fileFolders'
  1036. }],
  1037. warningsByHost: [1]
  1038. }
  1039. },
  1040. {
  1041. items: [
  1042. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1043. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1044. ],
  1045. m: 'not empty stackFoldersAndFiles on two hosts',
  1046. e: {
  1047. warnings: [{
  1048. name: 'n1',
  1049. hosts: ['c1', 'c2'],
  1050. onSingleHost: false,
  1051. category: 'fileFolders'
  1052. }],
  1053. warningsByHost: [1]
  1054. }
  1055. }
  1056. ])
  1057. },
  1058. {
  1059. m: 'parse installedPackages',
  1060. tests : Em.A([
  1061. {
  1062. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1063. m: 'empty installedPackages',
  1064. e: {
  1065. warnings: [],
  1066. warningsByHost: [0]
  1067. }
  1068. },
  1069. {
  1070. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1071. m: 'not empty installedPackages',
  1072. e: {
  1073. warnings: [{
  1074. name: 'n1',
  1075. hosts: ['c1'],
  1076. onSingleHost: true,
  1077. category: 'packages'
  1078. }],
  1079. warningsByHost: [1]
  1080. }
  1081. },
  1082. {
  1083. items: [
  1084. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1085. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1086. ],
  1087. m: 'not empty installedPackages on two hosts',
  1088. e: {
  1089. warnings: [{
  1090. name: 'n1',
  1091. hosts: ['c1', 'c2'],
  1092. onSingleHost: false,
  1093. category: 'packages'
  1094. }],
  1095. warningsByHost: [1]
  1096. }
  1097. }
  1098. ])
  1099. },
  1100. {
  1101. m: 'parse hostHealth.liveServices',
  1102. tests : Em.A([
  1103. {
  1104. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1105. m: 'empty hostHealth',
  1106. e: {
  1107. warnings: [],
  1108. warningsByHost: [0]
  1109. }
  1110. },
  1111. {
  1112. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1113. m: 'empty liveServices',
  1114. e: {
  1115. warnings: [],
  1116. warningsByHost: [0]
  1117. }
  1118. },
  1119. {
  1120. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1121. m: 'not empty hostHealth.liveServices',
  1122. e: {
  1123. warnings: [{
  1124. name: 'n1',
  1125. hosts: ['c1'],
  1126. onSingleHost: true,
  1127. category: 'services'
  1128. }],
  1129. warningsByHost: [1]
  1130. }
  1131. },
  1132. {
  1133. items: [
  1134. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1135. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1136. ],
  1137. m: 'not empty hostHealth.liveServices on two hosts',
  1138. e: {
  1139. warnings: [{
  1140. name: 'n1',
  1141. hosts: ['c1', 'c2'],
  1142. onSingleHost: false,
  1143. category: 'services'
  1144. }],
  1145. warningsByHost: [1, 1]
  1146. }
  1147. }
  1148. ])
  1149. },
  1150. {
  1151. m: 'parse existingUsers',
  1152. tests : Em.A([
  1153. {
  1154. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1155. m: 'empty existingUsers',
  1156. e: {
  1157. warnings: [],
  1158. warningsByHost: [0]
  1159. }
  1160. },
  1161. {
  1162. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1163. m: 'not empty existingUsers',
  1164. e: {
  1165. warnings: [{
  1166. name: 'n1',
  1167. hosts: ['c1'],
  1168. onSingleHost: true,
  1169. category: 'users'
  1170. }],
  1171. warningsByHost: [1]
  1172. }
  1173. },
  1174. {
  1175. items: [
  1176. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1177. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1178. ],
  1179. m: 'not empty existingUsers on two hosts',
  1180. e: {
  1181. warnings: [{
  1182. name: 'n1',
  1183. hosts: ['c1', 'c2'],
  1184. onSingleHost: false,
  1185. category: 'users'
  1186. }],
  1187. warningsByHost: [1, 1]
  1188. }
  1189. }
  1190. ])
  1191. },
  1192. {
  1193. m: 'parse alternatives',
  1194. tests : Em.A([
  1195. {
  1196. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1197. m: 'empty alternatives',
  1198. e: {
  1199. warnings: [],
  1200. warningsByHost: [0]
  1201. }
  1202. },
  1203. {
  1204. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1205. m: 'not empty alternatives',
  1206. e: {
  1207. warnings: [{
  1208. name: 'n1',
  1209. hosts: ['c1'],
  1210. onSingleHost: true,
  1211. category: 'alternatives'
  1212. }],
  1213. warningsByHost: [1]
  1214. }
  1215. },
  1216. {
  1217. items: [
  1218. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1219. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1220. ],
  1221. m: 'not empty alternatives on two hosts',
  1222. e: {
  1223. warnings: [{
  1224. name: 'n1',
  1225. hosts: ['c1', 'c2'],
  1226. onSingleHost: false,
  1227. category: 'alternatives'
  1228. }],
  1229. warningsByHost: [1, 1]
  1230. }
  1231. }
  1232. ])
  1233. },
  1234. {
  1235. m: 'parse hostHealth.activeJavaProcs',
  1236. tests : Em.A([
  1237. {
  1238. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1239. m: 'empty hostHealth',
  1240. e: {
  1241. warnings: [],
  1242. warningsByHost: [0]
  1243. }
  1244. },
  1245. {
  1246. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1247. m: 'empty activeJavaProcs',
  1248. e: {
  1249. warnings: [],
  1250. warningsByHost: [0]
  1251. }
  1252. },
  1253. {
  1254. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1255. m: 'not empty hostHealth.activeJavaProcs',
  1256. e: {
  1257. warnings: [{
  1258. pid: 'n1',
  1259. hosts: ['c1'],
  1260. onSingleHost: true,
  1261. category: 'processes'
  1262. }],
  1263. warningsByHost: [1]
  1264. }
  1265. },
  1266. {
  1267. items: [
  1268. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1269. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1270. ],
  1271. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1272. e: {
  1273. warnings: [{
  1274. pid: 'n1',
  1275. hosts: ['c1', 'c2'],
  1276. onSingleHost: false,
  1277. category: 'processes'
  1278. }],
  1279. warningsByHost: [1, 1]
  1280. }
  1281. }
  1282. ])
  1283. }
  1284. ]).forEach(function(category) {
  1285. describe(category.m, function() {
  1286. category.tests.forEach(function(test) {
  1287. it(test.m, function() {
  1288. c.parseWarnings({items: test.items});
  1289. c.get('warnings').forEach(function(w, i) {
  1290. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1291. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1292. });
  1293. });
  1294. for(var i in test.e.warningsByHost) {
  1295. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1296. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1297. }
  1298. }
  1299. });
  1300. });
  1301. });
  1302. });
  1303. });
  1304. describe('#navigateStep', function() {
  1305. Em.A([
  1306. {
  1307. isLoaded: true,
  1308. manualInstall: false,
  1309. bootStatus: false,
  1310. m: 'should call startBootstrap',
  1311. e: true
  1312. },
  1313. {
  1314. isLoaded: true,
  1315. manualInstall: false,
  1316. bootStatus: true,
  1317. m: 'shouldn\'t call startBootstrap (1)',
  1318. e: false
  1319. },
  1320. {
  1321. isLoaded: false,
  1322. manualInstall: false,
  1323. bootStatus: false,
  1324. m: 'shouldn\'t call startBootstrap (2)',
  1325. e: false
  1326. },
  1327. {
  1328. isLoaded: false,
  1329. manualInstall: true,
  1330. bootStatus: false,
  1331. m: 'shouldn\'t call startBootstrap (3)',
  1332. e: false
  1333. }
  1334. ]).forEach(function(test) {
  1335. it(test.m, function() {
  1336. c.reopen({
  1337. isLoaded: test.isLoaded,
  1338. content: {
  1339. installedHosts: [],
  1340. installOptions: {
  1341. manualInstall: test.manualInstall
  1342. }
  1343. },
  1344. wizardController: Em.Object.create({
  1345. getDBProperty: function() {
  1346. return test.bootStatus
  1347. }
  1348. })
  1349. });
  1350. sinon.stub(c, 'startBootstrap', Em.K);
  1351. c.navigateStep();
  1352. if(test.e) {
  1353. expect(c.startBootstrap.calledOnce).to.equal(true);
  1354. }
  1355. else {
  1356. expect(c.startBootstrap.called).to.equal(false);
  1357. }
  1358. c.startBootstrap.restore();
  1359. });
  1360. });
  1361. it('should set test data if testMode is true', function() {
  1362. c.reopen({
  1363. isLoaded: true,
  1364. hosts: [{}, {}, {}],
  1365. content: {
  1366. installedHosts: [],
  1367. installOptions: {
  1368. manualInstall: true
  1369. }
  1370. },
  1371. setRegistrationInProgress: Em.K
  1372. });
  1373. sinon.stub(App, 'get', function(k) {
  1374. if('testMode' === k) return true;
  1375. return Em.get(App, k);
  1376. });
  1377. c.navigateStep();
  1378. App.get.restore();
  1379. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1380. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1381. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1382. expect(c.get('isSubmitDisabled')).to.equal(false);
  1383. });
  1384. it('should start registration', function() {
  1385. c.reopen({
  1386. isLoaded: true,
  1387. hosts: [{}, {}, {}],
  1388. content: {
  1389. installedHosts: [],
  1390. installOptions: {
  1391. manualInstall: true
  1392. }
  1393. },
  1394. setRegistrationInProgress: Em.K,
  1395. startRegistration: Em.K
  1396. });
  1397. sinon.spy(c, 'startRegistration');
  1398. sinon.stub(App, 'get', function(k) {
  1399. if('testMode' === k) return false;
  1400. return Em.get(App, k);
  1401. });
  1402. c.navigateStep();
  1403. App.get.restore();
  1404. expect(c.startRegistration.calledOnce).to.equal(true);
  1405. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1406. expect(c.get('registrationStartedAt')).to.be.null;
  1407. c.startRegistration.restore();
  1408. });
  1409. });
  1410. describe('#checkHostDiskSpace', function() {
  1411. Em.A([
  1412. {
  1413. diskInfo: [
  1414. {
  1415. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1416. mountpoint: '/'
  1417. }
  1418. ],
  1419. m: 'available less than App.minDiskSpace',
  1420. e: false
  1421. },
  1422. {
  1423. diskInfo: [
  1424. {
  1425. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1426. mountpoint: '/usr'
  1427. }
  1428. ],
  1429. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1430. e: false
  1431. },
  1432. {
  1433. diskInfo: [
  1434. {
  1435. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1436. mountpoint: '/usr/lib'
  1437. }
  1438. ],
  1439. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1440. e: false
  1441. },
  1442. {
  1443. diskInfo: [
  1444. {
  1445. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1446. mountpoint: '/'
  1447. }
  1448. ],
  1449. m: 'available greater than App.minDiskSpace',
  1450. e: true
  1451. },
  1452. {
  1453. diskInfo: [
  1454. {
  1455. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1456. mountpoint: '/usr'
  1457. }
  1458. ],
  1459. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1460. e: true
  1461. },
  1462. {
  1463. diskInfo: [
  1464. {
  1465. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1466. mountpoint: '/usr/lib'
  1467. }
  1468. ],
  1469. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1470. e: true
  1471. },
  1472. {
  1473. diskInfo: [
  1474. {
  1475. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1476. mountpoint: '/home/tdk'
  1477. }
  1478. ],
  1479. m: 'mount point without free space checks',
  1480. e: true
  1481. }
  1482. ]).forEach(function (test) {
  1483. it(test.m, function () {
  1484. var r = c.checkHostDiskSpace('', test.diskInfo);
  1485. expect(Em.isEmpty(r)).to.equal(test.e);
  1486. });
  1487. });
  1488. });
  1489. describe('#checkHostOSType', function() {
  1490. it('should return empty string if no stacks provided', function() {
  1491. c.reopen({content: {stacks: null}});
  1492. expect(c.checkHostOSType()).to.equal('');
  1493. });
  1494. it('os type is valid', function() {
  1495. var osType = 'redhat6';
  1496. c.reopen({
  1497. content: {
  1498. stacks: [
  1499. Em.Object.create({isSelected: true, operatingSystems: [{selected: true, osType: osType}]})
  1500. ]
  1501. }
  1502. });
  1503. expect(c.checkHostOSType(osType, '')).to.equal('');
  1504. });
  1505. it('os type is invalid', function() {
  1506. var osType = 'os2';
  1507. c.reopen({
  1508. content: {
  1509. stacks: [
  1510. Em.Object.create({isSelected: true, operatingSystems: [{selected: true, osType: 'os1'}]})
  1511. ]
  1512. }
  1513. });
  1514. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1515. });
  1516. });
  1517. describe('#getHostInfoSuccessCallback', function() {
  1518. beforeEach(function() {
  1519. sinon.stub(c, 'parseWarnings', Em.K);
  1520. sinon.stub(c, 'stopRegistration', Em.K);
  1521. });
  1522. afterEach(function() {
  1523. c.parseWarnings.restore();
  1524. c.stopRegistration.restore();
  1525. });
  1526. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1527. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1528. sinon.stub(App, 'get', function(k) {
  1529. if ('skipBootstrap' === k) return true;
  1530. if ('testMode' === k) return false;
  1531. return Em.get(App, k);
  1532. });
  1533. c.reopen({
  1534. bootHosts: [Em.Object.create({name: 'h1'})]
  1535. });
  1536. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1537. c.getHostInfoSuccessCallback(jsonData);
  1538. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1539. App.get.restore();
  1540. c._setHostDataWithSkipBootstrap.restore();
  1541. });
  1542. it('should add repo warnings', function() {
  1543. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1544. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1545. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1546. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1547. sinon.stub(App, 'get', function(k) {
  1548. if ('skipBootstrap' === k) return false;
  1549. if ('testMode' === k) return false;
  1550. return Em.get(App, k);
  1551. });
  1552. c.reopen({
  1553. bootHosts: [Em.Object.create({name: 'h1'})]
  1554. });
  1555. c.getHostInfoSuccessCallback(jsonData);
  1556. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1557. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1558. c.checkHostOSType.restore();
  1559. c.checkHostDiskSpace.restore();
  1560. c._setHostDataFromLoadedHostInfo.restore();
  1561. App.get.restore();
  1562. });
  1563. it('should add disk warnings', function() {
  1564. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1565. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1566. sinon.stub(c, 'checkHostOSType', Em.K);
  1567. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1568. sinon.stub(App, 'get', function(k) {
  1569. if ('skipBootstrap' === k) return false;
  1570. if ('testMode' === k) return false;
  1571. return Em.get(App, k);
  1572. });
  1573. c.reopen({
  1574. bootHosts: [Em.Object.create({name: 'h1'})]
  1575. });
  1576. c.getHostInfoSuccessCallback(jsonData);
  1577. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1578. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1579. c.checkHostOSType.restore();
  1580. c.checkHostDiskSpace.restore();
  1581. c._setHostDataFromLoadedHostInfo.restore();
  1582. App.get.restore();
  1583. });
  1584. });
  1585. describe('#_setHostDataWithSkipBootstrap', function() {
  1586. it('should set mock-data', function() {
  1587. var host = Em.Object.create({});
  1588. c._setHostDataWithSkipBootstrap(host);
  1589. expect(host.get('cpu')).to.equal(2);
  1590. expect(host.get('memory')).to.equal('2000000.00');
  1591. expect(host.get('disk_info.length')).to.equal(4);
  1592. });
  1593. });
  1594. describe('#_setHostDataFromLoadedHostInfo', function() {
  1595. it('should set data from hostInfo', function() {
  1596. var host = Em.Object.create(),
  1597. hostInfo = {
  1598. Hosts: {
  1599. cpu_count: 2,
  1600. total_mem: 12345,
  1601. os_type: 't1',
  1602. os_arch: 'os1',
  1603. ip: '0.0.0.0',
  1604. disk_info: [
  1605. {mountpoint: '/boot'},
  1606. {mountpoint: '/usr'},
  1607. {mountpoint: '/no-boot'},
  1608. {mountpoint: '/boot'}
  1609. ]
  1610. }
  1611. };
  1612. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1613. expect(host.get('cpu')).to.equal(2);
  1614. expect(host.get('os_type')).to.equal('t1');
  1615. expect(host.get('os_arch')).to.equal('os1');
  1616. expect(host.get('ip')).to.equal('0.0.0.0');
  1617. expect(host.get('memory')).to.equal('12345.00');
  1618. expect(host.get('disk_info.length')).to.equal(2);
  1619. });
  1620. });
  1621. });