step3_test.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  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. it('should parse umask warnings', function() {
  1304. var items = [
  1305. {Hosts:{host_name: 'c1', last_agent_env: {umask: 18}}},
  1306. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1307. ];
  1308. c.parseWarnings({items: items});
  1309. var warnings = c.get('warnings');
  1310. expect(warnings.length).to.equal(1);
  1311. expect(warnings[0].hosts).to.eql(['c2']);
  1312. expect(warnings[0].onSingleHost).to.equal(true);
  1313. });
  1314. it('should parse umask warnings (2)', function() {
  1315. var items = [
  1316. {Hosts:{host_name: 'c1', last_agent_env: {umask: 8}}},
  1317. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1318. ];
  1319. c.parseWarnings({items: items});
  1320. var warnings = c.get('warnings');
  1321. expect(warnings.length).to.equal(2);
  1322. expect(warnings.mapProperty('hosts')).to.eql([['c1'], ['c2']]);
  1323. });
  1324. it('should parse firewall warnings', function() {
  1325. var items = [
  1326. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1327. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
  1328. ];
  1329. c.parseWarnings({items: items});
  1330. var warnings = c.get('warnings');
  1331. expect(warnings.length).to.equal(1);
  1332. expect(warnings[0].hosts).to.eql(['c1']);
  1333. expect(warnings[0].onSingleHost).to.equal(true);
  1334. });
  1335. it('should parse firewall warnings (2)', function() {
  1336. var items = [
  1337. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1338. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
  1339. ];
  1340. c.parseWarnings({items: items});
  1341. var warnings = c.get('warnings');
  1342. expect(warnings.length).to.equal(1);
  1343. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1344. expect(warnings[0].onSingleHost).to.equal(false);
  1345. });
  1346. it('should parse reverseLookup warnings', function() {
  1347. var items = [
  1348. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1349. ];
  1350. c.parseWarnings({items: items});
  1351. var warnings = c.get('warnings');
  1352. expect(warnings.length).to.equal(0);
  1353. });
  1354. it('should parse reverseLookup warnings (2)', function() {
  1355. var items = [
  1356. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1357. ];
  1358. c.parseWarnings({items: items});
  1359. var warnings = c.get('warnings');
  1360. expect(warnings.length).to.equal(1);
  1361. expect(warnings[0].hosts).to.eql(['c1']);
  1362. expect(warnings[0].onSingleHost).to.equal(true);
  1363. });
  1364. it('should parse reverseLookup warnings (3)', function() {
  1365. var items = [
  1366. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1367. {Hosts:{host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1368. ];
  1369. c.parseWarnings({items: items});
  1370. var warnings = c.get('warnings');
  1371. expect(warnings.length).to.equal(1);
  1372. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1373. expect(warnings[0].onSingleHost).to.equal(false);
  1374. });
  1375. });
  1376. describe('#navigateStep', function() {
  1377. Em.A([
  1378. {
  1379. isLoaded: true,
  1380. manualInstall: false,
  1381. bootStatus: false,
  1382. m: 'should call startBootstrap',
  1383. e: true
  1384. },
  1385. {
  1386. isLoaded: true,
  1387. manualInstall: false,
  1388. bootStatus: true,
  1389. m: 'shouldn\'t call startBootstrap (1)',
  1390. e: false
  1391. },
  1392. {
  1393. isLoaded: false,
  1394. manualInstall: false,
  1395. bootStatus: false,
  1396. m: 'shouldn\'t call startBootstrap (2)',
  1397. e: false
  1398. },
  1399. {
  1400. isLoaded: false,
  1401. manualInstall: true,
  1402. bootStatus: false,
  1403. m: 'shouldn\'t call startBootstrap (3)',
  1404. e: false
  1405. }
  1406. ]).forEach(function(test) {
  1407. it(test.m, function() {
  1408. c.reopen({
  1409. isLoaded: test.isLoaded,
  1410. content: {
  1411. installedHosts: [],
  1412. installOptions: {
  1413. manualInstall: test.manualInstall
  1414. }
  1415. },
  1416. wizardController: Em.Object.create({
  1417. getDBProperty: function() {
  1418. return test.bootStatus
  1419. }
  1420. })
  1421. });
  1422. sinon.stub(c, 'startBootstrap', Em.K);
  1423. c.navigateStep();
  1424. if(test.e) {
  1425. expect(c.startBootstrap.calledOnce).to.equal(true);
  1426. }
  1427. else {
  1428. expect(c.startBootstrap.called).to.equal(false);
  1429. }
  1430. c.startBootstrap.restore();
  1431. });
  1432. });
  1433. it('should set test data if testMode is true', function() {
  1434. c.reopen({
  1435. isLoaded: true,
  1436. hosts: [{}, {}, {}],
  1437. content: {
  1438. installedHosts: [],
  1439. installOptions: {
  1440. manualInstall: true
  1441. }
  1442. },
  1443. setRegistrationInProgress: Em.K
  1444. });
  1445. sinon.stub(App, 'get', function(k) {
  1446. if('testMode' === k) return true;
  1447. return Em.get(App, k);
  1448. });
  1449. c.navigateStep();
  1450. App.get.restore();
  1451. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1452. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1453. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1454. expect(c.get('isSubmitDisabled')).to.equal(false);
  1455. });
  1456. it('should start registration', function() {
  1457. c.reopen({
  1458. isLoaded: true,
  1459. hosts: [{}, {}, {}],
  1460. content: {
  1461. installedHosts: [],
  1462. installOptions: {
  1463. manualInstall: true
  1464. }
  1465. },
  1466. setRegistrationInProgress: Em.K,
  1467. startRegistration: Em.K
  1468. });
  1469. sinon.spy(c, 'startRegistration');
  1470. sinon.stub(App, 'get', function(k) {
  1471. if('testMode' === k) return false;
  1472. return Em.get(App, k);
  1473. });
  1474. c.navigateStep();
  1475. App.get.restore();
  1476. expect(c.startRegistration.calledOnce).to.equal(true);
  1477. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1478. expect(c.get('registrationStartedAt')).to.be.null;
  1479. c.startRegistration.restore();
  1480. });
  1481. });
  1482. describe('#checkHostDiskSpace', function() {
  1483. Em.A([
  1484. {
  1485. diskInfo: [
  1486. {
  1487. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1488. mountpoint: '/'
  1489. }
  1490. ],
  1491. m: 'available less than App.minDiskSpace',
  1492. e: false
  1493. },
  1494. {
  1495. diskInfo: [
  1496. {
  1497. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1498. mountpoint: '/usr'
  1499. }
  1500. ],
  1501. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1502. e: false
  1503. },
  1504. {
  1505. diskInfo: [
  1506. {
  1507. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1508. mountpoint: '/usr/lib'
  1509. }
  1510. ],
  1511. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1512. e: false
  1513. },
  1514. {
  1515. diskInfo: [
  1516. {
  1517. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1518. mountpoint: '/'
  1519. }
  1520. ],
  1521. m: 'available greater than App.minDiskSpace',
  1522. e: true
  1523. },
  1524. {
  1525. diskInfo: [
  1526. {
  1527. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1528. mountpoint: '/usr'
  1529. }
  1530. ],
  1531. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1532. e: true
  1533. },
  1534. {
  1535. diskInfo: [
  1536. {
  1537. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1538. mountpoint: '/usr/lib'
  1539. }
  1540. ],
  1541. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1542. e: true
  1543. },
  1544. {
  1545. diskInfo: [
  1546. {
  1547. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1548. mountpoint: '/home/tdk'
  1549. }
  1550. ],
  1551. m: 'mount point without free space checks',
  1552. e: true
  1553. }
  1554. ]).forEach(function (test) {
  1555. it(test.m, function () {
  1556. var r = c.checkHostDiskSpace('', test.diskInfo);
  1557. expect(Em.isEmpty(r)).to.equal(test.e);
  1558. });
  1559. });
  1560. });
  1561. describe('#checkHostOSType', function() {
  1562. it('should return empty string if no stacks provided', function() {
  1563. c.reopen({content: {stacks: null}});
  1564. expect(c.checkHostOSType()).to.equal('');
  1565. });
  1566. it('os type is valid', function() {
  1567. var osType = 'redhat6';
  1568. c.reopen({
  1569. content: {
  1570. stacks: [
  1571. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1572. ]
  1573. }
  1574. });
  1575. expect(c.checkHostOSType(osType, '')).to.equal('');
  1576. });
  1577. it('os type is invalid', function() {
  1578. var osType = 'os2';
  1579. c.reopen({
  1580. content: {
  1581. stacks: [
  1582. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1583. ]
  1584. }
  1585. });
  1586. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1587. });
  1588. });
  1589. describe('#getHostInfoSuccessCallback', function() {
  1590. beforeEach(function() {
  1591. sinon.stub(c, 'parseWarnings', Em.K);
  1592. sinon.stub(c, 'stopRegistration', Em.K);
  1593. });
  1594. afterEach(function() {
  1595. c.parseWarnings.restore();
  1596. c.stopRegistration.restore();
  1597. });
  1598. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1599. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1600. sinon.stub(App, 'get', function(k) {
  1601. if ('skipBootstrap' === k) return true;
  1602. if ('testMode' === k) return false;
  1603. return Em.get(App, k);
  1604. });
  1605. c.reopen({
  1606. bootHosts: [Em.Object.create({name: 'h1'})]
  1607. });
  1608. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1609. c.getHostInfoSuccessCallback(jsonData);
  1610. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1611. App.get.restore();
  1612. c._setHostDataWithSkipBootstrap.restore();
  1613. });
  1614. it('should add repo warnings', function() {
  1615. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1616. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1617. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1618. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1619. sinon.stub(App, 'get', function(k) {
  1620. if ('skipBootstrap' === k) return false;
  1621. if ('testMode' === k) return false;
  1622. return Em.get(App, k);
  1623. });
  1624. c.reopen({
  1625. bootHosts: [Em.Object.create({name: 'h1'})]
  1626. });
  1627. c.getHostInfoSuccessCallback(jsonData);
  1628. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1629. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1630. c.checkHostOSType.restore();
  1631. c.checkHostDiskSpace.restore();
  1632. c._setHostDataFromLoadedHostInfo.restore();
  1633. App.get.restore();
  1634. });
  1635. it('should add disk warnings', function() {
  1636. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1637. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1638. sinon.stub(c, 'checkHostOSType', Em.K);
  1639. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1640. sinon.stub(App, 'get', function(k) {
  1641. if ('skipBootstrap' === k) return false;
  1642. if ('testMode' === k) return false;
  1643. return Em.get(App, k);
  1644. });
  1645. c.reopen({
  1646. bootHosts: [Em.Object.create({name: 'h1'})]
  1647. });
  1648. c.getHostInfoSuccessCallback(jsonData);
  1649. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1650. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1651. c.checkHostOSType.restore();
  1652. c.checkHostDiskSpace.restore();
  1653. c._setHostDataFromLoadedHostInfo.restore();
  1654. App.get.restore();
  1655. });
  1656. });
  1657. describe('#_setHostDataWithSkipBootstrap', function() {
  1658. it('should set mock-data', function() {
  1659. var host = Em.Object.create({});
  1660. c._setHostDataWithSkipBootstrap(host);
  1661. expect(host.get('cpu')).to.equal(2);
  1662. expect(host.get('memory')).to.equal('2000000.00');
  1663. expect(host.get('disk_info.length')).to.equal(4);
  1664. });
  1665. });
  1666. describe('#_setHostDataFromLoadedHostInfo', function() {
  1667. it('should set data from hostInfo', function() {
  1668. var host = Em.Object.create(),
  1669. hostInfo = {
  1670. Hosts: {
  1671. cpu_count: 2,
  1672. total_mem: 12345,
  1673. os_type: 't1',
  1674. os_arch: 'os1',
  1675. ip: '0.0.0.0',
  1676. disk_info: [
  1677. {mountpoint: '/boot'},
  1678. {mountpoint: '/usr'},
  1679. {mountpoint: '/no-boot'},
  1680. {mountpoint: '/boot'}
  1681. ]
  1682. }
  1683. };
  1684. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1685. expect(host.get('cpu')).to.equal(2);
  1686. expect(host.get('os_type')).to.equal('t1');
  1687. expect(host.get('os_arch')).to.equal('os1');
  1688. expect(host.get('ip')).to.equal('0.0.0.0');
  1689. expect(host.get('memory')).to.equal('12345.00');
  1690. expect(host.get('disk_info.length')).to.equal(2);
  1691. });
  1692. });
  1693. describe('#getJDKName', function() {
  1694. beforeEach(function() {
  1695. sinon.stub($, 'ajax', Em.K);
  1696. sinon.stub(App, 'get', function(k) {
  1697. if ('testMode' === k) return false;
  1698. return Em.get(App, k);
  1699. });
  1700. });
  1701. afterEach(function() {
  1702. $.ajax.restore();
  1703. App.get.restore();
  1704. });
  1705. it('should do proper request to ambari-server', function() {
  1706. c.getJDKName();
  1707. expect($.ajax.args[0][0].type).to.contain('GET');
  1708. expect($.ajax.args[0][0].url).to.contain('/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/properties/jdk.name,RootServiceComponents/properties/java.home,RootServiceComponents/properties/jdk_location');
  1709. });
  1710. });
  1711. describe('#getJDKNameSuccessCallback', function() {
  1712. it('should set proper data to controller properties', function() {
  1713. var expected = {
  1714. name: 'name',
  1715. home: 'home',
  1716. location: 'location'
  1717. },
  1718. data = {
  1719. RootServiceComponents: {
  1720. properties: {
  1721. 'jdk.name': expected.name,
  1722. 'java.home': expected.home,
  1723. 'jdk_location': expected.location
  1724. }
  1725. }
  1726. };
  1727. c.getJDKNameSuccessCallback(data);
  1728. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  1729. expect(c.get('jdkLocation')).to.equal(expected.location);
  1730. expect(c.get('javaHome')).to.equal(expected.home);
  1731. });
  1732. });
  1733. describe('#doCheckJDK', function() {
  1734. beforeEach(function() {
  1735. sinon.stub($, 'ajax', Em.K);
  1736. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  1737. sinon.stub(App, 'get', function(k) {
  1738. if ('testMode' === k) return false;
  1739. return Em.get(App, k);
  1740. });
  1741. });
  1742. afterEach(function() {
  1743. $.ajax.restore();
  1744. c.setRegistrationInProgressOnce.restore();
  1745. App.get.restore();
  1746. });
  1747. it('should do proper request to the ambari-server', function() {
  1748. var bootHosts = [{name: 'n1'}, {name: 'n2'}],
  1749. javaHome = '/java',
  1750. jdkLocation = '/jdk';
  1751. c.reopen({
  1752. bootHosts: bootHosts,
  1753. javaHome: javaHome,
  1754. jdkLocation: jdkLocation
  1755. });
  1756. c.doCheckJDK();
  1757. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  1758. expect(request.type).to.equal('POST');
  1759. expect(request.url).to.contain('/requests');
  1760. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  1761. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  1762. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  1763. });
  1764. });
  1765. describe('#doCheckJDKsuccessCallback', function() {
  1766. beforeEach(function() {
  1767. sinon.stub($, 'ajax', Em.K);
  1768. sinon.stub(App, 'get', function(k) {
  1769. if ('testMode' === k) return false;
  1770. return Em.get(App, k);
  1771. });
  1772. });
  1773. afterEach(function() {
  1774. $.ajax.restore();
  1775. App.get.restore();
  1776. });
  1777. it('should set jdkRequestIndex if data provided', function() {
  1778. var data = {
  1779. href: '/a/b/c'
  1780. },
  1781. expected = 'c';
  1782. c.set('jdkRequestIndex', null);
  1783. c.doCheckJDKsuccessCallback(data);
  1784. expect(c.get('jdkRequestIndex')).to.equal(expected);
  1785. });
  1786. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function() {
  1787. var data = null,
  1788. expected = true;
  1789. c.set('isJDKWarningsLoaded', false);
  1790. c.set('jdkCategoryWarnings', {});
  1791. c.doCheckJDKsuccessCallback(data);
  1792. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  1793. });
  1794. it('should do propert request to ambari-server', function() {
  1795. var data = null,
  1796. jdkRequestIndex = 'jdkRequestIndex',
  1797. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  1798. c.set('jdkRequestIndex', jdkRequestIndex);
  1799. c.set('jdkCategoryWarnings', null);
  1800. c.doCheckJDKsuccessCallback(data);
  1801. expect($.ajax.args[0][0].type).to.equal('GET');
  1802. expect($.ajax.args[0][0].url).to.contain(url);
  1803. });
  1804. });
  1805. describe('#doCheckJDKerrorCallback', function() {
  1806. it('should set isJDKWarningsLoaded to true', function() {
  1807. c.set('isJDKWarningsLoaded', false);
  1808. c.doCheckJDKerrorCallback();
  1809. c.set('isJDKWarningsLoaded', true);
  1810. });
  1811. });
  1812. describe('#parseJDKCheckResults', function() {
  1813. beforeEach(function() {
  1814. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  1815. });
  1816. afterEach(function() {
  1817. c.doCheckJDKsuccessCallback.restore();
  1818. });
  1819. it('should set jdkCategoryWarnings to null if no data', function() {
  1820. var data = {Requests: {}};
  1821. c.set('jdkCategoryWarnings', {});
  1822. c.parseJDKCheckResults(data);
  1823. expect(c.get('jdkCategoryWarnings')).to.be.null;
  1824. });
  1825. it('should parse warnings (1)', function() {
  1826. var data = {
  1827. Requests: {
  1828. end_time: 1
  1829. },
  1830. tasks: []
  1831. };
  1832. c.set('jdkCategoryWarnings', {});
  1833. c.parseJDKCheckResults(data);
  1834. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  1835. });
  1836. it('should parse warnings (2)', function() {
  1837. var data = {
  1838. Requests: {
  1839. end_time: 1
  1840. },
  1841. tasks: [
  1842. {
  1843. Tasks: {
  1844. host_name: 'h1',
  1845. structured_out: {
  1846. java_home_check: {
  1847. exit_code: 1
  1848. }
  1849. }
  1850. }
  1851. },
  1852. {
  1853. Tasks: {
  1854. host_name: 'h2',
  1855. structured_out: {
  1856. java_home_check: {
  1857. exit_code: 0
  1858. }
  1859. }
  1860. }
  1861. }
  1862. ]
  1863. };
  1864. c.set('jdkCategoryWarnings', {});
  1865. c.parseJDKCheckResults(data);
  1866. var result = c.get('jdkCategoryWarnings');
  1867. expect(result.length).to.equal(1);
  1868. expect(result[0].hostsNames).to.eql(['h1']);
  1869. });
  1870. });
  1871. });