step3_test.js 63 KB

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