step3_test.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  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.WizardStep3Controller.create({
  459. content: {
  460. installOptions: {
  461. sshKey: 'key',
  462. sshUser: 'root'
  463. },
  464. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } }
  465. },
  466. agentUser: 'user'
  467. });
  468. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  469. controller.setupBootStrap();
  470. expect(installer.launchBootstrap.firstCall.args[0]).to.equal(JSON.stringify({
  471. verbose: true,
  472. sshKey: 'key',
  473. hosts: ['host0', 'host1'],
  474. user: 'root',
  475. userRunAs: item.userRunAs
  476. }));
  477. App.get.restore();
  478. });
  479. });
  480. });
  481. describe('#retryHost', function() {
  482. before(function(){
  483. sinon.spy(c, 'retryHosts');
  484. sinon.stub(App.router, 'get', function() {
  485. return {launchBootstrap: Em.K}
  486. });
  487. sinon.stub(c, 'doBootstrap', Em.K);
  488. });
  489. after(function(){
  490. c.retryHosts.restore();
  491. App.router.get.restore();
  492. c.doBootstrap.restore();
  493. });
  494. it('should callretryHosts with array as arg', function() {
  495. var host = {n: 'c'};
  496. c.set('content', {installOptions: {}});
  497. c.retryHost(host);
  498. expect(c.retryHosts.calledWith([host])).to.equal(true);
  499. });
  500. });
  501. describe('#retrySelectedHosts', function() {
  502. beforeEach(function () {
  503. sinon.spy(c, 'retryHosts');
  504. sinon.stub(App.router, 'get', function () {
  505. return {launchBootstrap: Em.K}
  506. });
  507. sinon.stub(c, 'doBootstrap', Em.K);
  508. });
  509. afterEach(function () {
  510. c.retryHosts.restore();
  511. App.router.get.restore();
  512. c.doBootstrap.restore();
  513. });
  514. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  515. c.set('isRetryDisabled', true);
  516. c.retrySelectedHosts();
  517. expect(c.retryHosts.called).to.equal(false);
  518. });
  519. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  520. c.set('isRetryDisabled', false);
  521. c.set('bootHosts', Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]));
  522. c.retrySelectedHosts();
  523. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  524. expect(c.get('isRetryDisabled')).to.equal(true);
  525. });
  526. });
  527. describe('#startBootstrap', function() {
  528. beforeEach(function(){
  529. sinon.stub(c, 'doBootstrap', Em.K);
  530. });
  531. afterEach(function(){
  532. c.doBootstrap.restore();
  533. });
  534. it('should drop numPolls and registrationStartedAt', function() {
  535. c.set('numPolls', 123);
  536. c.set('registrationStartedAt', 1234);
  537. c.startBootstrap();
  538. expect(c.get('numPolls')).to.equal(0);
  539. expect(c.get('registrationStartedAt')).to.be.null;
  540. });
  541. it('should drop numPolls and registrationStartedAt', function() {
  542. c.set('hosts', Em.A([{name: 'c1'}, {name: 'c2'}]))
  543. c.startBootstrap();
  544. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  545. });
  546. });
  547. describe('#setRegistrationInProgressOnce', function() {
  548. before(function(){
  549. sinon.spy(Em.run, 'once');
  550. });
  551. after(function(){
  552. Em.run.once.restore();
  553. });
  554. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  555. c.setRegistrationInProgressOnce();
  556. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  557. });
  558. });
  559. describe('#setRegistrationInProgress', function() {
  560. var tests = Em.A([
  561. {
  562. bootHosts: [],
  563. isLoaded: false,
  564. e: true,
  565. m: 'no bootHosts and isLoaded is false'
  566. },
  567. {
  568. bootHosts: [],
  569. isLoaded: true,
  570. e: false,
  571. m: 'no bootHosts and isLoaded is true'
  572. },
  573. {
  574. bootHosts: [
  575. Em.Object.create({bootStatus: 'RUNNING'}),
  576. Em.Object.create({bootStatus: 'RUNNING'})
  577. ],
  578. isLoaded: true,
  579. e: true,
  580. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  581. },
  582. {
  583. bootHosts: [
  584. Em.Object.create({bootStatus: 'RUNNING'}),
  585. Em.Object.create({bootStatus: 'RUNNING'})
  586. ],
  587. isLoaded: false,
  588. e: true,
  589. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  590. },
  591. {
  592. bootHosts: [
  593. Em.Object.create({bootStatus: 'REGISTERED'}),
  594. Em.Object.create({bootStatus: 'RUNNING'})
  595. ],
  596. isLoaded: false,
  597. e: true,
  598. m: 'bootHosts with one REGISTERED and isLoaded is false'
  599. },
  600. {
  601. bootHosts: [
  602. Em.Object.create({bootStatus: 'FAILED'}),
  603. Em.Object.create({bootStatus: 'RUNNING'})
  604. ],
  605. isLoaded: false,
  606. e: true,
  607. m: 'bootHosts with one FAILED and isLoaded is false'
  608. },
  609. {
  610. bootHosts: [
  611. Em.Object.create({bootStatus: 'REGISTERED'}),
  612. Em.Object.create({bootStatus: 'RUNNING'})
  613. ],
  614. isLoaded: true,
  615. e: true,
  616. m: 'bootHosts with one REGISTERED and isLoaded is true'
  617. },
  618. {
  619. bootHosts: [
  620. Em.Object.create({bootStatus: 'FAILED'}),
  621. Em.Object.create({bootStatus: 'RUNNING'})
  622. ],
  623. isLoaded: true,
  624. e: true,
  625. m: 'bootHosts with one FAILED and isLoaded is true'
  626. }
  627. ]);
  628. beforeEach(function(){
  629. sinon.stub(c, 'getAllRegisteredHosts', Em.K);
  630. sinon.stub(c, 'disablePreviousSteps', Em.K);
  631. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  632. sinon.stub(c, 'navigateStep', Em.K);
  633. });
  634. afterEach(function(){
  635. c.disablePreviousSteps.restore();
  636. c.getAllRegisteredHosts.restore();
  637. c.setRegistrationInProgressOnce.restore();
  638. c.navigateStep.restore();
  639. });
  640. tests.forEach(function(test) {
  641. it(test.m, function() {
  642. c.set('bootHosts', test.bootHosts);
  643. c.set('isLoaded', test.isLoaded);
  644. c.setRegistrationInProgress();
  645. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  646. });
  647. });
  648. });
  649. describe('#doBootstrap()', function() {
  650. beforeEach(function() {
  651. sinon.spy(App.ajax, 'send');
  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.doBootstrap();
  659. expect(App.ajax.send.called).to.equal(false);
  660. });
  661. it('should increment numPolls if stopBootstrap is false', function() {
  662. c.set('numPolls', 0);
  663. c.set('stopBootstrap', false);
  664. c.doBootstrap();
  665. expect(App.ajax.send.calledOnce).to.be.true;
  666. expect(c.get('numPolls')).to.equal(1);
  667. });
  668. });
  669. describe('#startRegistration', function() {
  670. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  671. c.set('registrationStartedAt', 1234);
  672. sinon.spy(c, 'isHostsRegistered');
  673. c.startRegistration();
  674. expect(c.isHostsRegistered.called).to.equal(false);
  675. expect(c.get('registrationStartedAt')).to.equal(1234);
  676. c.isHostsRegistered.restore();
  677. });
  678. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  679. c.set('registrationStartedAt', null);
  680. sinon.spy(c, 'isHostsRegistered');
  681. c.startRegistration();
  682. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  683. c.isHostsRegistered.restore();
  684. });
  685. });
  686. describe('#isHostsRegistered', function() {
  687. beforeEach(function() {
  688. sinon.stub(App.ajax, 'send', function() {return {retry: function() {return {then: Em.K}}}});
  689. });
  690. afterEach(function() {
  691. App.ajax.send.restore();
  692. });
  693. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  694. c.set('stopBootstrap', true);
  695. c.isHostsRegistered();
  696. expect(App.ajax.send.called).to.equal(false);
  697. });
  698. it('should do ajax call if stopBootstrap is false', function() {
  699. c.set('stopBootstrap', false);
  700. c.isHostsRegistered();
  701. expect(App.ajax.send.called).to.equal(true);
  702. });
  703. });
  704. describe('#isHostsRegisteredSuccessCallback', function() {
  705. var tests = Em.A([
  706. {
  707. bootHosts: Em.A([
  708. Em.Object.create({bootStatus: 'DONE'})
  709. ]),
  710. data: {items:[]},
  711. registrationStartedAt: 1000000,
  712. m: 'one host DONE',
  713. e: {
  714. bs: 'REGISTERING',
  715. getHostInfoCalled: false
  716. }
  717. },
  718. {
  719. bootHosts: Em.A([
  720. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  721. ]),
  722. data: {items:[{Hosts: {host_name: 'c1'}}]},
  723. m: ' one host REGISTERING',
  724. e: {
  725. bs: 'REGISTERED',
  726. getHostInfoCalled: false
  727. }
  728. },
  729. {
  730. bootHosts: Em.A([
  731. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  732. ]),
  733. data: {items:[{Hosts: {host_name: 'c2'}}]},
  734. registrationStartedAt: 0,
  735. m: 'one host REGISTERING but data missing info about it, timeout',
  736. e: {
  737. bs: 'FAILED',
  738. getHostInfoCalled: false
  739. }
  740. },
  741. {
  742. bootHosts: Em.A([
  743. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  744. ]),
  745. data: {items:[{Hosts: {host_name: 'c2'}}]},
  746. registrationStartedAt: 1000000,
  747. m: 'one host REGISTERING but data missing info about it',
  748. e: {
  749. bs: 'REGISTERING',
  750. getHostInfoCalled: false
  751. }
  752. },
  753. {
  754. bootHosts: Em.A([
  755. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  756. ]),
  757. data: {items:[{Hosts: {host_name: 'c1'}}]},
  758. m: ' one host RUNNING',
  759. e: {
  760. bs: 'RUNNING',
  761. getHostInfoCalled: false
  762. }
  763. }
  764. ]);
  765. beforeEach(function(){
  766. sinon.spy(c, 'getHostInfo');
  767. sinon.stub(App, 'dateTime').returns(1000000);
  768. });
  769. afterEach(function(){
  770. c.getHostInfo.restore();
  771. App.dateTime.restore();
  772. });
  773. tests.forEach(function(test) {
  774. it(test.m, function() {
  775. c.set('content.installedHosts', []);
  776. c.set('bootHosts', test.bootHosts);
  777. c.set('registrationStartedAt', test.registrationStartedAt);
  778. c.isHostsRegisteredSuccessCallback(test.data);
  779. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  780. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  781. });
  782. });
  783. });
  784. describe('#getAllRegisteredHosts', function() {
  785. it('should call App.ajax.send', function() {
  786. sinon.spy(App.ajax, 'send');
  787. c.getAllRegisteredHosts();
  788. expect(App.ajax.send.calledOnce).to.equal(true);
  789. App.ajax.send.restore();
  790. });
  791. });
  792. describe('#getAllRegisteredHostsCallback', function() {
  793. var tests = Em.A([
  794. {
  795. hostsInCluster: ['c3'],
  796. bootHosts: [{name:'c1'},{name:'c2'}],
  797. hosts: Em.A([
  798. {Hosts: {host_name:'c1'}},
  799. {Hosts: {host_name:'c2'}}
  800. ]),
  801. m: 'No registered hosts',
  802. e: {
  803. hasMoreRegisteredHosts: false,
  804. registeredHosts: ''
  805. }
  806. },
  807. {
  808. hostsInCluster: ['c4'],
  809. bootHosts: [{name:'c3'},{name:'c5'}],
  810. hosts: Em.A([
  811. {Hosts: {host_name:'c1'}},
  812. {Hosts: {host_name:'c2'}}
  813. ]),
  814. m: '2 registered hosts',
  815. e: {
  816. hasMoreRegisteredHosts: true,
  817. registeredHosts: ['c1','c2']
  818. }
  819. },
  820. {
  821. hostsInCluster: ['c4'],
  822. bootHosts: [{name:'c1'},{name:'c5'}],
  823. hosts: Em.A([
  824. {Hosts: {host_name:'c1'}},
  825. {Hosts: {host_name:'c2'}}
  826. ]),
  827. m: '1 registered host',
  828. e: {
  829. hasMoreRegisteredHosts: true,
  830. registeredHosts: ['c2']
  831. }
  832. },
  833. {
  834. hostsInCluster: ['c1'],
  835. bootHosts: [{name:'c3'},{name:'c5'}],
  836. hosts: Em.A([
  837. {Hosts: {host_name:'c1'}},
  838. {Hosts: {host_name:'c2'}}
  839. ]),
  840. m: '1 registered host (2)',
  841. e: {
  842. hasMoreRegisteredHosts: true,
  843. registeredHosts: ['c2']
  844. }
  845. }
  846. ]);
  847. tests.forEach(function(test) {
  848. it(test.m, function() {
  849. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  850. c.set('bootHosts', test.bootHosts);
  851. c.getAllRegisteredHostsCallback({items:test.hosts});
  852. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  853. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  854. });
  855. });
  856. });
  857. describe('#registerErrPopup', function() {
  858. it('should call App.ModalPopup.show', function() {
  859. sinon.spy(App.ModalPopup, 'show');
  860. c.registerErrPopup();
  861. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  862. App.ModalPopup.show.restore();
  863. });
  864. });
  865. describe('#getHostInfo', function() {
  866. it('should do ajax request', function() {
  867. sinon.spy(App.ajax, 'send');
  868. c.getHostInfo();
  869. expect(App.ajax.send.calledOnce).to.equal(true);
  870. App.ajax.send.restore();
  871. });
  872. });
  873. describe('#getHostInfoErrorCallback', function() {
  874. it('should call registerErrPopup', function() {
  875. sinon.spy(c, 'registerErrPopup');
  876. c.getHostInfoErrorCallback();
  877. expect(c.registerErrPopup.calledOnce).to.equal(true);
  878. c.registerErrPopup.restore();
  879. });
  880. });
  881. describe('#stopRegistration', function() {
  882. var tests = Em.A([
  883. {
  884. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  885. e: {isSubmitDisabled: false, isRetryDisabled: true}
  886. },
  887. {
  888. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  889. e: {isSubmitDisabled: true, isRetryDisabled: false}
  890. },
  891. {
  892. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  893. e: {isSubmitDisabled: false, isRetryDisabled: false}
  894. },
  895. {
  896. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  897. e: {isSubmitDisabled: true, isRetryDisabled: true}
  898. }
  899. ]);
  900. tests.forEach(function(test) {
  901. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  902. c.reopen({bootHosts: test.bootHosts});
  903. c.stopRegistration();
  904. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  905. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  906. });
  907. });
  908. });
  909. describe('#submit', function() {
  910. it('if isHostHaveWarnings should show confirmation popup', function() {
  911. c.reopen({isHostHaveWarnings: true});
  912. sinon.spy(App.ModalPopup, 'show');
  913. c.submit();
  914. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  915. App.ModalPopup.show.restore();
  916. });
  917. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  918. var bootHosts = [{name: 'c1'}];
  919. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  920. c.submit().onPrimary();
  921. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  922. });
  923. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  924. var bootHosts = [{name: 'c1'}];
  925. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  926. c.submit();
  927. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  928. });
  929. });
  930. describe('#hostLogPopup', function() {
  931. it('should show App.ModalPopup', function() {
  932. sinon.spy(App.ModalPopup, 'show');
  933. c.hostLogPopup({context:Em.Object.create({})});
  934. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  935. App.ModalPopup.show.restore();
  936. });
  937. });
  938. describe('#rerunChecksSuccessCallback', function() {
  939. beforeEach(function() {
  940. sinon.stub(c, 'parseWarnings', Em.K);
  941. });
  942. afterEach(function() {
  943. c.parseWarnings.restore();
  944. });
  945. it('should set checksUpdateProgress to 100', function() {
  946. c.set('checksUpdateProgress', 0);
  947. c.rerunChecksSuccessCallback({items: []});
  948. expect(c.get('checksUpdateProgress')).to.equal(100);
  949. });
  950. it('should set checksUpdateStatus to SUCCESS', function() {
  951. c.set('checksUpdateStatus', '');
  952. c.rerunChecksSuccessCallback({items: []});
  953. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  954. });
  955. it('should call parseWarnings', function() {
  956. c.rerunChecksSuccessCallback({items: []});
  957. expect(c.parseWarnings.calledOnce).to.equal(true);
  958. });
  959. });
  960. describe('#rerunChecksErrorCallback', function() {
  961. it('should set checksUpdateProgress to 100', function() {
  962. c.set('checksUpdateProgress', 0);
  963. c.rerunChecksErrorCallback({});
  964. expect(c.get('checksUpdateProgress')).to.equal(100);
  965. });
  966. it('should set checksUpdateStatus to FAILED', function() {
  967. c.set('checksUpdateStatus', '');
  968. c.rerunChecksErrorCallback({});
  969. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  970. });
  971. });
  972. describe('#filterBootHosts', function() {
  973. var tests = Em.A([
  974. {
  975. bootHosts: [
  976. Em.Object.create({name: 'c1'}),
  977. Em.Object.create({name: 'c2'})
  978. ],
  979. data: {
  980. items: [
  981. {Hosts: {host_name: 'c1'}}
  982. ]
  983. },
  984. m: 'one host',
  985. e: ['c1']
  986. },
  987. {
  988. bootHosts: [
  989. Em.Object.create({name: 'c1'}),
  990. Em.Object.create({name: 'c2'})
  991. ],
  992. data: {
  993. items: [
  994. {Hosts: {host_name: 'c3'}}
  995. ]
  996. },
  997. m: 'no hosts',
  998. e: []
  999. },
  1000. {
  1001. bootHosts: [
  1002. Em.Object.create({name: 'c1'}),
  1003. Em.Object.create({name: 'c2'})
  1004. ],
  1005. data: {
  1006. items: [
  1007. {Hosts: {host_name: 'c1'}},
  1008. {Hosts: {host_name: 'c2'}}
  1009. ]
  1010. },
  1011. m: 'many hosts',
  1012. e: ['c1', 'c2']
  1013. }
  1014. ]);
  1015. tests.forEach(function(test) {
  1016. it(test.m, function() {
  1017. c.reopen({bootHosts: test.bootHosts});
  1018. var filteredData = c.filterBootHosts(test.data);
  1019. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1020. });
  1021. });
  1022. });
  1023. describe('#hostWarningsPopup', function() {
  1024. it('should show App.ModalPopup', function() {
  1025. sinon.stub(App.ModalPopup, 'show', Em.K);
  1026. c.hostWarningsPopup();
  1027. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1028. App.ModalPopup.show.restore();
  1029. });
  1030. it('should clear checksUpdateStatus on primary', function() {
  1031. c.set('checksUpdateStatus', 'not null value');
  1032. c.hostWarningsPopup().onPrimary();
  1033. expect(c.get('checksUpdateStatus')).to.be.null;
  1034. });
  1035. it('should clear checksUpdateStatus on close', function() {
  1036. c.set('checksUpdateStatus', 'not null value');
  1037. c.hostWarningsPopup().onClose();
  1038. expect(c.get('checksUpdateStatus')).to.be.null;
  1039. });
  1040. it('should rerunChecks onSecondary', function() {
  1041. sinon.stub(c, 'rerunChecks', Em.K);
  1042. c.hostWarningsPopup().onSecondary();
  1043. expect(c.rerunChecks.calledOnce).to.equal(true);
  1044. });
  1045. });
  1046. describe('#registeredHostsPopup', function() {
  1047. it('should show App.ModalPopup', function() {
  1048. sinon.spy(App.ModalPopup, 'show');
  1049. c.registeredHostsPopup();
  1050. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1051. App.ModalPopup.show.restore();
  1052. });
  1053. });
  1054. describe('#parseWarnings', function() {
  1055. beforeEach(function() {
  1056. sinon.stub(App, 'get', function(k) {
  1057. if ('testMode' === k) return false;
  1058. return Em.get(App, k);
  1059. });
  1060. sinon.stub(c, 'filterBootHosts', function(k) {return k;});
  1061. });
  1062. afterEach(function() {
  1063. App.get.restore();
  1064. c.filterBootHosts.restore();
  1065. });
  1066. it('no warnings if last_agent_env isn\'t specified', function() {
  1067. c.set('warnings', [{}]);
  1068. c.set('warningsByHost', [{},{}]);
  1069. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  1070. expect(c.get('warnings')).to.eql([]);
  1071. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1072. });
  1073. Em.A([
  1074. {
  1075. m: 'parse stackFoldersAndFiles',
  1076. tests : Em.A([
  1077. {
  1078. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  1079. m: 'empty stackFoldersAndFiles',
  1080. e: {
  1081. warnings: [],
  1082. warningsByHost: [0]
  1083. }
  1084. },
  1085. {
  1086. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  1087. m: 'not empty stackFoldersAndFiles',
  1088. e: {
  1089. warnings: [{
  1090. name: 'n1',
  1091. hosts: ['c1'],
  1092. onSingleHost: true,
  1093. category: 'fileFolders'
  1094. }],
  1095. warningsByHost: [1]
  1096. }
  1097. },
  1098. {
  1099. items: [
  1100. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1101. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1102. ],
  1103. m: 'not empty stackFoldersAndFiles on two hosts',
  1104. e: {
  1105. warnings: [{
  1106. name: 'n1',
  1107. hosts: ['c1', 'c2'],
  1108. onSingleHost: false,
  1109. category: 'fileFolders'
  1110. }],
  1111. warningsByHost: [1]
  1112. }
  1113. }
  1114. ])
  1115. },
  1116. {
  1117. m: 'parse installedPackages',
  1118. tests : Em.A([
  1119. {
  1120. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1121. m: 'empty installedPackages',
  1122. e: {
  1123. warnings: [],
  1124. warningsByHost: [0]
  1125. }
  1126. },
  1127. {
  1128. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1129. m: 'not empty installedPackages',
  1130. e: {
  1131. warnings: [{
  1132. name: 'n1',
  1133. hosts: ['c1'],
  1134. onSingleHost: true,
  1135. category: 'packages'
  1136. }],
  1137. warningsByHost: [1]
  1138. }
  1139. },
  1140. {
  1141. items: [
  1142. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1143. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1144. ],
  1145. m: 'not empty installedPackages on two hosts',
  1146. e: {
  1147. warnings: [{
  1148. name: 'n1',
  1149. hosts: ['c1', 'c2'],
  1150. onSingleHost: false,
  1151. category: 'packages'
  1152. }],
  1153. warningsByHost: [1]
  1154. }
  1155. }
  1156. ])
  1157. },
  1158. {
  1159. m: 'parse hostHealth.liveServices',
  1160. tests : Em.A([
  1161. {
  1162. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1163. m: 'empty hostHealth',
  1164. e: {
  1165. warnings: [],
  1166. warningsByHost: [0]
  1167. }
  1168. },
  1169. {
  1170. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1171. m: 'empty liveServices',
  1172. e: {
  1173. warnings: [],
  1174. warningsByHost: [0]
  1175. }
  1176. },
  1177. {
  1178. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1179. m: 'not empty hostHealth.liveServices',
  1180. e: {
  1181. warnings: [{
  1182. name: 'n1',
  1183. hosts: ['c1'],
  1184. onSingleHost: true,
  1185. category: 'services'
  1186. }],
  1187. warningsByHost: [1]
  1188. }
  1189. },
  1190. {
  1191. items: [
  1192. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1193. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1194. ],
  1195. m: 'not empty hostHealth.liveServices on two hosts',
  1196. e: {
  1197. warnings: [{
  1198. name: 'n1',
  1199. hosts: ['c1', 'c2'],
  1200. onSingleHost: false,
  1201. category: 'services'
  1202. }],
  1203. warningsByHost: [1, 1]
  1204. }
  1205. }
  1206. ])
  1207. },
  1208. {
  1209. m: 'parse existingUsers',
  1210. tests : Em.A([
  1211. {
  1212. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1213. m: 'empty existingUsers',
  1214. e: {
  1215. warnings: [],
  1216. warningsByHost: [0]
  1217. }
  1218. },
  1219. {
  1220. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1221. m: 'not empty existingUsers',
  1222. e: {
  1223. warnings: [{
  1224. name: 'n1',
  1225. hosts: ['c1'],
  1226. onSingleHost: true,
  1227. category: 'users'
  1228. }],
  1229. warningsByHost: [1]
  1230. }
  1231. },
  1232. {
  1233. items: [
  1234. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1235. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1236. ],
  1237. m: 'not empty existingUsers on two hosts',
  1238. e: {
  1239. warnings: [{
  1240. name: 'n1',
  1241. hosts: ['c1', 'c2'],
  1242. onSingleHost: false,
  1243. category: 'users'
  1244. }],
  1245. warningsByHost: [1, 1]
  1246. }
  1247. }
  1248. ])
  1249. },
  1250. {
  1251. m: 'parse alternatives',
  1252. tests : Em.A([
  1253. {
  1254. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1255. m: 'empty alternatives',
  1256. e: {
  1257. warnings: [],
  1258. warningsByHost: [0]
  1259. }
  1260. },
  1261. {
  1262. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1263. m: 'not empty alternatives',
  1264. e: {
  1265. warnings: [{
  1266. name: 'n1',
  1267. hosts: ['c1'],
  1268. onSingleHost: true,
  1269. category: 'alternatives'
  1270. }],
  1271. warningsByHost: [1]
  1272. }
  1273. },
  1274. {
  1275. items: [
  1276. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1277. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1278. ],
  1279. m: 'not empty alternatives on two hosts',
  1280. e: {
  1281. warnings: [{
  1282. name: 'n1',
  1283. hosts: ['c1', 'c2'],
  1284. onSingleHost: false,
  1285. category: 'alternatives'
  1286. }],
  1287. warningsByHost: [1, 1]
  1288. }
  1289. }
  1290. ])
  1291. },
  1292. {
  1293. m: 'parse hostHealth.activeJavaProcs',
  1294. tests : Em.A([
  1295. {
  1296. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1297. m: 'empty hostHealth',
  1298. e: {
  1299. warnings: [],
  1300. warningsByHost: [0]
  1301. }
  1302. },
  1303. {
  1304. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1305. m: 'empty activeJavaProcs',
  1306. e: {
  1307. warnings: [],
  1308. warningsByHost: [0]
  1309. }
  1310. },
  1311. {
  1312. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1313. m: 'not empty hostHealth.activeJavaProcs',
  1314. e: {
  1315. warnings: [{
  1316. pid: 'n1',
  1317. hosts: ['c1'],
  1318. onSingleHost: true,
  1319. category: 'processes'
  1320. }],
  1321. warningsByHost: [1]
  1322. }
  1323. },
  1324. {
  1325. items: [
  1326. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1327. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1328. ],
  1329. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1330. e: {
  1331. warnings: [{
  1332. pid: 'n1',
  1333. hosts: ['c1', 'c2'],
  1334. onSingleHost: false,
  1335. category: 'processes'
  1336. }],
  1337. warningsByHost: [1, 1]
  1338. }
  1339. }
  1340. ])
  1341. }
  1342. ]).forEach(function(category) {
  1343. describe(category.m, function() {
  1344. category.tests.forEach(function(test) {
  1345. it(test.m, function() {
  1346. c.parseWarnings({items: test.items});
  1347. c.get('warnings').forEach(function(w, i) {
  1348. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1349. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1350. });
  1351. });
  1352. for(var i in test.e.warningsByHost) {
  1353. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1354. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1355. }
  1356. }
  1357. });
  1358. });
  1359. });
  1360. });
  1361. it('should parse umask warnings', function() {
  1362. var items = [
  1363. {Hosts:{host_name: 'c1', last_agent_env: {umask: 18}}},
  1364. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1365. ];
  1366. c.parseWarnings({items: items});
  1367. var warnings = c.get('warnings');
  1368. expect(warnings.length).to.equal(1);
  1369. expect(warnings[0].hosts).to.eql(['c2']);
  1370. expect(warnings[0].onSingleHost).to.equal(true);
  1371. });
  1372. it('should parse umask warnings (2)', function() {
  1373. var items = [
  1374. {Hosts:{host_name: 'c1', last_agent_env: {umask: 8}}},
  1375. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1376. ];
  1377. c.parseWarnings({items: items});
  1378. var warnings = c.get('warnings');
  1379. expect(warnings.length).to.equal(2);
  1380. expect(warnings.mapProperty('hosts')).to.eql([['c1'], ['c2']]);
  1381. });
  1382. it('should parse firewall warnings', function() {
  1383. var items = [
  1384. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1385. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
  1386. ];
  1387. c.parseWarnings({items: items});
  1388. var warnings = c.get('warnings');
  1389. expect(warnings.length).to.equal(1);
  1390. expect(warnings[0].hosts).to.eql(['c1']);
  1391. expect(warnings[0].onSingleHost).to.equal(true);
  1392. });
  1393. it('should parse firewall warnings (2)', function() {
  1394. var items = [
  1395. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1396. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
  1397. ];
  1398. c.parseWarnings({items: items});
  1399. var warnings = c.get('warnings');
  1400. expect(warnings.length).to.equal(1);
  1401. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1402. expect(warnings[0].onSingleHost).to.equal(false);
  1403. });
  1404. it('should parse reverseLookup warnings', function() {
  1405. var items = [
  1406. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1407. ];
  1408. c.parseWarnings({items: items});
  1409. var warnings = c.get('warnings');
  1410. expect(warnings.length).to.equal(0);
  1411. });
  1412. it('should parse reverseLookup warnings (2)', function() {
  1413. var items = [
  1414. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1415. ];
  1416. c.parseWarnings({items: items});
  1417. var warnings = c.get('warnings');
  1418. expect(warnings.length).to.equal(1);
  1419. expect(warnings[0].hosts).to.eql(['c1']);
  1420. expect(warnings[0].onSingleHost).to.equal(true);
  1421. });
  1422. it('should parse reverseLookup warnings (3)', function() {
  1423. var items = [
  1424. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1425. {Hosts:{host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1426. ];
  1427. c.parseWarnings({items: items});
  1428. var warnings = c.get('warnings');
  1429. expect(warnings.length).to.equal(1);
  1430. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1431. expect(warnings[0].onSingleHost).to.equal(false);
  1432. });
  1433. });
  1434. describe('#navigateStep', function() {
  1435. beforeEach(function(){
  1436. sinon.stub(c, 'setupBootStrap', Em.K);
  1437. });
  1438. afterEach(function(){
  1439. c.setupBootStrap.restore();
  1440. });
  1441. Em.A([
  1442. {
  1443. isLoaded: true,
  1444. manualInstall: false,
  1445. bootStatus: false,
  1446. m: 'should call setupBootStrap',
  1447. e: true
  1448. },
  1449. {
  1450. isLoaded: true,
  1451. manualInstall: false,
  1452. bootStatus: true,
  1453. m: 'shouldn\'t call setupBootStrap (1)',
  1454. e: false
  1455. },
  1456. {
  1457. isLoaded: false,
  1458. manualInstall: false,
  1459. bootStatus: false,
  1460. m: 'shouldn\'t call setupBootStrap (2)',
  1461. e: false
  1462. },
  1463. {
  1464. isLoaded: false,
  1465. manualInstall: true,
  1466. bootStatus: false,
  1467. m: 'shouldn\'t call setupBootStrap (3)',
  1468. e: false
  1469. }
  1470. ]).forEach(function(test) {
  1471. it(test.m, function() {
  1472. c.reopen({
  1473. isLoaded: test.isLoaded,
  1474. content: {
  1475. installedHosts: [],
  1476. installOptions: {
  1477. manualInstall: test.manualInstall
  1478. }
  1479. },
  1480. wizardController: Em.Object.create({
  1481. getDBProperty: function() {
  1482. return test.bootStatus
  1483. }
  1484. })
  1485. });
  1486. c.navigateStep();
  1487. if(test.e) {
  1488. expect(c.setupBootStrap.calledOnce).to.equal(true);
  1489. }
  1490. else {
  1491. expect(c.setupBootStrap.called).to.equal(false);
  1492. }
  1493. });
  1494. });
  1495. it('should set test data if testMode is true', function() {
  1496. c.reopen({
  1497. isLoaded: true,
  1498. hosts: [{}, {}, {}],
  1499. content: {
  1500. installedHosts: [],
  1501. installOptions: {
  1502. manualInstall: true
  1503. }
  1504. },
  1505. setRegistrationInProgress: Em.K
  1506. });
  1507. sinon.stub(App, 'get', function(k) {
  1508. if('testMode' === k) return true;
  1509. return Em.get(App, k);
  1510. });
  1511. c.navigateStep();
  1512. App.get.restore();
  1513. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1514. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1515. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1516. expect(c.get('isSubmitDisabled')).to.equal(false);
  1517. });
  1518. it('should start registration', function() {
  1519. c.reopen({
  1520. isLoaded: true,
  1521. hosts: [{}, {}, {}],
  1522. content: {
  1523. installedHosts: [],
  1524. installOptions: {
  1525. manualInstall: true
  1526. }
  1527. },
  1528. setRegistrationInProgress: Em.K,
  1529. startRegistration: Em.K
  1530. });
  1531. sinon.spy(c, 'startRegistration');
  1532. sinon.stub(App, 'get', function(k) {
  1533. if('testMode' === k) return false;
  1534. return Em.get(App, k);
  1535. });
  1536. c.navigateStep();
  1537. App.get.restore();
  1538. expect(c.startRegistration.calledOnce).to.equal(true);
  1539. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1540. expect(c.get('registrationStartedAt')).to.be.null;
  1541. c.startRegistration.restore();
  1542. });
  1543. });
  1544. describe('#setupBootStrap', function () {
  1545. var cases = [
  1546. {
  1547. customizeAgentUserAccount: true,
  1548. userRunAs: 'user',
  1549. title: 'Ambari Agent user account customize enabled'
  1550. },
  1551. {
  1552. customizeAgentUserAccount: false,
  1553. userRunAs: 'root',
  1554. title: 'Ambari Agent user account customize disabled'
  1555. }
  1556. ],
  1557. controller = App.WizardStep3Controller.create({
  1558. content: {
  1559. installOptions: {
  1560. sshKey: 'key',
  1561. sshUser: 'root'
  1562. },
  1563. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } },
  1564. controllerName: 'installerController'
  1565. },
  1566. agentUser: 'user'
  1567. });
  1568. beforeEach(function () {
  1569. sinon.spy(App.router.get('installerController'), 'launchBootstrap');
  1570. });
  1571. afterEach(function () {
  1572. App.router.get('installerController.launchBootstrap').restore();
  1573. App.get.restore();
  1574. });
  1575. cases.forEach(function (item) {
  1576. it(item.title, function () {
  1577. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  1578. controller.setupBootStrap();
  1579. expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
  1580. verbose: true,
  1581. sshKey: 'key',
  1582. hosts: ['host0', 'host1'],
  1583. user: 'root',
  1584. userRunAs: item.userRunAs
  1585. }));
  1586. });
  1587. });
  1588. });
  1589. describe('#checkHostDiskSpace', function() {
  1590. Em.A([
  1591. {
  1592. diskInfo: [
  1593. {
  1594. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1595. mountpoint: '/'
  1596. }
  1597. ],
  1598. m: 'available less than App.minDiskSpace',
  1599. e: false
  1600. },
  1601. {
  1602. diskInfo: [
  1603. {
  1604. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1605. mountpoint: '/usr'
  1606. }
  1607. ],
  1608. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1609. e: false
  1610. },
  1611. {
  1612. diskInfo: [
  1613. {
  1614. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1615. mountpoint: '/usr/lib'
  1616. }
  1617. ],
  1618. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1619. e: false
  1620. },
  1621. {
  1622. diskInfo: [
  1623. {
  1624. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1625. mountpoint: '/'
  1626. }
  1627. ],
  1628. m: 'available greater than App.minDiskSpace',
  1629. e: true
  1630. },
  1631. {
  1632. diskInfo: [
  1633. {
  1634. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1635. mountpoint: '/usr'
  1636. }
  1637. ],
  1638. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1639. e: true
  1640. },
  1641. {
  1642. diskInfo: [
  1643. {
  1644. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1645. mountpoint: '/usr/lib'
  1646. }
  1647. ],
  1648. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1649. e: true
  1650. },
  1651. {
  1652. diskInfo: [
  1653. {
  1654. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1655. mountpoint: '/home/tdk'
  1656. }
  1657. ],
  1658. m: 'mount point without free space checks',
  1659. e: true
  1660. }
  1661. ]).forEach(function (test) {
  1662. it(test.m, function () {
  1663. var r = c.checkHostDiskSpace('', test.diskInfo);
  1664. expect(Em.isEmpty(r)).to.equal(test.e);
  1665. });
  1666. });
  1667. });
  1668. describe('#checkHostOSType', function() {
  1669. it('should return empty string if no stacks provided', function() {
  1670. c.reopen({content: {stacks: null}});
  1671. expect(c.checkHostOSType()).to.equal('');
  1672. });
  1673. it('os type is valid', function() {
  1674. var osType = 'redhat6';
  1675. c.reopen({
  1676. content: {
  1677. stacks: [
  1678. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1679. ]
  1680. }
  1681. });
  1682. expect(c.checkHostOSType(osType, '')).to.equal('');
  1683. });
  1684. it('os type is invalid', function() {
  1685. var osType = 'os2';
  1686. c.reopen({
  1687. content: {
  1688. stacks: [
  1689. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1690. ]
  1691. }
  1692. });
  1693. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1694. });
  1695. });
  1696. describe('#getHostInfoSuccessCallback', function() {
  1697. beforeEach(function() {
  1698. sinon.stub(c, 'parseWarnings', Em.K);
  1699. sinon.stub(c, 'stopRegistration', Em.K);
  1700. });
  1701. afterEach(function() {
  1702. c.parseWarnings.restore();
  1703. c.stopRegistration.restore();
  1704. });
  1705. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1706. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1707. sinon.stub(App, 'get', function(k) {
  1708. if ('skipBootstrap' === k) return true;
  1709. if ('testMode' === k) return false;
  1710. return Em.get(App, k);
  1711. });
  1712. c.reopen({
  1713. bootHosts: [Em.Object.create({name: 'h1'})]
  1714. });
  1715. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1716. c.getHostInfoSuccessCallback(jsonData);
  1717. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1718. App.get.restore();
  1719. c._setHostDataWithSkipBootstrap.restore();
  1720. });
  1721. it('should add repo warnings', function() {
  1722. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1723. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1724. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1725. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1726. sinon.stub(App, 'get', function(k) {
  1727. if ('skipBootstrap' === k) return false;
  1728. if ('testMode' === k) return false;
  1729. return Em.get(App, k);
  1730. });
  1731. c.reopen({
  1732. bootHosts: [Em.Object.create({name: 'h1'})]
  1733. });
  1734. c.getHostInfoSuccessCallback(jsonData);
  1735. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1736. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1737. c.checkHostOSType.restore();
  1738. c.checkHostDiskSpace.restore();
  1739. c._setHostDataFromLoadedHostInfo.restore();
  1740. App.get.restore();
  1741. });
  1742. it('should add disk warnings', function() {
  1743. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1744. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1745. sinon.stub(c, 'checkHostOSType', Em.K);
  1746. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1747. sinon.stub(App, 'get', function(k) {
  1748. if ('skipBootstrap' === k) return false;
  1749. if ('testMode' === k) return false;
  1750. return Em.get(App, k);
  1751. });
  1752. c.reopen({
  1753. bootHosts: [Em.Object.create({name: 'h1'})]
  1754. });
  1755. c.getHostInfoSuccessCallback(jsonData);
  1756. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1757. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1758. c.checkHostOSType.restore();
  1759. c.checkHostDiskSpace.restore();
  1760. c._setHostDataFromLoadedHostInfo.restore();
  1761. App.get.restore();
  1762. });
  1763. });
  1764. describe('#_setHostDataWithSkipBootstrap', function() {
  1765. it('should set mock-data', function() {
  1766. var host = Em.Object.create({});
  1767. c._setHostDataWithSkipBootstrap(host);
  1768. expect(host.get('cpu')).to.equal(2);
  1769. expect(host.get('memory')).to.equal('2000000.00');
  1770. expect(host.get('disk_info.length')).to.equal(4);
  1771. });
  1772. });
  1773. describe('#_setHostDataFromLoadedHostInfo', function() {
  1774. it('should set data from hostInfo', function() {
  1775. var host = Em.Object.create(),
  1776. hostInfo = {
  1777. Hosts: {
  1778. cpu_count: 2,
  1779. total_mem: 12345,
  1780. os_type: 't1',
  1781. os_arch: 'os1',
  1782. ip: '0.0.0.0',
  1783. disk_info: [
  1784. {mountpoint: '/boot'},
  1785. {mountpoint: '/usr'},
  1786. {mountpoint: '/no-boot'},
  1787. {mountpoint: '/boot'}
  1788. ]
  1789. }
  1790. };
  1791. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1792. expect(host.get('cpu')).to.equal(2);
  1793. expect(host.get('os_type')).to.equal('t1');
  1794. expect(host.get('os_arch')).to.equal('os1');
  1795. expect(host.get('ip')).to.equal('0.0.0.0');
  1796. expect(host.get('memory')).to.equal('12345.00');
  1797. expect(host.get('disk_info.length')).to.equal(2);
  1798. });
  1799. });
  1800. describe('#getJDKName', function() {
  1801. beforeEach(function() {
  1802. sinon.stub($, 'ajax', Em.K);
  1803. sinon.stub(App, 'get', function(k) {
  1804. if ('testMode' === k) return false;
  1805. return Em.get(App, k);
  1806. });
  1807. });
  1808. afterEach(function() {
  1809. $.ajax.restore();
  1810. App.get.restore();
  1811. });
  1812. it('should do proper request to ambari-server', function() {
  1813. c.getJDKName();
  1814. expect($.ajax.args[0][0].type).to.contain('GET');
  1815. 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');
  1816. });
  1817. });
  1818. describe('#getJDKNameSuccessCallback', function() {
  1819. it('should set proper data to controller properties', function() {
  1820. var expected = {
  1821. name: 'name',
  1822. home: 'home',
  1823. location: 'location'
  1824. },
  1825. data = {
  1826. RootServiceComponents: {
  1827. properties: {
  1828. 'jdk.name': expected.name,
  1829. 'java.home': expected.home,
  1830. 'jdk_location': expected.location
  1831. }
  1832. }
  1833. };
  1834. c.getJDKNameSuccessCallback(data);
  1835. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  1836. expect(c.get('jdkLocation')).to.equal(expected.location);
  1837. expect(c.get('javaHome')).to.equal(expected.home);
  1838. });
  1839. });
  1840. describe('#doCheckJDK', function() {
  1841. beforeEach(function() {
  1842. sinon.stub($, 'ajax', Em.K);
  1843. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  1844. sinon.stub(App, 'get', function(k) {
  1845. if ('testMode' === k) return false;
  1846. return Em.get(App, k);
  1847. });
  1848. });
  1849. afterEach(function() {
  1850. $.ajax.restore();
  1851. c.setRegistrationInProgressOnce.restore();
  1852. App.get.restore();
  1853. });
  1854. it('should do proper request to the ambari-server', function() {
  1855. var bootHosts = [{name: 'n1', bootStatus: 'REGISTERED'}, {name: 'n2', bootStatus: 'REGISTERED'}],
  1856. javaHome = '/java',
  1857. jdkLocation = '/jdk';
  1858. c.reopen({
  1859. bootHosts: bootHosts,
  1860. javaHome: javaHome,
  1861. jdkLocation: jdkLocation
  1862. });
  1863. c.doCheckJDK();
  1864. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  1865. expect(request.type).to.equal('POST');
  1866. expect(request.url).to.contain('/requests');
  1867. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  1868. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  1869. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  1870. });
  1871. });
  1872. describe('#doCheckJDKsuccessCallback', function() {
  1873. beforeEach(function() {
  1874. sinon.stub($, 'ajax', Em.K);
  1875. sinon.stub(App, 'get', function(k) {
  1876. if ('testMode' === k) return false;
  1877. return Em.get(App, k);
  1878. });
  1879. });
  1880. afterEach(function() {
  1881. $.ajax.restore();
  1882. App.get.restore();
  1883. });
  1884. it('should set jdkRequestIndex if data provided', function() {
  1885. var data = {
  1886. href: '/a/b/c'
  1887. },
  1888. expected = 'c';
  1889. c.set('jdkRequestIndex', null);
  1890. c.doCheckJDKsuccessCallback(data);
  1891. expect(c.get('jdkRequestIndex')).to.equal(expected);
  1892. });
  1893. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function() {
  1894. var data = null,
  1895. expected = true;
  1896. c.set('isJDKWarningsLoaded', false);
  1897. c.set('jdkCategoryWarnings', {});
  1898. c.doCheckJDKsuccessCallback(data);
  1899. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  1900. });
  1901. it('should do propert request to ambari-server', function() {
  1902. var data = null,
  1903. jdkRequestIndex = 'jdkRequestIndex',
  1904. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  1905. c.set('jdkRequestIndex', jdkRequestIndex);
  1906. c.set('jdkCategoryWarnings', null);
  1907. c.doCheckJDKsuccessCallback(data);
  1908. expect($.ajax.args[0][0].type).to.equal('GET');
  1909. expect($.ajax.args[0][0].url).to.contain(url);
  1910. });
  1911. });
  1912. describe('#doCheckJDKerrorCallback', function() {
  1913. it('should set isJDKWarningsLoaded to true', function() {
  1914. c.set('isJDKWarningsLoaded', false);
  1915. c.doCheckJDKerrorCallback();
  1916. c.set('isJDKWarningsLoaded', true);
  1917. });
  1918. });
  1919. describe('#parseJDKCheckResults', function() {
  1920. beforeEach(function() {
  1921. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  1922. });
  1923. afterEach(function() {
  1924. c.doCheckJDKsuccessCallback.restore();
  1925. });
  1926. it('should set jdkCategoryWarnings to null if no data', function() {
  1927. var data = {Requests: {}};
  1928. c.set('jdkCategoryWarnings', {});
  1929. c.parseJDKCheckResults(data);
  1930. expect(c.get('jdkCategoryWarnings')).to.be.null;
  1931. });
  1932. it('should parse warnings (1)', function() {
  1933. var data = {
  1934. Requests: {
  1935. end_time: 1
  1936. },
  1937. tasks: []
  1938. };
  1939. c.set('jdkCategoryWarnings', {});
  1940. c.parseJDKCheckResults(data);
  1941. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  1942. });
  1943. it('should parse warnings (2)', function() {
  1944. var data = {
  1945. Requests: {
  1946. end_time: 1
  1947. },
  1948. tasks: [
  1949. {
  1950. Tasks: {
  1951. host_name: 'h1',
  1952. structured_out: {
  1953. java_home_check: {
  1954. exit_code: 1
  1955. }
  1956. }
  1957. }
  1958. },
  1959. {
  1960. Tasks: {
  1961. host_name: 'h2',
  1962. structured_out: {
  1963. java_home_check: {
  1964. exit_code: 0
  1965. }
  1966. }
  1967. }
  1968. }
  1969. ]
  1970. };
  1971. c.set('jdkCategoryWarnings', {});
  1972. c.parseJDKCheckResults(data);
  1973. var result = c.get('jdkCategoryWarnings');
  1974. expect(result.length).to.equal(1);
  1975. expect(result[0].hostsNames).to.eql(['h1']);
  1976. });
  1977. });
  1978. });