step3_test.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190
  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 App = require('app');
  19. var c;
  20. require('utils/ajax/ajax');
  21. require('utils/http_client');
  22. require('models/host');
  23. require('controllers/wizard/step3_controller');
  24. var testHelpers = require('test/helpers');
  25. function getController() {
  26. return App.WizardStep3Controller.create({
  27. content: Em.Object.create({installedHosts: Em.A([]), installOptions: {}, controllerName: ''}),
  28. wizardController: App.InstallerController.create(),
  29. setRegistrationInProgressOnce: Em.K,
  30. disablePreviousSteps: Em.K
  31. });
  32. }
  33. describe('App.WizardStep3Controller', function () {
  34. beforeEach(function () {
  35. c = getController();
  36. sinon.stub(App.db, 'getDisplayLength', Em.K);
  37. sinon.stub(App.db, 'getFilterConditions').returns([]);
  38. sinon.stub(App.router, 'send', Em.K);
  39. App.router.nextBtnClickInProgress = false;
  40. });
  41. afterEach(function () {
  42. App.db.getDisplayLength.restore();
  43. App.router.send.restore();
  44. App.db.getFilterConditions.restore();
  45. App.router.nextBtnClickInProgress = false;
  46. });
  47. App.TestAliases.testAsComputedGt(getController(), 'isHostHaveWarnings', 'warnings.length', 0);
  48. App.TestAliases.testAsComputedEqual(getController(), 'isAddHostWizard', 'content.controllerName', 'addHostController');
  49. App.TestAliases.testAsComputedIfThenElse(getController(), 'registrationTimeoutSecs', 'content.installOptions.manualInstall', 15, 120);
  50. App.TestAliases.testAsComputedAnd(getController(), 'isWarningsLoaded', ['isJDKWarningsLoaded', 'isHostsWarningsLoaded']);
  51. describe('#getAllRegisteredHostsCallback', function () {
  52. it('One host is already in the cluster, one host is registered', function () {
  53. c.get('content.installedHosts').pushObject({
  54. name: 'wst3_host1'
  55. });
  56. c.reopen({
  57. bootHosts: [
  58. Em.Object.create({name: 'wst3_host1'}),
  59. Em.Object.create({name: 'wst3_host2'})
  60. ]
  61. });
  62. var testData = {
  63. items: [
  64. {
  65. Hosts: {
  66. host_name: 'wst3_host1'
  67. }
  68. },
  69. {
  70. Hosts: {
  71. host_name: 'wst3_host2'
  72. }
  73. },
  74. {
  75. Hosts: {
  76. host_name: 'wst3_host3'
  77. }
  78. }
  79. ]
  80. };
  81. c.getAllRegisteredHostsCallback(testData);
  82. expect(c.get('hasMoreRegisteredHosts')).to.equal(true);
  83. expect(c.get('registeredHosts').length).to.equal(1);
  84. });
  85. it('All hosts are new', function () {
  86. c.get('content.installedHosts').pushObject({
  87. name: 'wst3_host1'
  88. });
  89. c.reopen({
  90. bootHosts: [
  91. {name: 'wst3_host3'},
  92. {name: 'wst3_host4'}
  93. ]
  94. });
  95. var testData = {
  96. items: [
  97. {
  98. Hosts: {
  99. host_name: 'wst3_host3'
  100. }
  101. },
  102. {
  103. Hosts: {
  104. host_name: 'wst3_host4'
  105. }
  106. }
  107. ]
  108. };
  109. c.getAllRegisteredHostsCallback(testData);
  110. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  111. expect(c.get('registeredHosts')).to.equal('');
  112. });
  113. it('No new hosts', function () {
  114. c.get('content.installedHosts').pushObject({
  115. name: 'wst3_host1'
  116. });
  117. c.reopen({
  118. bootHosts: [
  119. {name: 'wst3_host1'}
  120. ]
  121. });
  122. var testData = {
  123. items: [
  124. {
  125. Hosts: {
  126. host_name: 'wst3_host1'
  127. }
  128. }
  129. ]
  130. };
  131. c.getAllRegisteredHostsCallback(testData);
  132. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  133. expect(c.get('registeredHosts')).to.equal('');
  134. });
  135. });
  136. describe('#isWarningsBoxVisible', function () {
  137. it('for "real" mode should be based on isRegistrationInProgress', function () {
  138. c.set('isRegistrationInProgress', false);
  139. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  140. c.set('isRegistrationInProgress', true);
  141. expect(c.get('isWarningsBoxVisible')).to.equal(false);
  142. });
  143. });
  144. describe('#clearStep', function () {
  145. it('should clear hosts', function () {
  146. c.set('hosts', [
  147. {},
  148. {}
  149. ]);
  150. c.clearStep();
  151. expect(c.get('hosts')).to.eql([]);
  152. });
  153. it('should clear bootHosts', function () {
  154. c.set('bootHosts', [
  155. {},
  156. {}
  157. ]);
  158. c.clearStep();
  159. expect(c.get('bootHosts').length).to.equal(0);
  160. });
  161. it('should set stopBootstrap to false', function () {
  162. c.set('stopBootstrap', true);
  163. c.clearStep();
  164. expect(c.get('stopBootstrap')).to.equal(false);
  165. });
  166. it('should set wizardController DBProperty bootStatus to false', function () {
  167. c.get('wizardController').setDBProperty('bootStatus', true);
  168. c.clearStep();
  169. expect(c.get('wizardController').getDBProperty('bootStatus')).to.equal(false);
  170. });
  171. it('should set isSubmitDisabled to true', function () {
  172. c.set('isSubmitDisabled', false);
  173. c.clearStep();
  174. expect(c.get('isSubmitDisabled')).to.equal(true);
  175. });
  176. });
  177. describe('#loadStep', function () {
  178. beforeEach(function () {
  179. sinon.stub(App.router, 'get').withArgs('clusterController').returns({
  180. loadAmbariProperties: Em.K
  181. });
  182. sinon.spy(c, 'clearStep');
  183. sinon.stub(c, 'loadHosts', Em.K);
  184. sinon.stub(c, 'disablePreviousSteps', Em.K);
  185. });
  186. afterEach(function () {
  187. App.router.get.restore();
  188. c.clearStep.restore();
  189. c.disablePreviousSteps.restore();
  190. c.loadHosts.restore();
  191. });
  192. it('should set registrationStartedAt to null', function () {
  193. c.set('registrationStartedAt', {});
  194. c.loadStep();
  195. expect(c.get('registrationStartedAt')).to.be.null;
  196. });
  197. it('should call clearStep', function () {
  198. c.loadStep();
  199. expect(c.get('clearStep').calledOnce).to.equal(true);
  200. });
  201. it('should call loadHosts', function () {
  202. c.loadStep();
  203. expect(c.get('loadHosts').calledOnce).to.equal(true);
  204. });
  205. it('should call disablePreviousSteps', function () {
  206. c.loadStep();
  207. expect(c.get('disablePreviousSteps').calledOnce).to.equal(true);
  208. });
  209. });
  210. describe('#loadHosts', function () {
  211. beforeEach(function () {
  212. sinon.stub(c, 'navigateStep');
  213. });
  214. afterEach(function () {
  215. c.navigateStep.restore();
  216. });
  217. it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function () {
  218. c.set('content.installOptions', {manualInstall: true});
  219. c.set('content.hosts', {c: {name: 'name'}});
  220. c.loadHosts();
  221. expect(c.get('hosts').everyProperty('bootStatus', 'DONE')).to.equal(true);
  222. });
  223. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function () {
  224. c.set('content', {installOptions: {manualInstall: false}, hosts: {c: {name: 'name'}}});
  225. c.loadHosts();
  226. expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
  227. });
  228. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected (2)', function () {
  229. c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
  230. c.loadHosts();
  231. expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
  232. });
  233. });
  234. describe('#parseHostInfo', function () {
  235. var tests = Em.A([
  236. {
  237. bootHosts: Em.A([
  238. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  239. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  240. Em.Object.create({name: 'c3', bootStatus: 'RUNNING', bootLog: ''})
  241. ]),
  242. hostsStatusFromServer: Em.A([
  243. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  244. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  245. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  246. ]),
  247. m: 'bootHosts not empty, hostsStatusFromServer not empty, one is RUNNING',
  248. e: {
  249. c: true,
  250. r: true
  251. }
  252. },
  253. {
  254. bootHosts: Em.A([]),
  255. hostsStatusFromServer: Em.A([
  256. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  257. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  258. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  259. ]),
  260. m: 'bootHosts is empty',
  261. e: {
  262. c: false,
  263. r: false
  264. }
  265. },
  266. {
  267. bootHosts: Em.A([
  268. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  269. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  270. Em.Object.create({name: 'c3', bootStatus: 'REGISTERED', bootLog: ''})
  271. ]),
  272. hostsStatusFromServer: Em.A([
  273. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  274. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  275. {hostName: 'c3', status: 'REGISTERED', log: 'c3'}
  276. ]),
  277. m: 'bootHosts not empty, hostsStatusFromServer not empty, no one is RUNNING',
  278. e: {
  279. c: true,
  280. r: false
  281. }
  282. }
  283. ]);
  284. tests.forEach(function (test) {
  285. describe(test.m, function () {
  286. var r;
  287. beforeEach(function () {
  288. c.set('bootHosts', test.bootHosts);
  289. r = c.parseHostInfo(test.hostsStatusFromServer);
  290. });
  291. it('parsed hosts info is valid', function () {
  292. expect(r).to.equal(test.e.r);
  293. });
  294. if (test.e.c) {
  295. test.hostsStatusFromServer.forEach(function (h) {
  296. it('bootStatus and bootLog are valid', function () {
  297. var bootHosts = c.get('bootHosts').findProperty('name', h.hostName);
  298. if (!['REGISTERED', 'REGISTERING'].contains(bootHosts.get('bootStatus'))) {
  299. expect(bootHosts.get('bootStatus')).to.equal(h.status);
  300. expect(bootHosts.get('bootLog')).to.equal(h.log);
  301. }
  302. });
  303. });
  304. }
  305. });
  306. });
  307. });
  308. describe('#removeHosts', function () {
  309. beforeEach(function () {
  310. sinon.spy(App, 'showConfirmationPopup');
  311. });
  312. afterEach(function () {
  313. App.showConfirmationPopup.restore();
  314. });
  315. it('should call App.showConfirmationPopup', function () {
  316. c.removeHosts(Em.A([]));
  317. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  318. });
  319. it('primary should disable Submit if no more hosts', function () {
  320. var hosts = [
  321. {}
  322. ];
  323. c.set('hosts', hosts);
  324. c.removeHosts(hosts).onPrimary();
  325. expect(c.get('isSubmitDisabled')).to.equal(true);
  326. });
  327. });
  328. describe('#removeSelectedHosts', function () {
  329. beforeEach(function () {
  330. sinon.stub(c, 'removeHosts', Em.K);
  331. });
  332. afterEach(function () {
  333. c.removeHosts.restore();
  334. });
  335. it('should remove selected hosts', function () {
  336. c.set('hosts', [
  337. {isChecked: true, name: 'c1'},
  338. {isChecked: false, name: 'c2'}
  339. ]);
  340. c.removeSelectedHosts();
  341. expect(c.removeHosts.calledWith([
  342. {isChecked: true, name: 'c1'}
  343. ])).to.be.true;
  344. });
  345. });
  346. describe('#selectedHostsPopup', function () {
  347. beforeEach(function () {
  348. sinon.spy(App.ModalPopup, 'show');
  349. });
  350. afterEach(function () {
  351. App.ModalPopup.show.restore();
  352. });
  353. it('should show App.ModalPopup', function () {
  354. c.selectedHostsPopup();
  355. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  356. });
  357. });
  358. describe('#retryHosts', function () {
  359. var s;
  360. var agentUserCases = [
  361. {
  362. customizeAgentUserAccount: true,
  363. userRunAs: 'user',
  364. title: 'Ambari Agent user account customize enabled'
  365. },
  366. {
  367. customizeAgentUserAccount: false,
  368. userRunAs: 'root',
  369. title: 'Ambari Agent user account customize disabled'
  370. }
  371. ];
  372. var installer = {launchBootstrap: Em.K};
  373. beforeEach(function () {
  374. sinon.spy(installer, "launchBootstrap");
  375. s = sinon.stub(App.router, 'get', function () {
  376. return installer;
  377. });
  378. sinon.stub(c, 'doBootstrap', Em.K);
  379. sinon.spy(c, 'startRegistration');
  380. });
  381. afterEach(function () {
  382. c.doBootstrap.restore();
  383. s.restore();
  384. installer.launchBootstrap.restore();
  385. c.startRegistration.restore();
  386. });
  387. it('should set numPolls to 0', function () {
  388. c.set('content', {installOptions: {}});
  389. c.set('numPolls', 123);
  390. c.retryHosts(Em.A([]));
  391. expect(c.get('numPolls')).to.equal(0);
  392. });
  393. it('should set registrationStartedAt to null', function () {
  394. c.set('content', {installOptions: {}});
  395. c.retryHosts(Em.A([]));
  396. expect(c.get('registrationStartedAt')).to.be.null;
  397. });
  398. it('should startRegistration if installOptions.manualInstall is true', function () {
  399. c.set('content', {installOptions: {manualInstall: true}});
  400. c.retryHosts(Em.A([]));
  401. expect(c.startRegistration.calledOnce).to.equal(true);
  402. });
  403. it('should launchBootstrap if installOptions.manualInstall is false', function () {
  404. c.set('content', {installOptions: {manualInstall: false}});
  405. c.retryHosts(Em.A([]));
  406. expect(installer.launchBootstrap.calledOnce).to.be.true;
  407. });
  408. agentUserCases.forEach(function (item) {
  409. describe(item.title, function () {
  410. var controller;
  411. beforeEach(function () {
  412. controller = App.WizardStep3Controller.create({
  413. content: {
  414. installOptions: {
  415. sshKey: 'key',
  416. sshUser: 'root',
  417. sshPort: '123',
  418. agentUser: 'user'
  419. },
  420. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } }
  421. }
  422. });
  423. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  424. controller.setupBootStrap();
  425. });
  426. afterEach(function () {
  427. App.get.restore();
  428. });
  429. it('launchBootstrap is called with correct arguments', function () {
  430. expect(installer.launchBootstrap.firstCall.args[0]).to.equal(JSON.stringify({
  431. verbose: true,
  432. sshKey: 'key',
  433. hosts: ['host0', 'host1'],
  434. user: 'root',
  435. sshPort: '123',
  436. userRunAs: item.userRunAs
  437. }));
  438. });
  439. });
  440. });
  441. });
  442. describe('#retryHost', function () {
  443. beforeEach(function () {
  444. sinon.spy(c, 'retryHosts');
  445. sinon.stub(App.router, 'get', function () {
  446. return {launchBootstrap: Em.K}
  447. });
  448. sinon.stub(c, 'doBootstrap', Em.K);
  449. });
  450. afterEach(function () {
  451. c.retryHosts.restore();
  452. App.router.get.restore();
  453. c.doBootstrap.restore();
  454. });
  455. it('should callretryHosts with array as arg', function () {
  456. var host = {n: 'c'};
  457. c.set('content', {installOptions: {}});
  458. c.retryHost(host);
  459. expect(c.retryHosts.calledWith([host])).to.equal(true);
  460. });
  461. });
  462. describe('#retrySelectedHosts', function () {
  463. beforeEach(function () {
  464. sinon.spy(c, 'retryHosts');
  465. sinon.stub(App.router, 'get', function () {
  466. return {launchBootstrap: Em.K}
  467. });
  468. sinon.stub(c, 'doBootstrap', Em.K);
  469. });
  470. afterEach(function () {
  471. c.retryHosts.restore();
  472. App.router.get.restore();
  473. c.doBootstrap.restore();
  474. });
  475. it('shouldn\'t do nothing if isRetryDisabled is true', function () {
  476. c.set('isRetryDisabled', true);
  477. c.retrySelectedHosts();
  478. expect(c.retryHosts.called).to.be.false;
  479. });
  480. it('should retry hosts with FAILED bootStatus', function () {
  481. c.set('bootHosts', Em.A([
  482. Em.Object.create({
  483. name: 'c1',
  484. bootStatus: 'FAILED'
  485. }),
  486. Em.Object.create({
  487. name: 'c2',
  488. bootStatus: 'REGISTERED'
  489. })
  490. ]));
  491. c.reopen({isRetryDisabled: false});
  492. c.retrySelectedHosts();
  493. expect(c.retryHosts.calledWith([
  494. Em.Object.create({name: 'c1', bootStatus: 'DONE', bootLog: 'Retrying ...'})
  495. ])).to.be.true;
  496. });
  497. });
  498. describe('#startBootstrap', function () {
  499. beforeEach(function () {
  500. sinon.stub(c, 'doBootstrap', Em.K);
  501. });
  502. afterEach(function () {
  503. c.doBootstrap.restore();
  504. });
  505. it('should drop numPolls and registrationStartedAt', function () {
  506. c.set('numPolls', 123);
  507. c.set('registrationStartedAt', 1234);
  508. c.startBootstrap();
  509. expect(c.get('numPolls')).to.equal(0);
  510. expect(c.get('registrationStartedAt')).to.be.null;
  511. });
  512. it('should drop numPolls and registrationStartedAt (2)', function () {
  513. c.set('hosts', Em.A([
  514. {name: 'c1'},
  515. {name: 'c2'}
  516. ]));
  517. c.startBootstrap();
  518. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1', 'c2']);
  519. });
  520. });
  521. describe('#setRegistrationInProgress', function () {
  522. var tests = Em.A([
  523. {
  524. bootHosts: [],
  525. isLoaded: false,
  526. e: true,
  527. m: 'no bootHosts and isLoaded is false'
  528. },
  529. {
  530. bootHosts: [],
  531. isLoaded: true,
  532. e: false,
  533. m: 'no bootHosts and isLoaded is true'
  534. },
  535. {
  536. bootHosts: [
  537. Em.Object.create({bootStatus: 'RUNNING'}),
  538. Em.Object.create({bootStatus: 'RUNNING'})
  539. ],
  540. isLoaded: true,
  541. e: true,
  542. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  543. },
  544. {
  545. bootHosts: [
  546. Em.Object.create({bootStatus: 'RUNNING'}),
  547. Em.Object.create({bootStatus: 'RUNNING'})
  548. ],
  549. isLoaded: false,
  550. e: true,
  551. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  552. },
  553. {
  554. bootHosts: [
  555. Em.Object.create({bootStatus: 'REGISTERED'}),
  556. Em.Object.create({bootStatus: 'RUNNING'})
  557. ],
  558. isLoaded: false,
  559. e: true,
  560. m: 'bootHosts with one REGISTERED and isLoaded is false'
  561. },
  562. {
  563. bootHosts: [
  564. Em.Object.create({bootStatus: 'FAILED'}),
  565. Em.Object.create({bootStatus: 'RUNNING'})
  566. ],
  567. isLoaded: false,
  568. e: true,
  569. m: 'bootHosts with one FAILED and isLoaded is false'
  570. },
  571. {
  572. bootHosts: [
  573. Em.Object.create({bootStatus: 'REGISTERED'}),
  574. Em.Object.create({bootStatus: 'RUNNING'})
  575. ],
  576. isLoaded: true,
  577. e: true,
  578. m: 'bootHosts with one REGISTERED and isLoaded is true'
  579. },
  580. {
  581. bootHosts: [
  582. Em.Object.create({bootStatus: 'FAILED'}),
  583. Em.Object.create({bootStatus: 'RUNNING'})
  584. ],
  585. isLoaded: true,
  586. e: true,
  587. m: 'bootHosts with one FAILED and isLoaded is true'
  588. }
  589. ]);
  590. beforeEach(function () {
  591. sinon.stub(c, 'getAllRegisteredHosts', Em.K);
  592. sinon.stub(c, 'disablePreviousSteps', Em.K);
  593. sinon.stub(c, 'navigateStep', Em.K);
  594. });
  595. afterEach(function () {
  596. c.disablePreviousSteps.restore();
  597. c.getAllRegisteredHosts.restore();
  598. c.navigateStep.restore();
  599. });
  600. tests.forEach(function (test) {
  601. it(test.m, function () {
  602. c.set('bootHosts', test.bootHosts);
  603. c.set('isLoaded', test.isLoaded);
  604. c.setRegistrationInProgress();
  605. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  606. });
  607. });
  608. });
  609. describe('#doBootstrap()', function () {
  610. it('shouldn\'t do nothing if stopBootstrap is true', function () {
  611. c.set('stopBootstrap', true);
  612. c.doBootstrap();
  613. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.bootstrap');
  614. expect(args).not.exists;
  615. });
  616. it('should increment numPolls if stopBootstrap is false', function () {
  617. c.set('numPolls', 0);
  618. c.set('stopBootstrap', false);
  619. c.doBootstrap();
  620. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.bootstrap');
  621. expect(args).exists;
  622. expect(c.get('numPolls')).to.equal(1);
  623. });
  624. });
  625. describe('#startRegistration', function () {
  626. beforeEach(function () {
  627. sinon.spy(c, 'isHostsRegistered');
  628. });
  629. afterEach(function () {
  630. c.isHostsRegistered.restore();
  631. });
  632. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function () {
  633. c.set('registrationStartedAt', 1234);
  634. c.startRegistration();
  635. expect(c.isHostsRegistered.called).to.equal(false);
  636. expect(c.get('registrationStartedAt')).to.equal(1234);
  637. });
  638. it('shouldn\'t do nothing if registrationStartedAt isn\'t null (2)', function () {
  639. c.set('registrationStartedAt', null);
  640. c.startRegistration();
  641. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  642. });
  643. });
  644. describe('#isHostsRegistered', function () {
  645. it('shouldn\'t do nothing if stopBootstrap is true', function () {
  646. c.set('stopBootstrap', true);
  647. c.isHostsRegistered();
  648. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
  649. expect(args).not.exists;
  650. });
  651. it('should do ajax call if stopBootstrap is false', function () {
  652. c.set('stopBootstrap', false);
  653. c.isHostsRegistered();
  654. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
  655. expect(args).exists;
  656. });
  657. });
  658. describe('#isHostsRegisteredSuccessCallback', function () {
  659. var tests = Em.A([
  660. {
  661. bootHosts: Em.A([
  662. Em.Object.create({bootStatus: 'DONE'})
  663. ]),
  664. data: {items: []},
  665. registrationStartedAt: 1000000,
  666. m: 'one host DONE',
  667. e: {
  668. bs: 'REGISTERING',
  669. getHostInfoCalled: false
  670. }
  671. },
  672. {
  673. bootHosts: Em.A([
  674. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  675. ]),
  676. data: {items: [
  677. {Hosts: {host_name: 'c1'}}
  678. ]},
  679. m: ' one host REGISTERING',
  680. e: {
  681. bs: 'REGISTERED',
  682. getHostInfoCalled: false
  683. }
  684. },
  685. {
  686. bootHosts: Em.A([
  687. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  688. ]),
  689. data: {items: [
  690. {Hosts: {host_name: 'c2'}}
  691. ]},
  692. registrationStartedAt: 0,
  693. m: 'one host REGISTERING but data missing info about it, timeout',
  694. e: {
  695. bs: 'FAILED',
  696. getHostInfoCalled: false
  697. }
  698. },
  699. {
  700. bootHosts: Em.A([
  701. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  702. ]),
  703. data: {items: [
  704. {Hosts: {host_name: 'c2'}}
  705. ]},
  706. registrationStartedAt: 1000000,
  707. m: 'one host REGISTERING but data missing info about it',
  708. e: {
  709. bs: 'REGISTERING',
  710. getHostInfoCalled: false
  711. }
  712. },
  713. {
  714. bootHosts: Em.A([
  715. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  716. ]),
  717. data: {items: [
  718. {Hosts: {host_name: 'c1'}}
  719. ]},
  720. m: ' one host RUNNING',
  721. e: {
  722. bs: 'RUNNING',
  723. getHostInfoCalled: false
  724. }
  725. }
  726. ]);
  727. beforeEach(function () {
  728. sinon.spy(c, 'getHostInfo');
  729. sinon.stub(App, 'dateTime').returns(1000000);
  730. });
  731. afterEach(function () {
  732. c.getHostInfo.restore();
  733. App.dateTime.restore();
  734. });
  735. tests.forEach(function (test) {
  736. it(test.m, function () {
  737. c.set('content.installedHosts', []);
  738. c.set('bootHosts', test.bootHosts);
  739. c.set('registrationStartedAt', test.registrationStartedAt);
  740. c.isHostsRegisteredSuccessCallback(test.data);
  741. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  742. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  743. });
  744. });
  745. });
  746. describe('#getAllRegisteredHosts', function () {
  747. it('should call App.ajax.send', function () {
  748. c.getAllRegisteredHosts();
  749. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
  750. expect(args).exists;
  751. });
  752. });
  753. describe('#getAllRegisteredHostsCallback', function () {
  754. var tests = Em.A([
  755. {
  756. hostsInCluster: ['c3'],
  757. bootHosts: [
  758. {name: 'c1'},
  759. {name: 'c2'}
  760. ],
  761. hosts: Em.A([
  762. {Hosts: {host_name: 'c1'}},
  763. {Hosts: {host_name: 'c2'}}
  764. ]),
  765. m: 'No registered hosts',
  766. e: {
  767. hasMoreRegisteredHosts: false,
  768. registeredHosts: ''
  769. }
  770. },
  771. {
  772. hostsInCluster: ['c4'],
  773. bootHosts: [
  774. {name: 'c3'},
  775. {name: 'c5'}
  776. ],
  777. hosts: Em.A([
  778. {Hosts: {host_name: 'c1'}},
  779. {Hosts: {host_name: 'c2'}}
  780. ]),
  781. m: '2 registered hosts',
  782. e: {
  783. hasMoreRegisteredHosts: true,
  784. registeredHosts: ['c1', 'c2']
  785. }
  786. },
  787. {
  788. hostsInCluster: ['c4'],
  789. bootHosts: [
  790. {name: 'c1'},
  791. {name: 'c5'}
  792. ],
  793. hosts: Em.A([
  794. {Hosts: {host_name: 'c1'}},
  795. {Hosts: {host_name: 'c2'}}
  796. ]),
  797. m: '1 registered host',
  798. e: {
  799. hasMoreRegisteredHosts: true,
  800. registeredHosts: ['c2']
  801. }
  802. },
  803. {
  804. hostsInCluster: ['c1'],
  805. bootHosts: [
  806. {name: 'c3'},
  807. {name: 'c5'}
  808. ],
  809. hosts: Em.A([
  810. {Hosts: {host_name: 'c1'}},
  811. {Hosts: {host_name: 'c2'}}
  812. ]),
  813. m: '1 registered host (2)',
  814. e: {
  815. hasMoreRegisteredHosts: true,
  816. registeredHosts: ['c2']
  817. }
  818. }
  819. ]);
  820. tests.forEach(function (test) {
  821. it(test.m, function () {
  822. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  823. c.set('bootHosts', test.bootHosts);
  824. c.getAllRegisteredHostsCallback({items: test.hosts});
  825. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  826. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  827. });
  828. });
  829. });
  830. describe('#registerErrPopup', function () {
  831. beforeEach(function () {
  832. sinon.spy(App.ModalPopup, 'show');
  833. });
  834. afterEach(function () {
  835. App.ModalPopup.show.restore();
  836. });
  837. it('should call App.ModalPopup.show', function () {
  838. c.registerErrPopup();
  839. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  840. });
  841. });
  842. describe('#getHostInfo', function () {
  843. it('should do ajax request', function () {
  844. c.getHostInfo();
  845. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.host_info');
  846. expect(args).exists;
  847. });
  848. });
  849. describe('#getHostInfoErrorCallback', function () {
  850. beforeEach(function () {
  851. sinon.spy(c, 'registerErrPopup');
  852. });
  853. afterEach(function () {
  854. c.registerErrPopup.restore();
  855. });
  856. it('should call registerErrPopup', function () {
  857. c.getHostInfoErrorCallback();
  858. expect(c.registerErrPopup.calledOnce).to.equal(true);
  859. });
  860. });
  861. describe('#stopRegistration', function () {
  862. var tests = Em.A([
  863. {
  864. bootHosts: [
  865. Em.Object.create({bootStatus: 'REGISTERED'}),
  866. Em.Object.create({bootStatus: 'RUNNING'})
  867. ],
  868. e: {isSubmitDisabled: false}
  869. },
  870. {
  871. bootHosts: [
  872. Em.Object.create({bootStatus: 'FAILED'}),
  873. Em.Object.create({bootStatus: 'RUNNING'})
  874. ],
  875. e: {isSubmitDisabled: true}
  876. },
  877. {
  878. bootHosts: [
  879. Em.Object.create({bootStatus: 'FAILED'}),
  880. Em.Object.create({bootStatus: 'REGISTERED'})
  881. ],
  882. e: {isSubmitDisabled: false}
  883. },
  884. {
  885. bootHosts: [
  886. Em.Object.create({bootStatus: 'RUNNING'}),
  887. Em.Object.create({bootStatus: 'RUNNING'})
  888. ],
  889. e: {isSubmitDisabled: true}
  890. }
  891. ]);
  892. tests.forEach(function (test) {
  893. it(test.bootHosts.mapProperty('bootStatus').join(', '), function () {
  894. c.reopen({bootHosts: test.bootHosts});
  895. c.stopRegistration();
  896. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  897. });
  898. });
  899. });
  900. describe('#submit', function () {
  901. beforeEach(function () {
  902. sinon.spy(App.ModalPopup, 'show');
  903. });
  904. afterEach(function () {
  905. App.ModalPopup.show.restore();
  906. });
  907. it('if isHostHaveWarnings should show confirmation popup', function () {
  908. c.reopen({isHostHaveWarnings: true});
  909. c.submit();
  910. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  911. });
  912. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function () {
  913. var bootHosts = [
  914. Em.Object.create({name: 'c1'})
  915. ];
  916. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  917. c.submit().onPrimary();
  918. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  919. });
  920. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function () {
  921. var bootHosts = [
  922. Em.Object.create({name: 'c1'})
  923. ];
  924. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  925. c.submit();
  926. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  927. });
  928. it('if Next button is clicked multiple times before the next step renders, it must not be processed',function(){
  929. var bootHosts = [
  930. Em.Object.create({name: 'c1'})
  931. ];
  932. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  933. c.submit();
  934. expect(App.router.send.calledWith('next')).to.equal(true);
  935. App.router.send.reset();
  936. c.submit();
  937. expect(App.router.send.calledWith('next')).to.equal(false);
  938. });
  939. });
  940. describe('#hostLogPopup', function () {
  941. beforeEach(function () {
  942. sinon.spy(App.ModalPopup, 'show');
  943. });
  944. afterEach(function () {
  945. App.ModalPopup.show.restore();
  946. });
  947. it('should show App.ModalPopup', function () {
  948. c.hostLogPopup({context: Em.Object.create({})});
  949. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  950. });
  951. });
  952. describe('#rerunChecksSuccessCallback', function () {
  953. beforeEach(function () {
  954. sinon.stub(c, 'parseWarnings', Em.K);
  955. });
  956. afterEach(function () {
  957. c.parseWarnings.restore();
  958. });
  959. it('should set checksUpdateProgress to 100', function () {
  960. c.set('checksUpdateProgress', 0);
  961. c.rerunChecksSuccessCallback({items: []});
  962. expect(c.get('checksUpdateProgress')).to.equal(100);
  963. });
  964. it('should set checksUpdateStatus to SUCCESS', function () {
  965. c.set('checksUpdateStatus', '');
  966. c.rerunChecksSuccessCallback({items: []});
  967. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  968. });
  969. it('should call parseWarnings', function () {
  970. c.rerunChecksSuccessCallback({items: []});
  971. expect(c.parseWarnings.calledOnce).to.equal(true);
  972. });
  973. });
  974. describe('#rerunChecksErrorCallback', function () {
  975. it('should set checksUpdateProgress to 100', function () {
  976. c.set('checksUpdateProgress', 0);
  977. c.rerunChecksErrorCallback({});
  978. expect(c.get('checksUpdateProgress')).to.equal(100);
  979. });
  980. it('should set checksUpdateStatus to FAILED', function () {
  981. c.set('checksUpdateStatus', '');
  982. c.rerunChecksErrorCallback({});
  983. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  984. });
  985. });
  986. describe('#filterBootHosts', function () {
  987. var tests = Em.A([
  988. {
  989. bootHosts: [
  990. Em.Object.create({name: 'c1'}),
  991. Em.Object.create({name: 'c2'})
  992. ],
  993. data: {
  994. items: [
  995. {Hosts: {host_name: 'c1'}}
  996. ]
  997. },
  998. m: 'one host',
  999. e: ['c1']
  1000. },
  1001. {
  1002. bootHosts: [
  1003. Em.Object.create({name: 'c1'}),
  1004. Em.Object.create({name: 'c2'})
  1005. ],
  1006. data: {
  1007. items: [
  1008. {Hosts: {host_name: 'c3'}}
  1009. ]
  1010. },
  1011. m: 'no hosts',
  1012. e: []
  1013. },
  1014. {
  1015. bootHosts: [
  1016. Em.Object.create({name: 'c1'}),
  1017. Em.Object.create({name: 'c2'})
  1018. ],
  1019. data: {
  1020. items: [
  1021. {Hosts: {host_name: 'c1'}},
  1022. {Hosts: {host_name: 'c2'}}
  1023. ]
  1024. },
  1025. m: 'many hosts',
  1026. e: ['c1', 'c2']
  1027. }
  1028. ]);
  1029. tests.forEach(function (test) {
  1030. it(test.m, function () {
  1031. c.reopen({bootHosts: test.bootHosts});
  1032. var filteredData = c.filterBootHosts(test.data);
  1033. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1034. });
  1035. });
  1036. });
  1037. describe('#hostWarningsPopup', function () {
  1038. beforeEach(function () {
  1039. sinon.spy(App.ModalPopup, 'show');
  1040. sinon.stub(c, 'rerunChecks', Em.K);
  1041. });
  1042. afterEach(function () {
  1043. App.ModalPopup.show.restore();
  1044. c.rerunChecks.restore();
  1045. });
  1046. it('should show App.ModalPopup', function () {
  1047. c.hostWarningsPopup();
  1048. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1049. });
  1050. it('should clear checksUpdateStatus on primary', function () {
  1051. c.set('checksUpdateStatus', 'not null value');
  1052. c.hostWarningsPopup().onPrimary();
  1053. expect(c.get('checksUpdateStatus')).to.be.null;
  1054. });
  1055. it('should clear checksUpdateStatus on close', function () {
  1056. c.set('checksUpdateStatus', 'not null value');
  1057. c.hostWarningsPopup().onClose();
  1058. expect(c.get('checksUpdateStatus')).to.be.null;
  1059. });
  1060. it('should rerunChecks onSecondary', function () {
  1061. c.hostWarningsPopup().onSecondary();
  1062. expect(c.rerunChecks.calledOnce).to.equal(true);
  1063. });
  1064. });
  1065. describe('#registeredHostsPopup', function () {
  1066. beforeEach(function () {
  1067. sinon.spy(App.ModalPopup, 'show');
  1068. });
  1069. afterEach(function () {
  1070. App.ModalPopup.show.restore();
  1071. });
  1072. it('should show App.ModalPopup', function () {
  1073. c.registeredHostsPopup();
  1074. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1075. });
  1076. });
  1077. describe('#parseHostCheckWarnings', function () {
  1078. beforeEach(function () {
  1079. sinon.stub(c, 'filterHostsData', function (k) {
  1080. return k;
  1081. });
  1082. });
  1083. afterEach(function () {
  1084. c.filterHostsData.restore();
  1085. });
  1086. it('no warnings if last_agent_env isn\'t specified', function () {
  1087. c.set('warnings', [
  1088. {}
  1089. ]);
  1090. c.set('warningsByHost', [
  1091. {},
  1092. {}
  1093. ]);
  1094. c.parseHostCheckWarnings({tasks: [
  1095. {Tasks: {host_name: 'c1'}}
  1096. ]});
  1097. expect(c.get('warnings')).to.eql([]);
  1098. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1099. });
  1100. Em.A([
  1101. {
  1102. m: 'parse stackFoldersAndFiles',
  1103. tests: Em.A([
  1104. {
  1105. tasks: [
  1106. {Tasks: {host_name: 'c1',
  1107. structured_out:{last_agent_env_check: {stackFoldersAndFiles: []}}
  1108. }
  1109. }
  1110. ],
  1111. m: 'empty stackFoldersAndFiles',
  1112. e: {
  1113. warnings: [],
  1114. warningsByHost: [0]
  1115. }
  1116. },
  1117. {
  1118. tasks: [
  1119. {Tasks: {host_name: 'c1',
  1120. structured_out: {last_agent_env_check: {stackFoldersAndFiles: [{name: 'n1'}]}}
  1121. }
  1122. }
  1123. ],
  1124. m: 'not empty stackFoldersAndFiles',
  1125. e: {
  1126. warnings: [
  1127. {
  1128. name: 'n1',
  1129. hosts: ['c1'],
  1130. onSingleHost: true,
  1131. category: 'fileFolders'
  1132. }
  1133. ],
  1134. warningsByHost: [1]
  1135. }
  1136. },
  1137. {
  1138. tasks: [
  1139. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {stackFoldersAndFiles: [
  1140. {name: 'n1'}
  1141. ]}}}},
  1142. {Tasks: {host_name: 'c2', structured_out: {last_agent_env_check: {stackFoldersAndFiles: [
  1143. {name: 'n1'}
  1144. ]}}}}
  1145. ],
  1146. m: 'not empty stackFoldersAndFiles on two hosts',
  1147. e: {
  1148. warnings: [
  1149. {
  1150. name: 'n1',
  1151. hosts: ['c1', 'c2'],
  1152. onSingleHost: false,
  1153. category: 'fileFolders'
  1154. }
  1155. ],
  1156. warningsByHost: [1]
  1157. }
  1158. }
  1159. ])
  1160. },
  1161. {
  1162. m: 'parse hostHealth.liveServices',
  1163. tests: Em.A([
  1164. {
  1165. tasks: [
  1166. {Tasks: {host_name: 'c1', structured_out: {last_agent_env_check: {hostHealth: []}}}}
  1167. ],
  1168. m: 'empty hostHealth',
  1169. e: {
  1170. warnings: [],
  1171. warningsByHost: [0]
  1172. }
  1173. },
  1174. {
  1175. tasks: [
  1176. {Tasks: {host_name: 'c1', structured_out: {last_agent_env_check: {hostHealth: {liveServices: []}}}}}
  1177. ],
  1178. m: 'empty liveServices',
  1179. e: {
  1180. warnings: [],
  1181. warningsByHost: [0]
  1182. }
  1183. },
  1184. {
  1185. tasks: [
  1186. {Tasks: {host_name: 'c1',
  1187. structured_out: {last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1188. }
  1189. }
  1190. ],
  1191. m: 'not empty hostHealth.liveServices',
  1192. e: {
  1193. warnings: [
  1194. {
  1195. name: 'n1',
  1196. hosts: ['c1'],
  1197. onSingleHost: true,
  1198. category: 'services'
  1199. }
  1200. ],
  1201. warningsByHost: [1]
  1202. }
  1203. },
  1204. {
  1205. tasks: [
  1206. {Tasks: {host_name: 'c1',
  1207. structured_out:{last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1208. }
  1209. },
  1210. {Tasks: {host_name: 'c2',
  1211. structured_out:{last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1212. }
  1213. }
  1214. ],
  1215. m: 'not empty hostHealth.liveServices on two hosts',
  1216. e: {
  1217. warnings: [
  1218. {
  1219. name: 'n1',
  1220. hosts: ['c1', 'c2'],
  1221. onSingleHost: false,
  1222. category: 'services'
  1223. }
  1224. ],
  1225. warningsByHost: [1, 1]
  1226. }
  1227. }
  1228. ])
  1229. },
  1230. {
  1231. m: 'parse existingUsers',
  1232. tests: Em.A([
  1233. {
  1234. tasks: [
  1235. {Tasks: {host_name: 'c1',
  1236. structured_out: {last_agent_env_check: {existingUsers: []}}
  1237. }
  1238. }
  1239. ],
  1240. m: 'empty existingUsers',
  1241. e: {
  1242. warnings: [],
  1243. warningsByHost: [0]
  1244. }
  1245. },
  1246. {
  1247. tasks: [
  1248. {Tasks: {host_name: 'c1',
  1249. structured_out: {last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1250. }
  1251. }
  1252. ],
  1253. m: 'not empty existingUsers',
  1254. e: {
  1255. warnings: [
  1256. {
  1257. name: 'n1',
  1258. hosts: ['c1'],
  1259. onSingleHost: true,
  1260. category: 'users'
  1261. }
  1262. ],
  1263. warningsByHost: [1]
  1264. }
  1265. },
  1266. {
  1267. tasks: [
  1268. {Tasks: {host_name: 'c1',
  1269. structured_out:{last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1270. }
  1271. },
  1272. {Tasks: {host_name: 'c2',
  1273. structured_out:{last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1274. }
  1275. }
  1276. ],
  1277. m: 'not empty existingUsers on two hosts',
  1278. e: {
  1279. warnings: [
  1280. {
  1281. name: 'n1',
  1282. hosts: ['c1', 'c2'],
  1283. onSingleHost: false,
  1284. category: 'users'
  1285. }
  1286. ],
  1287. warningsByHost: [1, 1]
  1288. }
  1289. }
  1290. ])
  1291. },
  1292. {
  1293. m: 'parse alternatives',
  1294. tests: Em.A([
  1295. {
  1296. tasks: [
  1297. {Tasks: {host_name: 'c1',
  1298. structured_out:{last_agent_env_check: {alternatives: []}}
  1299. }
  1300. }
  1301. ],
  1302. m: 'empty alternatives',
  1303. e: {
  1304. warnings: [],
  1305. warningsByHost: [0]
  1306. }
  1307. },
  1308. {
  1309. tasks: [
  1310. {Tasks: {host_name: 'c1',
  1311. structured_out: {last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1312. }
  1313. }
  1314. ],
  1315. m: 'not empty alternatives',
  1316. e: {
  1317. warnings: [
  1318. {
  1319. name: 'n1',
  1320. hosts: ['c1'],
  1321. onSingleHost: true,
  1322. category: 'alternatives'
  1323. }
  1324. ],
  1325. warningsByHost: [1]
  1326. }
  1327. },
  1328. {
  1329. tasks: [
  1330. {Tasks: {host_name: 'c1',
  1331. structured_out:{last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1332. }
  1333. },
  1334. {Tasks: {host_name: 'c2',
  1335. structured_out:{last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1336. }
  1337. }
  1338. ],
  1339. m: 'not empty alternatives on two hosts',
  1340. e: {
  1341. warnings: [
  1342. {
  1343. name: 'n1',
  1344. hosts: ['c1', 'c2'],
  1345. onSingleHost: false,
  1346. category: 'alternatives'
  1347. }
  1348. ],
  1349. warningsByHost: [1, 1]
  1350. }
  1351. }
  1352. ])
  1353. },
  1354. {
  1355. m: 'parse hostHealth.activeJavaProcs',
  1356. tests: Em.A([
  1357. {
  1358. tasks: [
  1359. {Tasks: {host_name: 'c1',
  1360. structured_out:{last_agent_env_check: {hostHealth: [], javaProcs: []}}
  1361. }
  1362. }
  1363. ],
  1364. m: 'empty hostHealth',
  1365. e: {
  1366. warnings: [],
  1367. warningsByHost: [0]
  1368. }
  1369. },
  1370. {
  1371. tasks: [
  1372. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: []}}}}}
  1373. ],
  1374. m: 'empty activeJavaProcs',
  1375. e: {
  1376. warnings: [],
  1377. warningsByHost: [0]
  1378. }
  1379. },
  1380. {
  1381. tasks: [
  1382. {Tasks: {host_name: 'c1',
  1383. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1384. }
  1385. }
  1386. ],
  1387. m: 'not empty hostHealth.activeJavaProcs',
  1388. e: {
  1389. warnings: [
  1390. {
  1391. pid: 'n1',
  1392. hosts: ['c1'],
  1393. onSingleHost: true,
  1394. category: 'processes'
  1395. }
  1396. ],
  1397. warningsByHost: [1]
  1398. }
  1399. },
  1400. {
  1401. tasks: [
  1402. {Tasks: {host_name: 'c1',
  1403. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1404. }
  1405. },
  1406. {Tasks: {host_name: 'c2',
  1407. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1408. }
  1409. }
  1410. ],
  1411. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1412. e: {
  1413. warnings: [
  1414. {
  1415. pid: 'n1',
  1416. hosts: ['c1', 'c2'],
  1417. onSingleHost: false,
  1418. category: 'processes'
  1419. }
  1420. ],
  1421. warningsByHost: [1, 1]
  1422. }
  1423. }
  1424. ])
  1425. }
  1426. ]).forEach(function (category) {
  1427. describe(category.m, function () {
  1428. category.tests.forEach(function (test) {
  1429. describe(test.m, function () {
  1430. beforeEach(function () {
  1431. c.parseHostCheckWarnings({tasks: test.tasks});
  1432. });
  1433. it('warnings count is valid', function () {
  1434. expect(c.get('warnings.length')).to.be.equal(test.e.warnings.length);
  1435. });
  1436. test.e.warnings.forEach(function (warning, index) {
  1437. Object.keys(warning).forEach(function (warningKey) {
  1438. it('warning #' + (index + 1) + ' key: ' + warningKey, function () {
  1439. expect(c.get('warnings')[index][warningKey]).to.be.eql(warning[warningKey]);
  1440. });
  1441. });
  1442. });
  1443. Object.keys(test.e.warningsByHost).forEach(function (warningByHostKey, index) {
  1444. it ('warningsByHost #' + (index + 1), function () {
  1445. expect(c.get('warningsByHost')[index].warnings.length).to.equal(test.e.warningsByHost[warningByHostKey]);
  1446. });
  1447. });
  1448. });
  1449. });
  1450. });
  1451. });
  1452. it('should parse umask warnings', function () {
  1453. var tasks = [
  1454. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {umask: 24}}}},
  1455. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {umask: 1}}}}
  1456. ];
  1457. c.parseHostCheckWarnings({tasks: tasks});
  1458. var warnings = c.get('warnings');
  1459. expect(warnings.length).to.equal(1);
  1460. expect(warnings[0].hosts).to.eql(['c1']);
  1461. expect(warnings[0].hostsLong).to.eql(['c1']);
  1462. expect(warnings[0].onSingleHost).to.equal(true);
  1463. });
  1464. it('should parse umask warnings (2)', function () {
  1465. var tasks = [
  1466. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {umask: 24}}}},
  1467. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {umask: 25}}}}
  1468. ];
  1469. c.parseHostCheckWarnings({tasks: tasks});
  1470. var warnings = c.get('warnings');
  1471. expect(warnings.length).to.equal(2);
  1472. expect(warnings.mapProperty('hosts')).to.eql([
  1473. ['c1'],
  1474. ['c2']
  1475. ]);
  1476. });
  1477. it('should parse firewall warnings', function () {
  1478. var tasks = [
  1479. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}},
  1480. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {firewallRunning: false, firewallName: "iptables"}}}}
  1481. ];
  1482. c.parseHostCheckWarnings({tasks: tasks});
  1483. var warnings = c.get('warnings');
  1484. expect(warnings.length).to.equal(1);
  1485. expect(warnings[0].hosts).to.eql(['c1']);
  1486. expect(warnings[0].hostsLong).to.eql(['c1']);
  1487. expect(warnings[0].onSingleHost).to.equal(true);
  1488. });
  1489. it('should parse firewall warnings (2)', function () {
  1490. var tasks = [
  1491. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}},
  1492. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}}
  1493. ];
  1494. c.parseHostCheckWarnings({tasks: tasks});
  1495. var warnings = c.get('warnings');
  1496. expect(warnings.length).to.equal(1);
  1497. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1498. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1499. expect(warnings[0].onSingleHost).to.equal(false);
  1500. });
  1501. it('should parse reverseLookup warnings', function () {
  1502. var tasks = [
  1503. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: true}}}}
  1504. ];
  1505. c.parseHostCheckWarnings({tasks: tasks});
  1506. var warnings = c.get('warnings');
  1507. expect(warnings.length).to.equal(0);
  1508. });
  1509. it('should parse reverseLookup warnings (2)', function () {
  1510. var tasks = [
  1511. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: false}}}}
  1512. ];
  1513. c.parseHostCheckWarnings({tasks: tasks});
  1514. var warnings = c.get('warnings');
  1515. expect(warnings.length).to.equal(1);
  1516. expect(warnings[0].hosts).to.eql(['c1']);
  1517. expect(warnings[0].hostsLong).to.eql(['c1']);
  1518. expect(warnings[0].onSingleHost).to.equal(true);
  1519. });
  1520. it('should parse reverseLookup warnings (3)', function () {
  1521. var tasks = [
  1522. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: false}}}},
  1523. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {reverseLookup: false}}}}
  1524. ];
  1525. c.parseHostCheckWarnings({tasks: tasks});
  1526. var warnings = c.get('warnings');
  1527. expect(warnings.length).to.equal(1);
  1528. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1529. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1530. expect(warnings[0].onSingleHost).to.equal(false);
  1531. });
  1532. });
  1533. describe('#parseWarnings', function () {
  1534. beforeEach(function () {
  1535. sinon.stub(c, 'filterBootHosts', function (k) {
  1536. return k;
  1537. });
  1538. });
  1539. afterEach(function () {
  1540. c.filterBootHosts.restore();
  1541. });
  1542. it('no warnings if last_agent_env isn\'t specified', function () {
  1543. c.set('warnings', [
  1544. {}
  1545. ]);
  1546. c.set('warningsByHost', [
  1547. {},
  1548. {}
  1549. ]);
  1550. c.parseWarnings({items: [
  1551. {Hosts: {host_name: 'c1'}}
  1552. ]});
  1553. expect(c.get('warnings')).to.eql([]);
  1554. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1555. });
  1556. Em.A([
  1557. {
  1558. m: 'parse stackFoldersAndFiles',
  1559. tests: Em.A([
  1560. {
  1561. items: [
  1562. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}
  1563. ],
  1564. m: 'empty stackFoldersAndFiles',
  1565. e: {
  1566. warnings: [],
  1567. warningsByHost: [0]
  1568. }
  1569. },
  1570. {
  1571. items: [
  1572. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1573. {name: 'n1'}
  1574. ]}}}
  1575. ],
  1576. m: 'not empty stackFoldersAndFiles',
  1577. e: {
  1578. warnings: [
  1579. {
  1580. name: 'n1',
  1581. hosts: ['c1'],
  1582. onSingleHost: true,
  1583. category: 'fileFolders'
  1584. }
  1585. ],
  1586. warningsByHost: [1]
  1587. }
  1588. },
  1589. {
  1590. items: [
  1591. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1592. {name: 'n1'}
  1593. ]}}},
  1594. {Hosts: {host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [
  1595. {name: 'n1'}
  1596. ]}}}
  1597. ],
  1598. m: 'not empty stackFoldersAndFiles on two hosts',
  1599. e: {
  1600. warnings: [
  1601. {
  1602. name: 'n1',
  1603. hosts: ['c1', 'c2'],
  1604. onSingleHost: false,
  1605. category: 'fileFolders'
  1606. }
  1607. ],
  1608. warningsByHost: [1]
  1609. }
  1610. }
  1611. ])
  1612. },
  1613. {
  1614. m: 'parse hostHealth.liveServices',
  1615. tests: Em.A([
  1616. {
  1617. items: [
  1618. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: []}}}
  1619. ],
  1620. m: 'empty hostHealth',
  1621. e: {
  1622. warnings: [],
  1623. warningsByHost: [0]
  1624. }
  1625. },
  1626. {
  1627. items: [
  1628. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: []}}}}
  1629. ],
  1630. m: 'empty liveServices',
  1631. e: {
  1632. warnings: [],
  1633. warningsByHost: [0]
  1634. }
  1635. },
  1636. {
  1637. items: [
  1638. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1639. {status: 'Unhealthy', name: 'n1'}
  1640. ]}}}}
  1641. ],
  1642. m: 'not empty hostHealth.liveServices',
  1643. e: {
  1644. warnings: [
  1645. {
  1646. name: 'n1',
  1647. hosts: ['c1'],
  1648. onSingleHost: true,
  1649. category: 'services'
  1650. }
  1651. ],
  1652. warningsByHost: [1]
  1653. }
  1654. },
  1655. {
  1656. items: [
  1657. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1658. {status: 'Unhealthy', name: 'n1'}
  1659. ]}}}},
  1660. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {liveServices: [
  1661. {status: 'Unhealthy', name: 'n1'}
  1662. ]}}}}
  1663. ],
  1664. m: 'not empty hostHealth.liveServices on two hosts',
  1665. e: {
  1666. warnings: [
  1667. {
  1668. name: 'n1',
  1669. hosts: ['c1', 'c2'],
  1670. onSingleHost: false,
  1671. category: 'services'
  1672. }
  1673. ],
  1674. warningsByHost: [1, 1]
  1675. }
  1676. }
  1677. ])
  1678. },
  1679. {
  1680. m: 'parse existingUsers',
  1681. tests: Em.A([
  1682. {
  1683. items: [
  1684. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: []}}}
  1685. ],
  1686. m: 'empty existingUsers',
  1687. e: {
  1688. warnings: [],
  1689. warningsByHost: [0]
  1690. }
  1691. },
  1692. {
  1693. items: [
  1694. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1695. {name: 'n1'}
  1696. ]}}}
  1697. ],
  1698. m: 'not empty existingUsers',
  1699. e: {
  1700. warnings: [
  1701. {
  1702. name: 'n1',
  1703. hosts: ['c1'],
  1704. onSingleHost: true,
  1705. category: 'users'
  1706. }
  1707. ],
  1708. warningsByHost: [1]
  1709. }
  1710. },
  1711. {
  1712. items: [
  1713. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1714. {name: 'n1'}
  1715. ]}}},
  1716. {Hosts: {host_name: 'c2', last_agent_env: {existingUsers: [
  1717. {name: 'n1'}
  1718. ]}}}
  1719. ],
  1720. m: 'not empty existingUsers on two hosts',
  1721. e: {
  1722. warnings: [
  1723. {
  1724. name: 'n1',
  1725. hosts: ['c1', 'c2'],
  1726. onSingleHost: false,
  1727. category: 'users'
  1728. }
  1729. ],
  1730. warningsByHost: [1, 1]
  1731. }
  1732. }
  1733. ])
  1734. },
  1735. {
  1736. m: 'parse alternatives',
  1737. tests: Em.A([
  1738. {
  1739. items: [
  1740. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: []}}}
  1741. ],
  1742. m: 'empty alternatives',
  1743. e: {
  1744. warnings: [],
  1745. warningsByHost: [0]
  1746. }
  1747. },
  1748. {
  1749. items: [
  1750. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1751. {name: 'n1'}
  1752. ]}}}
  1753. ],
  1754. m: 'not empty alternatives',
  1755. e: {
  1756. warnings: [
  1757. {
  1758. name: 'n1',
  1759. hosts: ['c1'],
  1760. onSingleHost: true,
  1761. category: 'alternatives'
  1762. }
  1763. ],
  1764. warningsByHost: [1]
  1765. }
  1766. },
  1767. {
  1768. items: [
  1769. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1770. {name: 'n1'}
  1771. ]}}},
  1772. {Hosts: {host_name: 'c2', last_agent_env: {alternatives: [
  1773. {name: 'n1'}
  1774. ]}}}
  1775. ],
  1776. m: 'not empty alternatives on two hosts',
  1777. e: {
  1778. warnings: [
  1779. {
  1780. name: 'n1',
  1781. hosts: ['c1', 'c2'],
  1782. onSingleHost: false,
  1783. category: 'alternatives'
  1784. }
  1785. ],
  1786. warningsByHost: [1, 1]
  1787. }
  1788. }
  1789. ])
  1790. },
  1791. {
  1792. m: 'parse hostHealth.activeJavaProcs',
  1793. tests: Em.A([
  1794. {
  1795. items: [
  1796. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}
  1797. ],
  1798. m: 'empty hostHealth',
  1799. e: {
  1800. warnings: [],
  1801. warningsByHost: [0]
  1802. }
  1803. },
  1804. {
  1805. items: [
  1806. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: []}}}}
  1807. ],
  1808. m: 'empty activeJavaProcs',
  1809. e: {
  1810. warnings: [],
  1811. warningsByHost: [0]
  1812. }
  1813. },
  1814. {
  1815. items: [
  1816. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1817. {pid: 'n1', command: ''}
  1818. ]}}}}
  1819. ],
  1820. m: 'not empty hostHealth.activeJavaProcs',
  1821. e: {
  1822. warnings: [
  1823. {
  1824. pid: 'n1',
  1825. hosts: ['c1'],
  1826. onSingleHost: true,
  1827. category: 'processes'
  1828. }
  1829. ],
  1830. warningsByHost: [1]
  1831. }
  1832. },
  1833. {
  1834. items: [
  1835. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1836. {pid: 'n1', command: ''}
  1837. ]}}}},
  1838. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {activeJavaProcs: [
  1839. {pid: 'n1', command: ''}
  1840. ]}}}}
  1841. ],
  1842. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1843. e: {
  1844. warnings: [
  1845. {
  1846. pid: 'n1',
  1847. hosts: ['c1', 'c2'],
  1848. onSingleHost: false,
  1849. category: 'processes'
  1850. }
  1851. ],
  1852. warningsByHost: [1, 1]
  1853. }
  1854. }
  1855. ])
  1856. }
  1857. ]).forEach(function (category) {
  1858. describe(category.m, function () {
  1859. category.tests.forEach(function (test) {
  1860. describe(test.m, function () {
  1861. beforeEach(function () {
  1862. c.parseWarnings({items: test.items});
  1863. });
  1864. test.e.warnings.forEach(function (warning, index) {
  1865. Object.keys(warning).forEach(function (warningKey) {
  1866. it('warning #' + (index + 1) + ' key: ' + warningKey, function () {
  1867. expect(c.get('warnings')[index][warningKey]).to.be.eql(warning[warningKey]);
  1868. });
  1869. });
  1870. });
  1871. Object.keys(test.e.warningsByHost).forEach(function (warningByHostKey, index) {
  1872. it ('warningsByHost #' + (index + 1), function () {
  1873. expect(c.get('warningsByHost')[index].warnings.length).to.equal(test.e.warningsByHost[warningByHostKey]);
  1874. });
  1875. });
  1876. });
  1877. });
  1878. });
  1879. });
  1880. it('should parse umask warnings', function () {
  1881. var items = [
  1882. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1883. {Hosts: {host_name: 'c2', last_agent_env: {umask: 1}}}
  1884. ];
  1885. c.parseWarnings({items: items});
  1886. var warnings = c.get('warnings');
  1887. expect(warnings.length).to.equal(1);
  1888. expect(warnings[0].hosts).to.eql(['c1']);
  1889. expect(warnings[0].hostsLong).to.eql(['c1']);
  1890. expect(warnings[0].onSingleHost).to.equal(true);
  1891. });
  1892. it('should parse umask warnings (2)', function () {
  1893. var items = [
  1894. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1895. {Hosts: {host_name: 'c2', last_agent_env: {umask: 25}}}
  1896. ];
  1897. c.parseWarnings({items: items});
  1898. var warnings = c.get('warnings');
  1899. expect(warnings.length).to.equal(2);
  1900. expect(warnings.mapProperty('hosts')).to.eql([
  1901. ['c1'],
  1902. ['c2']
  1903. ]);
  1904. });
  1905. it('should parse firewall warnings', function () {
  1906. var items = [
  1907. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1908. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: false, firewallName: "iptables"}}}
  1909. ];
  1910. c.parseWarnings({items: items});
  1911. var warnings = c.get('warnings');
  1912. expect(warnings.length).to.equal(1);
  1913. expect(warnings[0].hosts).to.eql(['c1']);
  1914. expect(warnings[0].hostsLong).to.eql(['c1']);
  1915. expect(warnings[0].onSingleHost).to.equal(true);
  1916. });
  1917. it('should parse firewall warnings (2)', function () {
  1918. var items = [
  1919. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1920. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}}
  1921. ];
  1922. c.parseWarnings({items: items});
  1923. var warnings = c.get('warnings');
  1924. expect(warnings.length).to.equal(1);
  1925. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1926. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1927. expect(warnings[0].onSingleHost).to.equal(false);
  1928. });
  1929. it('should parse reverseLookup warnings', function () {
  1930. var items = [
  1931. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1932. ];
  1933. c.parseWarnings({items: items});
  1934. var warnings = c.get('warnings');
  1935. expect(warnings.length).to.equal(0);
  1936. });
  1937. it('should parse reverseLookup warnings (2)', function () {
  1938. var items = [
  1939. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1940. ];
  1941. c.parseWarnings({items: items});
  1942. var warnings = c.get('warnings');
  1943. expect(warnings.length).to.equal(1);
  1944. expect(warnings[0].hosts).to.eql(['c1']);
  1945. expect(warnings[0].hostsLong).to.eql(['c1']);
  1946. expect(warnings[0].onSingleHost).to.equal(true);
  1947. });
  1948. it('should parse reverseLookup warnings (3)', function () {
  1949. var items = [
  1950. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1951. {Hosts: {host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1952. ];
  1953. c.parseWarnings({items: items});
  1954. var warnings = c.get('warnings');
  1955. expect(warnings.length).to.equal(1);
  1956. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1957. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1958. expect(warnings[0].onSingleHost).to.equal(false);
  1959. });
  1960. });
  1961. describe('#navigateStep', function () {
  1962. beforeEach(function () {
  1963. sinon.stub(c, 'setupBootStrap', Em.K);
  1964. });
  1965. afterEach(function () {
  1966. c.setupBootStrap.restore();
  1967. });
  1968. Em.A([
  1969. {
  1970. isLoaded: true,
  1971. manualInstall: false,
  1972. bootStatus: false,
  1973. m: 'should call setupBootStrap',
  1974. e: true
  1975. },
  1976. {
  1977. isLoaded: true,
  1978. manualInstall: false,
  1979. bootStatus: true,
  1980. m: 'shouldn\'t call setupBootStrap (1)',
  1981. e: false
  1982. },
  1983. {
  1984. isLoaded: false,
  1985. manualInstall: false,
  1986. bootStatus: false,
  1987. m: 'shouldn\'t call setupBootStrap (2)',
  1988. e: false
  1989. },
  1990. {
  1991. isLoaded: false,
  1992. manualInstall: true,
  1993. bootStatus: false,
  1994. m: 'shouldn\'t call setupBootStrap (3)',
  1995. e: false
  1996. }
  1997. ]).forEach(function (test) {
  1998. it(test.m, function () {
  1999. c.reopen({
  2000. isLoaded: test.isLoaded,
  2001. content: {
  2002. installedHosts: [],
  2003. installOptions: {
  2004. manualInstall: test.manualInstall
  2005. }
  2006. },
  2007. wizardController: Em.Object.create({
  2008. getDBProperty: function () {
  2009. return test.bootStatus
  2010. }
  2011. })
  2012. });
  2013. c.navigateStep();
  2014. if (test.e) {
  2015. expect(c.setupBootStrap.calledOnce).to.equal(true);
  2016. }
  2017. else {
  2018. expect(c.setupBootStrap.called).to.equal(false);
  2019. }
  2020. });
  2021. });
  2022. describe('should start registration', function () {
  2023. beforeEach(function () {
  2024. c.reopen({
  2025. isLoaded: true,
  2026. hosts: [
  2027. {},
  2028. {},
  2029. {}
  2030. ],
  2031. content: {
  2032. installedHosts: [],
  2033. installOptions: {
  2034. manualInstall: true
  2035. }
  2036. },
  2037. setRegistrationInProgress: Em.K,
  2038. startRegistration: Em.K
  2039. });
  2040. sinon.spy(c, 'startRegistration');
  2041. c.navigateStep();
  2042. });
  2043. afterEach(function () {
  2044. c.startRegistration.restore();
  2045. });
  2046. it('startRegistration is called once', function () {
  2047. expect(c.startRegistration.calledOnce).to.equal(true);
  2048. });
  2049. it('all hosts are bootHosts', function () {
  2050. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  2051. });
  2052. it('registrationStartedAt is null', function () {
  2053. expect(c.get('registrationStartedAt')).to.be.null;
  2054. });
  2055. });
  2056. });
  2057. describe('#setupBootStrap', function () {
  2058. var cases = [
  2059. {
  2060. customizeAgentUserAccount: true,
  2061. userRunAs: 'user',
  2062. title: 'Ambari Agent user account customize enabled'
  2063. },
  2064. {
  2065. customizeAgentUserAccount: false,
  2066. userRunAs: 'root',
  2067. title: 'Ambari Agent user account customize disabled'
  2068. }
  2069. ],
  2070. controller = App.WizardStep3Controller.create({
  2071. content: {
  2072. installOptions: {
  2073. sshKey: 'key',
  2074. sshUser: 'root',
  2075. sshPort: '123',
  2076. agentUser: 'user'
  2077. },
  2078. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } },
  2079. controllerName: 'installerController'
  2080. }
  2081. });
  2082. beforeEach(function () {
  2083. sinon.stub(App.router.get('installerController'), 'launchBootstrap', Em.K);
  2084. this.mock = sinon.stub(App, 'get');
  2085. });
  2086. afterEach(function () {
  2087. App.router.get('installerController').launchBootstrap.restore();
  2088. this.mock.restore();
  2089. });
  2090. cases.forEach(function (item) {
  2091. it(item.title, function () {
  2092. this.mock.withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  2093. controller.setupBootStrap();
  2094. expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
  2095. verbose: true,
  2096. sshKey: 'key',
  2097. hosts: ['host0', 'host1'],
  2098. user: 'root',
  2099. sshPort: '123',
  2100. userRunAs: item.userRunAs
  2101. }));
  2102. });
  2103. });
  2104. });
  2105. describe('#checkHostDiskSpace', function () {
  2106. Em.A([
  2107. {
  2108. diskInfo: [
  2109. {
  2110. available: App.minDiskSpace * 1024 * 1024 - 1024,
  2111. mountpoint: '/'
  2112. }
  2113. ],
  2114. m: 'available less than App.minDiskSpace',
  2115. e: false
  2116. },
  2117. {
  2118. diskInfo: [
  2119. {
  2120. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  2121. mountpoint: '/usr'
  2122. }
  2123. ],
  2124. m: 'available less than App.minDiskSpaceUsrLib (1)',
  2125. e: false
  2126. },
  2127. {
  2128. diskInfo: [
  2129. {
  2130. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  2131. mountpoint: '/usr/lib'
  2132. }
  2133. ],
  2134. m: 'available less than App.minDiskSpaceUsrLib (2)',
  2135. e: false
  2136. },
  2137. {
  2138. diskInfo: [
  2139. {
  2140. available: App.minDiskSpace * 1024 * 1024 + 1024,
  2141. mountpoint: '/'
  2142. }
  2143. ],
  2144. m: 'available greater than App.minDiskSpace',
  2145. e: true
  2146. },
  2147. {
  2148. diskInfo: [
  2149. {
  2150. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2151. mountpoint: '/usr'
  2152. }
  2153. ],
  2154. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  2155. e: true
  2156. },
  2157. {
  2158. diskInfo: [
  2159. {
  2160. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2161. mountpoint: '/usr/lib'
  2162. }
  2163. ],
  2164. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  2165. e: true
  2166. },
  2167. {
  2168. diskInfo: [
  2169. {
  2170. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2171. mountpoint: '/home/tdk'
  2172. }
  2173. ],
  2174. m: 'mount point without free space checks',
  2175. e: true
  2176. }
  2177. ]).forEach(function (test) {
  2178. it(test.m, function () {
  2179. var r = c.checkHostDiskSpace('', test.diskInfo);
  2180. expect(Em.isEmpty(r)).to.equal(test.e);
  2181. });
  2182. });
  2183. });
  2184. describe('#checkHostOSType', function () {
  2185. it('should return empty string if no stacks provided', function () {
  2186. c.reopen({content: {stacks: null}});
  2187. expect(c.checkHostOSType()).to.equal('');
  2188. });
  2189. it('os type is valid', function () {
  2190. var osType = 'redhat6';
  2191. c.reopen({
  2192. content: {
  2193. stacks: [
  2194. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  2195. ]
  2196. }
  2197. });
  2198. expect(c.checkHostOSType(osType, '')).to.equal('');
  2199. });
  2200. it('os type is invalid', function () {
  2201. var osType = 'os2';
  2202. c.reopen({
  2203. content: {
  2204. stacks: [
  2205. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  2206. ]
  2207. }
  2208. });
  2209. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  2210. });
  2211. });
  2212. describe('#getHostInfoSuccessCallback', function () {
  2213. var jsonData = {items: [
  2214. {Hosts: {host_name: 'h1'}}
  2215. ]};
  2216. var skipBootstrap = false;
  2217. beforeEach(function () {
  2218. sinon.stub(c, 'parseWarnings', Em.K);
  2219. sinon.stub(c, 'stopRegistration', Em.K);
  2220. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  2221. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  2222. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  2223. sinon.stub(App, 'get', function (k) {
  2224. if ('skipBootstrap' === k) return skipBootstrap;
  2225. return Em.get(App, k);
  2226. });
  2227. c.reopen({
  2228. bootHosts: [Em.Object.create({name: 'h1'})]
  2229. });
  2230. sinon.stub(c, 'checkHostOSType', function () {
  2231. return 'not_null_value';
  2232. });
  2233. });
  2234. afterEach(function () {
  2235. c.parseWarnings.restore();
  2236. c.stopRegistration.restore();
  2237. c.checkHostDiskSpace.restore();
  2238. c._setHostDataFromLoadedHostInfo.restore();
  2239. c._setHostDataWithSkipBootstrap.restore();
  2240. App.get.restore();
  2241. c.checkHostOSType.restore();
  2242. });
  2243. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function () {
  2244. skipBootstrap = true;
  2245. c.getHostInfoSuccessCallback(jsonData);
  2246. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  2247. });
  2248. it('should add repo warnings', function () {
  2249. skipBootstrap = false;
  2250. c.getHostInfoSuccessCallback(jsonData);
  2251. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  2252. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  2253. });
  2254. it('should add disk warnings', function () {
  2255. skipBootstrap = false;
  2256. c.getHostInfoSuccessCallback(jsonData);
  2257. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  2258. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  2259. });
  2260. });
  2261. describe('#_setHostDataWithSkipBootstrap', function () {
  2262. it('should set mock-data', function () {
  2263. var host = Em.Object.create({});
  2264. c._setHostDataWithSkipBootstrap(host);
  2265. expect(host.get('cpu')).to.equal(2);
  2266. expect(host.get('memory')).to.equal('2000000.00');
  2267. expect(host.get('disk_info.length')).to.equal(4);
  2268. });
  2269. });
  2270. describe('#_setHostDataFromLoadedHostInfo', function () {
  2271. var host;
  2272. beforeEach(function () {
  2273. host = Em.Object.create();
  2274. var hostInfo = {
  2275. Hosts: {
  2276. cpu_count: 2,
  2277. total_mem: 12345,
  2278. os_type: 't1',
  2279. os_arch: 'os1',
  2280. os_family: 'osf1',
  2281. ip: '0.0.0.0',
  2282. disk_info: [
  2283. {mountpoint: '/boot'},
  2284. {mountpoint: '/usr'},
  2285. {mountpoint: '/no-boot'},
  2286. {mountpoint: '/boot'}
  2287. ]
  2288. }
  2289. };
  2290. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  2291. });
  2292. it('cpu', function () {
  2293. expect(host.get('cpu')).to.equal(2);
  2294. });
  2295. it('os_type', function () {
  2296. expect(host.get('os_type')).to.equal('t1');
  2297. });
  2298. it('os_arch', function () {
  2299. expect(host.get('os_arch')).to.equal('os1');
  2300. });
  2301. it('os_family', function () {
  2302. expect(host.get('os_family')).to.equal('osf1');
  2303. });
  2304. it('ip', function () {
  2305. expect(host.get('ip')).to.equal('0.0.0.0');
  2306. });
  2307. it('memory', function () {
  2308. expect(host.get('memory')).to.equal('12345.00');
  2309. });
  2310. it('disk_info.length', function () {
  2311. expect(host.get('disk_info.length')).to.equal(2);
  2312. });
  2313. });
  2314. describe('#getJDKNameSuccessCallback', function () {
  2315. it('should set proper data to controller properties', function () {
  2316. var expected = {
  2317. name: 'name',
  2318. home: 'home',
  2319. location: 'location'
  2320. },
  2321. data = {
  2322. RootServiceComponents: {
  2323. properties: {
  2324. 'jdk.name': expected.name,
  2325. 'java.home': expected.home,
  2326. 'jdk_location': expected.location
  2327. }
  2328. }
  2329. };
  2330. c.getJDKNameSuccessCallback(data);
  2331. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  2332. expect(c.get('jdkLocation')).to.equal(expected.location);
  2333. expect(c.get('javaHome')).to.equal(expected.home);
  2334. });
  2335. });
  2336. describe('#doCheckJDK', function () {
  2337. it('should do request to the ambari-server', function () {
  2338. var bootHosts = [
  2339. Em.Object.create({name: 'n1', bootStatus: 'REGISTERED'}),
  2340. Em.Object.create({name: 'n2', bootStatus: 'REGISTERED'})
  2341. ],
  2342. javaHome = '/java',
  2343. jdkLocation = '/jdk';
  2344. c.reopen({
  2345. bootHosts: bootHosts,
  2346. javaHome: javaHome,
  2347. jdkLocation: jdkLocation
  2348. });
  2349. c.doCheckJDK();
  2350. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check');
  2351. expect(args).exists;
  2352. });
  2353. });
  2354. describe('#doCheckJDKsuccessCallback', function () {
  2355. it('should set jdkRequestIndex if data provided', function () {
  2356. var data = {
  2357. href: '/a/b/c'
  2358. },
  2359. expected = 'c';
  2360. c.set('jdkRequestIndex', null);
  2361. c.doCheckJDKsuccessCallback(data);
  2362. expect(c.get('jdkRequestIndex')).to.equal(expected);
  2363. });
  2364. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function () {
  2365. var data = null,
  2366. expected = true;
  2367. c.set('isJDKWarningsLoaded', false);
  2368. c.set('jdkCategoryWarnings', {});
  2369. c.doCheckJDKsuccessCallback(data);
  2370. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  2371. });
  2372. it('should do request to ambari-server', function () {
  2373. var data = null,
  2374. jdkRequestIndex = 'jdkRequestIndex';
  2375. c.set('jdkRequestIndex', jdkRequestIndex);
  2376. c.set('jdkCategoryWarnings', null);
  2377. c.doCheckJDKsuccessCallback(data);
  2378. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check.get_results');
  2379. expect(args).exists;
  2380. });
  2381. });
  2382. describe('#doCheckJDKerrorCallback', function () {
  2383. it('should set isJDKWarningsLoaded to true', function () {
  2384. c.set('isJDKWarningsLoaded', false);
  2385. c.doCheckJDKerrorCallback();
  2386. expect(c.get('isJDKWarningsLoaded')).to.be.true;
  2387. });
  2388. });
  2389. describe('#parseJDKCheckResults', function () {
  2390. beforeEach(function () {
  2391. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  2392. });
  2393. afterEach(function () {
  2394. c.doCheckJDKsuccessCallback.restore();
  2395. });
  2396. it('should set jdkCategoryWarnings to null if no data', function () {
  2397. var data = {Requests: {}};
  2398. c.set('jdkCategoryWarnings', {});
  2399. c.parseJDKCheckResults(data);
  2400. expect(c.get('jdkCategoryWarnings')).to.be.null;
  2401. });
  2402. it('should parse warnings (1)', function () {
  2403. var data = {
  2404. Requests: {
  2405. end_time: 1
  2406. },
  2407. tasks: []
  2408. };
  2409. c.set('jdkCategoryWarnings', {});
  2410. c.parseJDKCheckResults(data);
  2411. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  2412. });
  2413. it('should parse warnings (2)', function () {
  2414. var data = {
  2415. Requests: {
  2416. end_time: 1
  2417. },
  2418. tasks: [
  2419. {
  2420. Tasks: {
  2421. host_name: 'h1',
  2422. structured_out: {
  2423. java_home_check: {
  2424. exit_code: 1
  2425. }
  2426. }
  2427. }
  2428. },
  2429. {
  2430. Tasks: {
  2431. host_name: 'h2',
  2432. structured_out: {
  2433. java_home_check: {
  2434. exit_code: 0
  2435. }
  2436. }
  2437. }
  2438. }
  2439. ]
  2440. };
  2441. c.set('jdkCategoryWarnings', {});
  2442. c.parseJDKCheckResults(data);
  2443. var result = c.get('jdkCategoryWarnings');
  2444. expect(result.length).to.equal(1);
  2445. expect(result[0].hostsNames).to.eql(['h1']);
  2446. });
  2447. });
  2448. describe('#getHostCheckTasksSuccess', function() {
  2449. beforeEach(function() {
  2450. sinon.stub(c, 'getHostInfo', Em.K);
  2451. sinon.stub(c, 'parseHostNameResolution', Em.K);
  2452. sinon.stub(c, 'getGeneralHostCheck', Em.K);
  2453. sinon.stub(c, 'getHostCheckTasks', Em.K);
  2454. });
  2455. afterEach(function() {
  2456. c.getHostInfo.restore();
  2457. c.parseHostNameResolution.restore();
  2458. c.getGeneralHostCheck.restore();
  2459. c.getHostCheckTasks.restore();
  2460. });
  2461. var dataInProgress = {
  2462. Requests: {
  2463. request_status: "IN_PROGRESS"
  2464. }
  2465. };
  2466. it('run getHostCheckTasks', function() {
  2467. c.getHostCheckTasksSuccess(dataInProgress);
  2468. expect(c.getHostCheckTasks.calledOnce).to.be.true;
  2469. });
  2470. var hostResolutionCheckComplete = {
  2471. Requests: {
  2472. request_status: "COMPLETED",
  2473. inputs: "host_resolution_check"
  2474. }
  2475. };
  2476. it('run parseHostNameResolution and getGeneralHostCheck', function() {
  2477. c.getHostCheckTasksSuccess(hostResolutionCheckComplete);
  2478. expect(c.parseHostNameResolution.calledWith(hostResolutionCheckComplete)).to.be.true;
  2479. expect(c.getGeneralHostCheck.calledOnce).to.be.true;
  2480. });
  2481. var lastAgentEnvCheckComplete = {
  2482. Requests: {
  2483. request_status: "COMPLETED",
  2484. inputs: "last_agent_env_check"
  2485. },
  2486. tasks: [
  2487. {
  2488. Tasks: {
  2489. host_name: 'h1',
  2490. structured_out: {
  2491. "installed_packages": [
  2492. {
  2493. "version": "b1",
  2494. "name": "n1",
  2495. "repoName": "r1"
  2496. },
  2497. {
  2498. "version": "b2",
  2499. "name": "n2",
  2500. "repoName": "r2"
  2501. }
  2502. ]
  2503. }
  2504. }
  2505. }
  2506. ]
  2507. };
  2508. it('run getHostInfo', function() {
  2509. c.getHostCheckTasksSuccess(lastAgentEnvCheckComplete);
  2510. expect(c.get('stopChecking')).to.be.true;
  2511. expect(c.getHostInfo.calledOnce).to.be.true;
  2512. expect(JSON.parse(JSON.stringify(c.get('hostsPackagesData')))).eql([
  2513. {
  2514. hostName: 'h1',
  2515. installedPackages: [
  2516. {
  2517. "version": "b1",
  2518. "name": "n1",
  2519. "repoName": "r1"
  2520. },
  2521. {
  2522. "version": "b2",
  2523. "name": "n2",
  2524. "repoName": "r2"
  2525. }
  2526. ]
  2527. }
  2528. ]);
  2529. });
  2530. });
  2531. describe('#getDataForCheckRequest', function() {
  2532. var tests = [
  2533. {
  2534. bootHosts: [
  2535. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2536. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2537. ],
  2538. addHosts: true,
  2539. rez: {
  2540. RequestInfo: {
  2541. "action": "check_host",
  2542. "context": "Check host",
  2543. "parameters": {
  2544. "check_execute_list": 'checkExecuteList',
  2545. "jdk_location" : "jdk_location",
  2546. "threshold": "20",
  2547. "hosts": "h1"
  2548. }
  2549. },
  2550. resource_filters: {
  2551. "hosts": "h1"
  2552. }
  2553. },
  2554. m: 'with add host param'
  2555. },
  2556. {
  2557. bootHosts: [
  2558. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2559. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2560. ],
  2561. addHosts: false,
  2562. rez: {
  2563. RequestInfo: {
  2564. "action": "check_host",
  2565. "context": "Check host",
  2566. "parameters": {
  2567. "check_execute_list": 'checkExecuteList',
  2568. "jdk_location" : "jdk_location",
  2569. "threshold": "20"
  2570. }
  2571. },
  2572. resource_filters: {
  2573. "hosts": "h1"
  2574. }
  2575. },
  2576. m: 'without add host param'
  2577. },
  2578. {
  2579. bootHosts: [
  2580. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h1'}),
  2581. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2582. ],
  2583. rez: null,
  2584. m: 'with all hosts failed'
  2585. }
  2586. ];
  2587. beforeEach(function() {
  2588. sinon.stub(App.get('router'), 'get' , function(p) {
  2589. return p === 'clusterController.ambariProperties.jdk_location' ? 'jdk_location' : Em.get(App.get('router'), p);
  2590. })
  2591. });
  2592. afterEach(function() {
  2593. App.get('router').get.restore();
  2594. });
  2595. tests.forEach(function(t) {
  2596. it(t.m, function() {
  2597. c.set('bootHosts', t.bootHosts);
  2598. expect(c.getDataForCheckRequest('checkExecuteList', t.addHosts)).to.be.eql(t.rez);
  2599. });
  2600. })
  2601. });
  2602. describe('#isBackDisabled', function () {
  2603. var cases = [
  2604. {
  2605. inputData: {
  2606. isRegistrationInProgress: true,
  2607. isWarningsLoaded: true,
  2608. isBootstrapFailed: true
  2609. },
  2610. isBackDisabled: false
  2611. },
  2612. {
  2613. inputData: {
  2614. isRegistrationInProgress: true,
  2615. isWarningsLoaded: false,
  2616. isBootstrapFailed: false
  2617. },
  2618. isBackDisabled: true
  2619. },
  2620. {
  2621. inputData: {
  2622. isRegistrationInProgress: true,
  2623. isWarningsLoaded: true,
  2624. isBootstrapFailed: false
  2625. },
  2626. isBackDisabled: true
  2627. },
  2628. {
  2629. inputData: {
  2630. isRegistrationInProgress: true,
  2631. isWarningsLoaded: false,
  2632. isBootstrapFailed: true
  2633. },
  2634. isBackDisabled: false
  2635. },
  2636. {
  2637. inputData: {
  2638. isRegistrationInProgress: false,
  2639. isWarningsLoaded: true,
  2640. isBootstrapFailed: true
  2641. },
  2642. isBackDisabled: false
  2643. },
  2644. {
  2645. inputData: {
  2646. isRegistrationInProgress: false,
  2647. isWarningsLoaded: false,
  2648. isBootstrapFailed: false
  2649. },
  2650. isBackDisabled: true
  2651. },
  2652. {
  2653. inputData: {
  2654. isRegistrationInProgress: false,
  2655. isWarningsLoaded: true,
  2656. isBootstrapFailed: false
  2657. },
  2658. isBackDisabled: false
  2659. },
  2660. {
  2661. inputData: {
  2662. isRegistrationInProgress: false,
  2663. isWarningsLoaded: false,
  2664. isBootstrapFailed: true
  2665. },
  2666. isBackDisabled: false
  2667. }
  2668. ];
  2669. cases.forEach(function (item) {
  2670. var title = Em.keys(item.inputData).map(function (key) {
  2671. return key + ':' + item.inputData[key];
  2672. }).join(', ');
  2673. it(title, function () {
  2674. c.setProperties({
  2675. isRegistrationInProgress: item.inputData.isRegistrationInProgress,
  2676. isBootstrapFailed: item.inputData.isBootstrapFailed
  2677. });
  2678. c.reopen({
  2679. isWarningsLoaded: item.inputData.isWarningsLoaded
  2680. });
  2681. expect(c.get('isBackDisabled')).to.equal(item.isBackDisabled);
  2682. });
  2683. });
  2684. });
  2685. describe('#hostsInCluster', function () {
  2686. var hosts = {
  2687. host1: {isInstalled: true},
  2688. host2: {isInstalled: false},
  2689. host3: {isInstalled: true},
  2690. host4: {isInstalled: false}
  2691. };
  2692. beforeEach(function () {
  2693. c.set('content', {hosts: hosts});
  2694. c.propertyDidChange('hostsInCluster');
  2695. });
  2696. it('should take only installed hosts', function () {
  2697. expect(c.get('hostsInCluster')).to.be.eql(['host1', 'host3']);
  2698. });
  2699. });
  2700. describe('#filterHostsData', function () {
  2701. var bootHosts = [
  2702. Em.Object.create({name: 'c1'}),
  2703. Em.Object.create({name: 'c2'}),
  2704. Em.Object.create({name: 'c3'})
  2705. ];
  2706. var data = {
  2707. href: 'abc',
  2708. tasks: [
  2709. {Tasks: {host_name: 'c1'}},
  2710. {Tasks: {host_name: 'c2'}},
  2711. {Tasks: {host_name: 'c3'}},
  2712. {Tasks: {host_name: 'c2'}},
  2713. {Tasks: {host_name: 'c3'}},
  2714. {Tasks: {host_name: 'c4'}}
  2715. ]
  2716. };
  2717. beforeEach(function() {
  2718. c.set('bootHosts', bootHosts);
  2719. this.result = c.filterHostsData(data);
  2720. });
  2721. it('href is valid', function () {
  2722. expect(this.result.href).to.be.equal('abc');
  2723. });
  2724. it('tasks are valid', function () {
  2725. expect(this.result.tasks).to.be.eql([
  2726. {Tasks: {host_name: 'c1'}},
  2727. {Tasks: {host_name: 'c2'}},
  2728. {Tasks: {host_name: 'c3'}},
  2729. {Tasks: {host_name: 'c2'}},
  2730. {Tasks: {host_name: 'c3'}}
  2731. ]);
  2732. });
  2733. });
  2734. describe('#parseHostNameResolution', function () {
  2735. var data = {
  2736. tasks: [
  2737. {Tasks: {status: 'COMPLETED', host_name: 'h1', structured_out: {host_resolution_check: {failed_count: 2, failures: [{host: 'h2'}, {host: 'h3'}]}}}},
  2738. {Tasks: {status: 'COMPLETED', host_name: 'h4', structured_out: {host_resolution_check: {failed_count: 2, failures: [{host: 'h5'}, {host: 'h6'}]}}}},
  2739. {Tasks: {status: 'COMPLETED', host_name: 'h7', structured_out: {host_resolution_check: {failed_count: 1, failures: [{host: 'h8'}]}}}}
  2740. ]
  2741. };
  2742. var hostCheckWarnings = [];
  2743. beforeEach(function () {
  2744. c.set('hostCheckWarnings', hostCheckWarnings);
  2745. c.parseHostNameResolution(data);
  2746. this.warnings = c.get('hostCheckWarnings').findProperty('name', Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.error'));
  2747. });
  2748. it('Host check warnings for hostname resolutions exist', function () {
  2749. expect(this.warnings).to.exist;
  2750. });
  2751. it('hostsNames are ["h1", "h4", "h7"]', function () {
  2752. expect(this.warnings.hostsNames.toArray()).to.be.eql(['h1', 'h4', 'h7']);
  2753. });
  2754. it('warning appears on many hosts', function () {
  2755. expect(this.warnings.onSingleHost).to.be.false;
  2756. });
  2757. it('validation context for hosts is valid', function () {
  2758. var hosts = this.warnings.hosts;
  2759. var expected = [
  2760. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h1', 2 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.hosts')),
  2761. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h4', 2 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.hosts')),
  2762. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h7', 1 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.host'))
  2763. ];
  2764. expect(hosts).to.be.eql(expected);
  2765. });
  2766. it('validation context (long) for hosts is valid', function () {
  2767. var hostsLong = this.warnings.hostsLong;
  2768. var expected = [
  2769. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h1', 'h2, h3'),
  2770. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h4', 'h5, h6'),
  2771. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h7', 'h8')
  2772. ];
  2773. expect(hostsLong).to.be.eql(expected);
  2774. });
  2775. });
  2776. describe('#getHostCheckTasksError', function () {
  2777. beforeEach(function () {
  2778. c.set('stopChecking', false);
  2779. });
  2780. it('should set `stopChecking` to true', function () {
  2781. c.getHostCheckTasksError();
  2782. expect(c.get('stopChecking')).to.be.true;
  2783. });
  2784. });
  2785. describe('#closeReloadPopupOnExit', function () {
  2786. var cases = [
  2787. {
  2788. stopBootstrap: true,
  2789. closeReloadPopupCallCount: 1,
  2790. title: 'bootstrap should be stopped'
  2791. },
  2792. {
  2793. stopBootstrap: false,
  2794. closeReloadPopupCallCount: 0,
  2795. title: 'bootstrap should not be stopped'
  2796. }
  2797. ];
  2798. beforeEach(function () {
  2799. sinon.stub(c, 'closeReloadPopup', Em.K);
  2800. });
  2801. afterEach(function () {
  2802. c.closeReloadPopup.restore();
  2803. });
  2804. cases.forEach(function (item) {
  2805. it(item.title, function () {
  2806. if (c.get('stopBootstrap') === item.stopBootstrap) {
  2807. c.propertyDidChange('stopBootstrap');
  2808. } else {
  2809. c.set('stopBootstrap', item.stopBootstrap);
  2810. }
  2811. expect(c.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
  2812. });
  2813. });
  2814. });
  2815. });