step3_test.js 71 KB

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