step3_test.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295
  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.set('router.nextBtnClickInProgress', false);
  40. });
  41. afterEach(function () {
  42. App.db.getDisplayLength.restore();
  43. App.router.send.restore();
  44. App.db.getFilterConditions.restore();
  45. App.set('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. });
  929. describe('#hostLogPopup', function () {
  930. beforeEach(function () {
  931. sinon.spy(App.ModalPopup, 'show');
  932. });
  933. afterEach(function () {
  934. App.ModalPopup.show.restore();
  935. });
  936. it('should show App.ModalPopup', function () {
  937. c.hostLogPopup({context: Em.Object.create({})});
  938. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  939. });
  940. });
  941. describe('#rerunChecksSuccessCallback', function () {
  942. beforeEach(function () {
  943. sinon.stub(c, 'parseWarnings', Em.K);
  944. });
  945. afterEach(function () {
  946. c.parseWarnings.restore();
  947. });
  948. it('should set checksUpdateProgress to 100', function () {
  949. c.set('checksUpdateProgress', 0);
  950. c.rerunChecksSuccessCallback({items: []});
  951. expect(c.get('checksUpdateProgress')).to.equal(100);
  952. });
  953. it('should set checksUpdateStatus to SUCCESS', function () {
  954. c.set('checksUpdateStatus', '');
  955. c.rerunChecksSuccessCallback({items: []});
  956. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  957. });
  958. it('should call parseWarnings', function () {
  959. c.rerunChecksSuccessCallback({items: []});
  960. expect(c.parseWarnings.calledOnce).to.equal(true);
  961. });
  962. });
  963. describe('#rerunChecksErrorCallback', function () {
  964. it('should set checksUpdateProgress to 100', function () {
  965. c.set('checksUpdateProgress', 0);
  966. c.rerunChecksErrorCallback({});
  967. expect(c.get('checksUpdateProgress')).to.equal(100);
  968. });
  969. it('should set checksUpdateStatus to FAILED', function () {
  970. c.set('checksUpdateStatus', '');
  971. c.rerunChecksErrorCallback({});
  972. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  973. });
  974. });
  975. describe('#filterBootHosts', function () {
  976. var tests = Em.A([
  977. {
  978. bootHosts: [
  979. Em.Object.create({name: 'c1'}),
  980. Em.Object.create({name: 'c2'})
  981. ],
  982. data: {
  983. items: [
  984. {Hosts: {host_name: 'c1'}}
  985. ]
  986. },
  987. m: 'one host',
  988. e: ['c1']
  989. },
  990. {
  991. bootHosts: [
  992. Em.Object.create({name: 'c1'}),
  993. Em.Object.create({name: 'c2'})
  994. ],
  995. data: {
  996. items: [
  997. {Hosts: {host_name: 'c3'}}
  998. ]
  999. },
  1000. m: 'no hosts',
  1001. e: []
  1002. },
  1003. {
  1004. bootHosts: [
  1005. Em.Object.create({name: 'c1'}),
  1006. Em.Object.create({name: 'c2'})
  1007. ],
  1008. data: {
  1009. items: [
  1010. {Hosts: {host_name: 'c1'}},
  1011. {Hosts: {host_name: 'c2'}}
  1012. ]
  1013. },
  1014. m: 'many hosts',
  1015. e: ['c1', 'c2']
  1016. }
  1017. ]);
  1018. tests.forEach(function (test) {
  1019. it(test.m, function () {
  1020. c.reopen({bootHosts: test.bootHosts});
  1021. var filteredData = c.filterBootHosts(test.data);
  1022. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1023. });
  1024. });
  1025. });
  1026. describe('#hostWarningsPopup', function () {
  1027. beforeEach(function () {
  1028. sinon.spy(App.ModalPopup, 'show');
  1029. sinon.stub(c, 'rerunChecks', Em.K);
  1030. });
  1031. afterEach(function () {
  1032. App.ModalPopup.show.restore();
  1033. c.rerunChecks.restore();
  1034. });
  1035. it('should show App.ModalPopup', function () {
  1036. c.hostWarningsPopup();
  1037. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1038. });
  1039. it('should clear checksUpdateStatus on primary', function () {
  1040. c.set('checksUpdateStatus', 'not null value');
  1041. c.hostWarningsPopup().onPrimary();
  1042. expect(c.get('checksUpdateStatus')).to.be.null;
  1043. });
  1044. it('should clear checksUpdateStatus on close', function () {
  1045. c.set('checksUpdateStatus', 'not null value');
  1046. c.hostWarningsPopup().onClose();
  1047. expect(c.get('checksUpdateStatus')).to.be.null;
  1048. });
  1049. it('should rerunChecks onSecondary', function () {
  1050. c.hostWarningsPopup().onSecondary();
  1051. expect(c.rerunChecks.calledOnce).to.equal(true);
  1052. });
  1053. });
  1054. describe('#registeredHostsPopup', function () {
  1055. beforeEach(function () {
  1056. sinon.spy(App.ModalPopup, 'show');
  1057. });
  1058. afterEach(function () {
  1059. App.ModalPopup.show.restore();
  1060. });
  1061. it('should show App.ModalPopup', function () {
  1062. c.registeredHostsPopup();
  1063. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1064. });
  1065. });
  1066. describe('#parseHostCheckWarnings', function () {
  1067. beforeEach(function () {
  1068. sinon.stub(c, 'filterHostsData', function (k) {
  1069. return k;
  1070. });
  1071. });
  1072. afterEach(function () {
  1073. c.filterHostsData.restore();
  1074. });
  1075. it('no warnings if last_agent_env isn\'t specified', function () {
  1076. c.set('warnings', [
  1077. {}
  1078. ]);
  1079. c.set('warningsByHost', [
  1080. {},
  1081. {}
  1082. ]);
  1083. c.parseHostCheckWarnings({tasks: [
  1084. {Tasks: {host_name: 'c1'}}
  1085. ]});
  1086. expect(c.get('warnings')).to.eql([]);
  1087. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1088. });
  1089. Em.A([
  1090. {
  1091. m: 'parse stackFoldersAndFiles',
  1092. tests: Em.A([
  1093. {
  1094. tasks: [
  1095. {Tasks: {host_name: 'c1',
  1096. structured_out:{last_agent_env_check: {stackFoldersAndFiles: []}}
  1097. }
  1098. }
  1099. ],
  1100. m: 'empty stackFoldersAndFiles',
  1101. e: {
  1102. warnings: [],
  1103. warningsByHost: [0]
  1104. }
  1105. },
  1106. {
  1107. tasks: [
  1108. {Tasks: {host_name: 'c1',
  1109. structured_out: {last_agent_env_check: {stackFoldersAndFiles: [{name: 'n1'}]}}
  1110. }
  1111. }
  1112. ],
  1113. m: 'not empty stackFoldersAndFiles',
  1114. e: {
  1115. warnings: [
  1116. {
  1117. name: 'n1',
  1118. hosts: ['c1'],
  1119. onSingleHost: true,
  1120. category: 'fileFolders'
  1121. }
  1122. ],
  1123. warningsByHost: [1]
  1124. }
  1125. },
  1126. {
  1127. tasks: [
  1128. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {stackFoldersAndFiles: [
  1129. {name: 'n1'}
  1130. ]}}}},
  1131. {Tasks: {host_name: 'c2', structured_out: {last_agent_env_check: {stackFoldersAndFiles: [
  1132. {name: 'n1'}
  1133. ]}}}}
  1134. ],
  1135. m: 'not empty stackFoldersAndFiles on two hosts',
  1136. e: {
  1137. warnings: [
  1138. {
  1139. name: 'n1',
  1140. hosts: ['c1', 'c2'],
  1141. onSingleHost: false,
  1142. category: 'fileFolders'
  1143. }
  1144. ],
  1145. warningsByHost: [1]
  1146. }
  1147. }
  1148. ])
  1149. },
  1150. {
  1151. m: 'parse hostHealth.liveServices',
  1152. tests: Em.A([
  1153. {
  1154. tasks: [
  1155. {Tasks: {host_name: 'c1', structured_out: {last_agent_env_check: {hostHealth: []}}}}
  1156. ],
  1157. m: 'empty hostHealth',
  1158. e: {
  1159. warnings: [],
  1160. warningsByHost: [0]
  1161. }
  1162. },
  1163. {
  1164. tasks: [
  1165. {Tasks: {host_name: 'c1', structured_out: {last_agent_env_check: {hostHealth: {liveServices: []}}}}}
  1166. ],
  1167. m: 'empty liveServices',
  1168. e: {
  1169. warnings: [],
  1170. warningsByHost: [0]
  1171. }
  1172. },
  1173. {
  1174. tasks: [
  1175. {Tasks: {host_name: 'c1',
  1176. structured_out: {last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1177. }
  1178. }
  1179. ],
  1180. m: 'not empty hostHealth.liveServices',
  1181. e: {
  1182. warnings: [
  1183. {
  1184. name: 'n1',
  1185. hosts: ['c1'],
  1186. onSingleHost: true,
  1187. category: 'services'
  1188. }
  1189. ],
  1190. warningsByHost: [1]
  1191. }
  1192. },
  1193. {
  1194. tasks: [
  1195. {Tasks: {host_name: 'c1',
  1196. structured_out:{last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1197. }
  1198. },
  1199. {Tasks: {host_name: 'c2',
  1200. structured_out:{last_agent_env_check: {hostHealth: {liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}
  1201. }
  1202. }
  1203. ],
  1204. m: 'not empty hostHealth.liveServices on two hosts',
  1205. e: {
  1206. warnings: [
  1207. {
  1208. name: 'n1',
  1209. hosts: ['c1', 'c2'],
  1210. onSingleHost: false,
  1211. category: 'services'
  1212. }
  1213. ],
  1214. warningsByHost: [1, 1]
  1215. }
  1216. }
  1217. ])
  1218. },
  1219. {
  1220. m: 'parse existingUsers',
  1221. tests: Em.A([
  1222. {
  1223. tasks: [
  1224. {Tasks: {host_name: 'c1',
  1225. structured_out: {last_agent_env_check: {existingUsers: []}}
  1226. }
  1227. }
  1228. ],
  1229. m: 'empty existingUsers',
  1230. e: {
  1231. warnings: [],
  1232. warningsByHost: [0]
  1233. }
  1234. },
  1235. {
  1236. tasks: [
  1237. {Tasks: {host_name: 'c1',
  1238. structured_out: {last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1239. }
  1240. }
  1241. ],
  1242. m: 'not empty existingUsers',
  1243. e: {
  1244. warnings: [
  1245. {
  1246. name: 'n1',
  1247. hosts: ['c1'],
  1248. onSingleHost: true,
  1249. category: 'users'
  1250. }
  1251. ],
  1252. warningsByHost: [1]
  1253. }
  1254. },
  1255. {
  1256. tasks: [
  1257. {Tasks: {host_name: 'c1',
  1258. structured_out:{last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1259. }
  1260. },
  1261. {Tasks: {host_name: 'c2',
  1262. structured_out:{last_agent_env_check: {existingUsers: [{name: 'n1'}]}}
  1263. }
  1264. }
  1265. ],
  1266. m: 'not empty existingUsers on two hosts',
  1267. e: {
  1268. warnings: [
  1269. {
  1270. name: 'n1',
  1271. hosts: ['c1', 'c2'],
  1272. onSingleHost: false,
  1273. category: 'users'
  1274. }
  1275. ],
  1276. warningsByHost: [1, 1]
  1277. }
  1278. }
  1279. ])
  1280. },
  1281. {
  1282. m: 'parse alternatives',
  1283. tests: Em.A([
  1284. {
  1285. tasks: [
  1286. {Tasks: {host_name: 'c1',
  1287. structured_out:{last_agent_env_check: {alternatives: []}}
  1288. }
  1289. }
  1290. ],
  1291. m: 'empty alternatives',
  1292. e: {
  1293. warnings: [],
  1294. warningsByHost: [0]
  1295. }
  1296. },
  1297. {
  1298. tasks: [
  1299. {Tasks: {host_name: 'c1',
  1300. structured_out: {last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1301. }
  1302. }
  1303. ],
  1304. m: 'not empty alternatives',
  1305. e: {
  1306. warnings: [
  1307. {
  1308. name: 'n1',
  1309. hosts: ['c1'],
  1310. onSingleHost: true,
  1311. category: 'alternatives'
  1312. }
  1313. ],
  1314. warningsByHost: [1]
  1315. }
  1316. },
  1317. {
  1318. tasks: [
  1319. {Tasks: {host_name: 'c1',
  1320. structured_out:{last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1321. }
  1322. },
  1323. {Tasks: {host_name: 'c2',
  1324. structured_out:{last_agent_env_check: {alternatives: [{name: 'n1'}]}}
  1325. }
  1326. }
  1327. ],
  1328. m: 'not empty alternatives on two hosts',
  1329. e: {
  1330. warnings: [
  1331. {
  1332. name: 'n1',
  1333. hosts: ['c1', 'c2'],
  1334. onSingleHost: false,
  1335. category: 'alternatives'
  1336. }
  1337. ],
  1338. warningsByHost: [1, 1]
  1339. }
  1340. }
  1341. ])
  1342. },
  1343. {
  1344. m: 'parse hostHealth.activeJavaProcs',
  1345. tests: Em.A([
  1346. {
  1347. tasks: [
  1348. {Tasks: {host_name: 'c1',
  1349. structured_out:{last_agent_env_check: {hostHealth: [], javaProcs: []}}
  1350. }
  1351. }
  1352. ],
  1353. m: 'empty hostHealth',
  1354. e: {
  1355. warnings: [],
  1356. warningsByHost: [0]
  1357. }
  1358. },
  1359. {
  1360. tasks: [
  1361. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: []}}}}}
  1362. ],
  1363. m: 'empty activeJavaProcs',
  1364. e: {
  1365. warnings: [],
  1366. warningsByHost: [0]
  1367. }
  1368. },
  1369. {
  1370. tasks: [
  1371. {Tasks: {host_name: 'c1',
  1372. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1373. }
  1374. }
  1375. ],
  1376. m: 'not empty hostHealth.activeJavaProcs',
  1377. e: {
  1378. warnings: [
  1379. {
  1380. pid: 'n1',
  1381. hosts: ['c1'],
  1382. onSingleHost: true,
  1383. category: 'processes'
  1384. }
  1385. ],
  1386. warningsByHost: [1]
  1387. }
  1388. },
  1389. {
  1390. tasks: [
  1391. {Tasks: {host_name: 'c1',
  1392. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1393. }
  1394. },
  1395. {Tasks: {host_name: 'c2',
  1396. structured_out:{last_agent_env_check: {hostHealth: {activeJavaProcs: [{pid: 'n1', command: ''}]}}}
  1397. }
  1398. }
  1399. ],
  1400. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1401. e: {
  1402. warnings: [
  1403. {
  1404. pid: 'n1',
  1405. hosts: ['c1', 'c2'],
  1406. onSingleHost: false,
  1407. category: 'processes'
  1408. }
  1409. ],
  1410. warningsByHost: [1, 1]
  1411. }
  1412. }
  1413. ])
  1414. }
  1415. ]).forEach(function (category) {
  1416. describe(category.m, function () {
  1417. category.tests.forEach(function (test) {
  1418. describe(test.m, function () {
  1419. beforeEach(function () {
  1420. c.parseHostCheckWarnings({tasks: test.tasks});
  1421. });
  1422. it('warnings count is valid', function () {
  1423. expect(c.get('warnings.length')).to.be.equal(test.e.warnings.length);
  1424. });
  1425. test.e.warnings.forEach(function (warning, index) {
  1426. Object.keys(warning).forEach(function (warningKey) {
  1427. it('warning #' + (index + 1) + ' key: ' + warningKey, function () {
  1428. expect(c.get('warnings')[index][warningKey]).to.be.eql(warning[warningKey]);
  1429. });
  1430. });
  1431. });
  1432. Object.keys(test.e.warningsByHost).forEach(function (warningByHostKey, index) {
  1433. it ('warningsByHost #' + (index + 1), function () {
  1434. expect(c.get('warningsByHost')[index].warnings.length).to.equal(test.e.warningsByHost[warningByHostKey]);
  1435. });
  1436. });
  1437. });
  1438. });
  1439. });
  1440. });
  1441. it('should parse umask warnings', function () {
  1442. var tasks = [
  1443. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {umask: 24}}}},
  1444. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {umask: 1}}}}
  1445. ];
  1446. c.parseHostCheckWarnings({tasks: tasks});
  1447. var warnings = c.get('warnings');
  1448. expect(warnings.length).to.equal(1);
  1449. expect(warnings[0].hosts).to.eql(['c1']);
  1450. expect(warnings[0].hostsLong).to.eql(['c1']);
  1451. expect(warnings[0].onSingleHost).to.equal(true);
  1452. });
  1453. it('should parse umask warnings (2)', function () {
  1454. var tasks = [
  1455. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {umask: 24}}}},
  1456. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {umask: 25}}}}
  1457. ];
  1458. c.parseHostCheckWarnings({tasks: tasks});
  1459. var warnings = c.get('warnings');
  1460. expect(warnings.length).to.equal(2);
  1461. expect(warnings.mapProperty('hosts')).to.eql([
  1462. ['c1'],
  1463. ['c2']
  1464. ]);
  1465. });
  1466. it('should parse firewall warnings', function () {
  1467. var tasks = [
  1468. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}},
  1469. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {firewallRunning: false, firewallName: "iptables"}}}}
  1470. ];
  1471. c.parseHostCheckWarnings({tasks: tasks});
  1472. var warnings = c.get('warnings');
  1473. expect(warnings.length).to.equal(1);
  1474. expect(warnings[0].hosts).to.eql(['c1']);
  1475. expect(warnings[0].hostsLong).to.eql(['c1']);
  1476. expect(warnings[0].onSingleHost).to.equal(true);
  1477. });
  1478. it('should parse firewall warnings (2)', function () {
  1479. var tasks = [
  1480. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}},
  1481. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {firewallRunning: true, firewallName: "iptables"}}}}
  1482. ];
  1483. c.parseHostCheckWarnings({tasks: tasks});
  1484. var warnings = c.get('warnings');
  1485. expect(warnings.length).to.equal(1);
  1486. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1487. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1488. expect(warnings[0].onSingleHost).to.equal(false);
  1489. });
  1490. it('should parse reverseLookup warnings', function () {
  1491. var tasks = [
  1492. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: true}}}}
  1493. ];
  1494. c.parseHostCheckWarnings({tasks: tasks});
  1495. var warnings = c.get('warnings');
  1496. expect(warnings.length).to.equal(0);
  1497. });
  1498. it('should parse reverseLookup warnings (2)', function () {
  1499. var tasks = [
  1500. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: false}}}}
  1501. ];
  1502. c.parseHostCheckWarnings({tasks: tasks});
  1503. var warnings = c.get('warnings');
  1504. expect(warnings.length).to.equal(1);
  1505. expect(warnings[0].hosts).to.eql(['c1']);
  1506. expect(warnings[0].hostsLong).to.eql(['c1']);
  1507. expect(warnings[0].onSingleHost).to.equal(true);
  1508. });
  1509. it('should parse reverseLookup warnings (3)', function () {
  1510. var tasks = [
  1511. {Tasks: {host_name: 'c1', structured_out:{last_agent_env_check: {reverseLookup: false}}}},
  1512. {Tasks: {host_name: 'c2', structured_out:{last_agent_env_check: {reverseLookup: false}}}}
  1513. ];
  1514. c.parseHostCheckWarnings({tasks: tasks});
  1515. var warnings = c.get('warnings');
  1516. expect(warnings.length).to.equal(1);
  1517. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1518. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1519. expect(warnings[0].onSingleHost).to.equal(false);
  1520. });
  1521. });
  1522. describe('#parseWarnings', function () {
  1523. beforeEach(function () {
  1524. sinon.stub(c, 'filterBootHosts', function (k) {
  1525. return k;
  1526. });
  1527. });
  1528. afterEach(function () {
  1529. c.filterBootHosts.restore();
  1530. });
  1531. it('no warnings if last_agent_env isn\'t specified', function () {
  1532. c.set('warnings', [
  1533. {}
  1534. ]);
  1535. c.set('warningsByHost', [
  1536. {},
  1537. {}
  1538. ]);
  1539. c.parseWarnings({items: [
  1540. {Hosts: {host_name: 'c1'}}
  1541. ]});
  1542. expect(c.get('warnings')).to.eql([]);
  1543. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1544. });
  1545. Em.A([
  1546. {
  1547. m: 'parse stackFoldersAndFiles',
  1548. tests: Em.A([
  1549. {
  1550. items: [
  1551. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}
  1552. ],
  1553. m: 'empty stackFoldersAndFiles',
  1554. e: {
  1555. warnings: [],
  1556. warningsByHost: [0]
  1557. }
  1558. },
  1559. {
  1560. items: [
  1561. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1562. {name: 'n1'}
  1563. ]}}}
  1564. ],
  1565. m: 'not empty stackFoldersAndFiles',
  1566. e: {
  1567. warnings: [
  1568. {
  1569. name: 'n1',
  1570. hosts: ['c1'],
  1571. onSingleHost: true,
  1572. category: 'fileFolders'
  1573. }
  1574. ],
  1575. warningsByHost: [1]
  1576. }
  1577. },
  1578. {
  1579. items: [
  1580. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1581. {name: 'n1'}
  1582. ]}}},
  1583. {Hosts: {host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [
  1584. {name: 'n1'}
  1585. ]}}}
  1586. ],
  1587. m: 'not empty stackFoldersAndFiles on two hosts',
  1588. e: {
  1589. warnings: [
  1590. {
  1591. name: 'n1',
  1592. hosts: ['c1', 'c2'],
  1593. onSingleHost: false,
  1594. category: 'fileFolders'
  1595. }
  1596. ],
  1597. warningsByHost: [1]
  1598. }
  1599. }
  1600. ])
  1601. },
  1602. {
  1603. m: 'parse hostHealth.liveServices',
  1604. tests: Em.A([
  1605. {
  1606. items: [
  1607. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: []}}}
  1608. ],
  1609. m: 'empty hostHealth',
  1610. e: {
  1611. warnings: [],
  1612. warningsByHost: [0]
  1613. }
  1614. },
  1615. {
  1616. items: [
  1617. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: []}}}}
  1618. ],
  1619. m: 'empty liveServices',
  1620. e: {
  1621. warnings: [],
  1622. warningsByHost: [0]
  1623. }
  1624. },
  1625. {
  1626. items: [
  1627. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1628. {status: 'Unhealthy', name: 'n1'}
  1629. ]}}}}
  1630. ],
  1631. m: 'not empty hostHealth.liveServices',
  1632. e: {
  1633. warnings: [
  1634. {
  1635. name: 'n1',
  1636. hosts: ['c1'],
  1637. onSingleHost: true,
  1638. category: 'services'
  1639. }
  1640. ],
  1641. warningsByHost: [1]
  1642. }
  1643. },
  1644. {
  1645. items: [
  1646. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1647. {status: 'Unhealthy', name: 'n1'}
  1648. ]}}}},
  1649. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {liveServices: [
  1650. {status: 'Unhealthy', name: 'n1'}
  1651. ]}}}}
  1652. ],
  1653. m: 'not empty hostHealth.liveServices on two hosts',
  1654. e: {
  1655. warnings: [
  1656. {
  1657. name: 'n1',
  1658. hosts: ['c1', 'c2'],
  1659. onSingleHost: false,
  1660. category: 'services'
  1661. }
  1662. ],
  1663. warningsByHost: [1, 1]
  1664. }
  1665. }
  1666. ])
  1667. },
  1668. {
  1669. m: 'parse existingUsers',
  1670. tests: Em.A([
  1671. {
  1672. items: [
  1673. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: []}}}
  1674. ],
  1675. m: 'empty existingUsers',
  1676. e: {
  1677. warnings: [],
  1678. warningsByHost: [0]
  1679. }
  1680. },
  1681. {
  1682. items: [
  1683. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1684. {name: 'n1'}
  1685. ]}}}
  1686. ],
  1687. m: 'not empty existingUsers',
  1688. e: {
  1689. warnings: [
  1690. {
  1691. name: 'n1',
  1692. hosts: ['c1'],
  1693. onSingleHost: true,
  1694. category: 'users'
  1695. }
  1696. ],
  1697. warningsByHost: [1]
  1698. }
  1699. },
  1700. {
  1701. items: [
  1702. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1703. {name: 'n1'}
  1704. ]}}},
  1705. {Hosts: {host_name: 'c2', last_agent_env: {existingUsers: [
  1706. {name: 'n1'}
  1707. ]}}}
  1708. ],
  1709. m: 'not empty existingUsers on two hosts',
  1710. e: {
  1711. warnings: [
  1712. {
  1713. name: 'n1',
  1714. hosts: ['c1', 'c2'],
  1715. onSingleHost: false,
  1716. category: 'users'
  1717. }
  1718. ],
  1719. warningsByHost: [1, 1]
  1720. }
  1721. }
  1722. ])
  1723. },
  1724. {
  1725. m: 'parse alternatives',
  1726. tests: Em.A([
  1727. {
  1728. items: [
  1729. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: []}}}
  1730. ],
  1731. m: 'empty alternatives',
  1732. e: {
  1733. warnings: [],
  1734. warningsByHost: [0]
  1735. }
  1736. },
  1737. {
  1738. items: [
  1739. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1740. {name: 'n1'}
  1741. ]}}}
  1742. ],
  1743. m: 'not empty alternatives',
  1744. e: {
  1745. warnings: [
  1746. {
  1747. name: 'n1',
  1748. hosts: ['c1'],
  1749. onSingleHost: true,
  1750. category: 'alternatives'
  1751. }
  1752. ],
  1753. warningsByHost: [1]
  1754. }
  1755. },
  1756. {
  1757. items: [
  1758. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1759. {name: 'n1'}
  1760. ]}}},
  1761. {Hosts: {host_name: 'c2', last_agent_env: {alternatives: [
  1762. {name: 'n1'}
  1763. ]}}}
  1764. ],
  1765. m: 'not empty alternatives on two hosts',
  1766. e: {
  1767. warnings: [
  1768. {
  1769. name: 'n1',
  1770. hosts: ['c1', 'c2'],
  1771. onSingleHost: false,
  1772. category: 'alternatives'
  1773. }
  1774. ],
  1775. warningsByHost: [1, 1]
  1776. }
  1777. }
  1778. ])
  1779. },
  1780. {
  1781. m: 'parse hostHealth.activeJavaProcs',
  1782. tests: Em.A([
  1783. {
  1784. items: [
  1785. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}
  1786. ],
  1787. m: 'empty hostHealth',
  1788. e: {
  1789. warnings: [],
  1790. warningsByHost: [0]
  1791. }
  1792. },
  1793. {
  1794. items: [
  1795. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: []}}}}
  1796. ],
  1797. m: 'empty activeJavaProcs',
  1798. e: {
  1799. warnings: [],
  1800. warningsByHost: [0]
  1801. }
  1802. },
  1803. {
  1804. items: [
  1805. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1806. {pid: 'n1', command: ''}
  1807. ]}}}}
  1808. ],
  1809. m: 'not empty hostHealth.activeJavaProcs',
  1810. e: {
  1811. warnings: [
  1812. {
  1813. pid: 'n1',
  1814. hosts: ['c1'],
  1815. onSingleHost: true,
  1816. category: 'processes'
  1817. }
  1818. ],
  1819. warningsByHost: [1]
  1820. }
  1821. },
  1822. {
  1823. items: [
  1824. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1825. {pid: 'n1', command: ''}
  1826. ]}}}},
  1827. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {activeJavaProcs: [
  1828. {pid: 'n1', command: ''}
  1829. ]}}}}
  1830. ],
  1831. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1832. e: {
  1833. warnings: [
  1834. {
  1835. pid: 'n1',
  1836. hosts: ['c1', 'c2'],
  1837. onSingleHost: false,
  1838. category: 'processes'
  1839. }
  1840. ],
  1841. warningsByHost: [1, 1]
  1842. }
  1843. }
  1844. ])
  1845. }
  1846. ]).forEach(function (category) {
  1847. describe(category.m, function () {
  1848. category.tests.forEach(function (test) {
  1849. describe(test.m, function () {
  1850. beforeEach(function () {
  1851. c.parseWarnings({items: test.items});
  1852. });
  1853. test.e.warnings.forEach(function (warning, index) {
  1854. Object.keys(warning).forEach(function (warningKey) {
  1855. it('warning #' + (index + 1) + ' key: ' + warningKey, function () {
  1856. expect(c.get('warnings')[index][warningKey]).to.be.eql(warning[warningKey]);
  1857. });
  1858. });
  1859. });
  1860. Object.keys(test.e.warningsByHost).forEach(function (warningByHostKey, index) {
  1861. it ('warningsByHost #' + (index + 1), function () {
  1862. expect(c.get('warningsByHost')[index].warnings.length).to.equal(test.e.warningsByHost[warningByHostKey]);
  1863. });
  1864. });
  1865. });
  1866. });
  1867. });
  1868. });
  1869. it('should parse umask warnings', function () {
  1870. var items = [
  1871. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1872. {Hosts: {host_name: 'c2', last_agent_env: {umask: 1}}}
  1873. ];
  1874. c.parseWarnings({items: items});
  1875. var warnings = c.get('warnings');
  1876. expect(warnings.length).to.equal(1);
  1877. expect(warnings[0].hosts).to.eql(['c1']);
  1878. expect(warnings[0].hostsLong).to.eql(['c1']);
  1879. expect(warnings[0].onSingleHost).to.equal(true);
  1880. });
  1881. it('should parse umask warnings (2)', function () {
  1882. var items = [
  1883. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1884. {Hosts: {host_name: 'c2', last_agent_env: {umask: 25}}}
  1885. ];
  1886. c.parseWarnings({items: items});
  1887. var warnings = c.get('warnings');
  1888. expect(warnings.length).to.equal(2);
  1889. expect(warnings.mapProperty('hosts')).to.eql([
  1890. ['c1'],
  1891. ['c2']
  1892. ]);
  1893. });
  1894. it('should parse firewall warnings', function () {
  1895. var items = [
  1896. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1897. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: false, firewallName: "iptables"}}}
  1898. ];
  1899. c.parseWarnings({items: items});
  1900. var warnings = c.get('warnings');
  1901. expect(warnings.length).to.equal(1);
  1902. expect(warnings[0].hosts).to.eql(['c1']);
  1903. expect(warnings[0].hostsLong).to.eql(['c1']);
  1904. expect(warnings[0].onSingleHost).to.equal(true);
  1905. });
  1906. it('should parse firewall warnings (2)', function () {
  1907. var items = [
  1908. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1909. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}}
  1910. ];
  1911. c.parseWarnings({items: items});
  1912. var warnings = c.get('warnings');
  1913. expect(warnings.length).to.equal(1);
  1914. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1915. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1916. expect(warnings[0].onSingleHost).to.equal(false);
  1917. });
  1918. it('should parse reverseLookup warnings', function () {
  1919. var items = [
  1920. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1921. ];
  1922. c.parseWarnings({items: items});
  1923. var warnings = c.get('warnings');
  1924. expect(warnings.length).to.equal(0);
  1925. });
  1926. it('should parse reverseLookup warnings (2)', function () {
  1927. var items = [
  1928. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1929. ];
  1930. c.parseWarnings({items: items});
  1931. var warnings = c.get('warnings');
  1932. expect(warnings.length).to.equal(1);
  1933. expect(warnings[0].hosts).to.eql(['c1']);
  1934. expect(warnings[0].hostsLong).to.eql(['c1']);
  1935. expect(warnings[0].onSingleHost).to.equal(true);
  1936. });
  1937. it('should parse reverseLookup warnings (3)', function () {
  1938. var items = [
  1939. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1940. {Hosts: {host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1941. ];
  1942. c.parseWarnings({items: items});
  1943. var warnings = c.get('warnings');
  1944. expect(warnings.length).to.equal(1);
  1945. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1946. expect(warnings[0].hostsLong).to.eql(['c1', 'c2']);
  1947. expect(warnings[0].onSingleHost).to.equal(false);
  1948. });
  1949. });
  1950. describe('#navigateStep', function () {
  1951. beforeEach(function () {
  1952. sinon.stub(c, 'setupBootStrap', Em.K);
  1953. });
  1954. afterEach(function () {
  1955. c.setupBootStrap.restore();
  1956. });
  1957. Em.A([
  1958. {
  1959. isLoaded: true,
  1960. manualInstall: false,
  1961. bootStatus: false,
  1962. m: 'should call setupBootStrap',
  1963. e: true
  1964. },
  1965. {
  1966. isLoaded: true,
  1967. manualInstall: false,
  1968. bootStatus: true,
  1969. m: 'shouldn\'t call setupBootStrap (1)',
  1970. e: false
  1971. },
  1972. {
  1973. isLoaded: false,
  1974. manualInstall: false,
  1975. bootStatus: false,
  1976. m: 'shouldn\'t call setupBootStrap (2)',
  1977. e: false
  1978. },
  1979. {
  1980. isLoaded: false,
  1981. manualInstall: true,
  1982. bootStatus: false,
  1983. m: 'shouldn\'t call setupBootStrap (3)',
  1984. e: false
  1985. }
  1986. ]).forEach(function (test) {
  1987. it(test.m, function () {
  1988. c.reopen({
  1989. isLoaded: test.isLoaded,
  1990. content: {
  1991. installedHosts: [],
  1992. installOptions: {
  1993. manualInstall: test.manualInstall
  1994. }
  1995. },
  1996. wizardController: Em.Object.create({
  1997. getDBProperty: function () {
  1998. return test.bootStatus
  1999. }
  2000. })
  2001. });
  2002. c.navigateStep();
  2003. if (test.e) {
  2004. expect(c.setupBootStrap.calledOnce).to.equal(true);
  2005. }
  2006. else {
  2007. expect(c.setupBootStrap.called).to.equal(false);
  2008. }
  2009. });
  2010. });
  2011. describe('should start registration', function () {
  2012. beforeEach(function () {
  2013. c.reopen({
  2014. isLoaded: true,
  2015. hosts: [
  2016. {},
  2017. {},
  2018. {}
  2019. ],
  2020. content: {
  2021. installedHosts: [],
  2022. installOptions: {
  2023. manualInstall: true
  2024. }
  2025. },
  2026. setRegistrationInProgress: Em.K,
  2027. startRegistration: Em.K
  2028. });
  2029. sinon.spy(c, 'startRegistration');
  2030. c.navigateStep();
  2031. });
  2032. afterEach(function () {
  2033. c.startRegistration.restore();
  2034. });
  2035. it('startRegistration is called once', function () {
  2036. expect(c.startRegistration.calledOnce).to.equal(true);
  2037. });
  2038. it('all hosts are bootHosts', function () {
  2039. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  2040. });
  2041. it('registrationStartedAt is null', function () {
  2042. expect(c.get('registrationStartedAt')).to.be.null;
  2043. });
  2044. });
  2045. });
  2046. describe('#setupBootStrap', function () {
  2047. var cases = [
  2048. {
  2049. customizeAgentUserAccount: true,
  2050. userRunAs: 'user',
  2051. title: 'Ambari Agent user account customize enabled'
  2052. },
  2053. {
  2054. customizeAgentUserAccount: false,
  2055. userRunAs: 'root',
  2056. title: 'Ambari Agent user account customize disabled'
  2057. }
  2058. ],
  2059. controller = App.WizardStep3Controller.create({
  2060. content: {
  2061. installOptions: {
  2062. sshKey: 'key',
  2063. sshUser: 'root',
  2064. sshPort: '123',
  2065. agentUser: 'user'
  2066. },
  2067. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } },
  2068. controllerName: 'installerController'
  2069. }
  2070. });
  2071. beforeEach(function () {
  2072. sinon.stub(App.router.get('installerController'), 'launchBootstrap', Em.K);
  2073. this.mock = sinon.stub(App, 'get');
  2074. });
  2075. afterEach(function () {
  2076. App.router.get('installerController').launchBootstrap.restore();
  2077. this.mock.restore();
  2078. });
  2079. cases.forEach(function (item) {
  2080. it(item.title, function () {
  2081. this.mock.withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  2082. controller.setupBootStrap();
  2083. expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
  2084. verbose: true,
  2085. sshKey: 'key',
  2086. hosts: ['host0', 'host1'],
  2087. user: 'root',
  2088. sshPort: '123',
  2089. userRunAs: item.userRunAs
  2090. }));
  2091. });
  2092. });
  2093. });
  2094. describe('#checkHostDiskSpace', function () {
  2095. Em.A([
  2096. {
  2097. diskInfo: [
  2098. {
  2099. available: App.minDiskSpace * 1024 * 1024 - 1024,
  2100. mountpoint: '/'
  2101. }
  2102. ],
  2103. m: 'available less than App.minDiskSpace',
  2104. e: false
  2105. },
  2106. {
  2107. diskInfo: [
  2108. {
  2109. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  2110. mountpoint: '/usr'
  2111. }
  2112. ],
  2113. m: 'available less than App.minDiskSpaceUsrLib (1)',
  2114. e: false
  2115. },
  2116. {
  2117. diskInfo: [
  2118. {
  2119. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  2120. mountpoint: '/usr/lib'
  2121. }
  2122. ],
  2123. m: 'available less than App.minDiskSpaceUsrLib (2)',
  2124. e: false
  2125. },
  2126. {
  2127. diskInfo: [
  2128. {
  2129. available: App.minDiskSpace * 1024 * 1024 + 1024,
  2130. mountpoint: '/'
  2131. }
  2132. ],
  2133. m: 'available greater than App.minDiskSpace',
  2134. e: true
  2135. },
  2136. {
  2137. diskInfo: [
  2138. {
  2139. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2140. mountpoint: '/usr'
  2141. }
  2142. ],
  2143. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  2144. e: true
  2145. },
  2146. {
  2147. diskInfo: [
  2148. {
  2149. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2150. mountpoint: '/usr/lib'
  2151. }
  2152. ],
  2153. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  2154. e: true
  2155. },
  2156. {
  2157. diskInfo: [
  2158. {
  2159. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  2160. mountpoint: '/home/tdk'
  2161. }
  2162. ],
  2163. m: 'mount point without free space checks',
  2164. e: true
  2165. }
  2166. ]).forEach(function (test) {
  2167. it(test.m, function () {
  2168. var r = c.checkHostDiskSpace('', test.diskInfo);
  2169. expect(Em.isEmpty(r)).to.equal(test.e);
  2170. });
  2171. });
  2172. });
  2173. describe('#checkHostOSType', function () {
  2174. it('should return empty string if no stacks provided', function () {
  2175. c.reopen({content: {stacks: null}});
  2176. expect(c.checkHostOSType()).to.equal('');
  2177. });
  2178. it('os type is valid', function () {
  2179. var osType = 'redhat6';
  2180. c.reopen({
  2181. content: {
  2182. stacks: [
  2183. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  2184. ]
  2185. }
  2186. });
  2187. expect(c.checkHostOSType(osType, '')).to.equal('');
  2188. });
  2189. it('os type is invalid', function () {
  2190. var osType = 'os2';
  2191. c.reopen({
  2192. content: {
  2193. stacks: [
  2194. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  2195. ]
  2196. }
  2197. });
  2198. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  2199. });
  2200. });
  2201. describe('#getHostInfoSuccessCallback', function () {
  2202. var jsonData = {items: [
  2203. {Hosts: {host_name: 'h1'}}
  2204. ]};
  2205. var skipBootstrap = false;
  2206. beforeEach(function () {
  2207. sinon.stub(c, 'parseWarnings', Em.K);
  2208. sinon.stub(c, 'stopRegistration', Em.K);
  2209. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  2210. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  2211. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  2212. sinon.stub(App, 'get', function (k) {
  2213. if ('skipBootstrap' === k) return skipBootstrap;
  2214. return Em.get(App, k);
  2215. });
  2216. c.reopen({
  2217. bootHosts: [Em.Object.create({name: 'h1'})]
  2218. });
  2219. sinon.stub(c, 'checkHostOSType', function () {
  2220. return 'not_null_value';
  2221. });
  2222. });
  2223. afterEach(function () {
  2224. c.parseWarnings.restore();
  2225. c.stopRegistration.restore();
  2226. c.checkHostDiskSpace.restore();
  2227. c._setHostDataFromLoadedHostInfo.restore();
  2228. c._setHostDataWithSkipBootstrap.restore();
  2229. App.get.restore();
  2230. c.checkHostOSType.restore();
  2231. });
  2232. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function () {
  2233. skipBootstrap = true;
  2234. c.getHostInfoSuccessCallback(jsonData);
  2235. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  2236. });
  2237. it('should add repo warnings', function () {
  2238. skipBootstrap = false;
  2239. c.getHostInfoSuccessCallback(jsonData);
  2240. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  2241. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  2242. });
  2243. it('should add disk warnings', function () {
  2244. skipBootstrap = false;
  2245. c.getHostInfoSuccessCallback(jsonData);
  2246. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  2247. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  2248. });
  2249. });
  2250. describe('#_setHostDataWithSkipBootstrap', function () {
  2251. it('should set mock-data', function () {
  2252. var host = Em.Object.create({});
  2253. c._setHostDataWithSkipBootstrap(host);
  2254. expect(host.get('cpu')).to.equal(2);
  2255. expect(host.get('memory')).to.equal('2000000.00');
  2256. expect(host.get('disk_info.length')).to.equal(4);
  2257. });
  2258. });
  2259. describe('#_setHostDataFromLoadedHostInfo', function () {
  2260. var host;
  2261. beforeEach(function () {
  2262. host = Em.Object.create();
  2263. var hostInfo = {
  2264. Hosts: {
  2265. cpu_count: 2,
  2266. total_mem: 12345,
  2267. os_type: 't1',
  2268. os_arch: 'os1',
  2269. os_family: 'osf1',
  2270. ip: '0.0.0.0',
  2271. disk_info: [
  2272. {mountpoint: '/boot'},
  2273. {mountpoint: '/usr'},
  2274. {mountpoint: '/no-boot'},
  2275. {mountpoint: '/boot'}
  2276. ]
  2277. }
  2278. };
  2279. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  2280. });
  2281. it('cpu', function () {
  2282. expect(host.get('cpu')).to.equal(2);
  2283. });
  2284. it('os_type', function () {
  2285. expect(host.get('os_type')).to.equal('t1');
  2286. });
  2287. it('os_arch', function () {
  2288. expect(host.get('os_arch')).to.equal('os1');
  2289. });
  2290. it('os_family', function () {
  2291. expect(host.get('os_family')).to.equal('osf1');
  2292. });
  2293. it('ip', function () {
  2294. expect(host.get('ip')).to.equal('0.0.0.0');
  2295. });
  2296. it('memory', function () {
  2297. expect(host.get('memory')).to.equal('12345.00');
  2298. });
  2299. it('disk_info.length', function () {
  2300. expect(host.get('disk_info.length')).to.equal(2);
  2301. });
  2302. });
  2303. describe('#getJDKNameSuccessCallback', function () {
  2304. it('should set proper data to controller properties', function () {
  2305. var expected = {
  2306. name: 'name',
  2307. home: 'home',
  2308. location: 'location'
  2309. },
  2310. data = {
  2311. RootServiceComponents: {
  2312. properties: {
  2313. 'jdk.name': expected.name,
  2314. 'java.home': expected.home,
  2315. 'jdk_location': expected.location
  2316. }
  2317. }
  2318. };
  2319. c.getJDKNameSuccessCallback(data);
  2320. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  2321. expect(c.get('jdkLocation')).to.equal(expected.location);
  2322. expect(c.get('javaHome')).to.equal(expected.home);
  2323. });
  2324. });
  2325. describe('#doCheckJDK', function () {
  2326. it('should do request to the ambari-server', function () {
  2327. var bootHosts = [
  2328. Em.Object.create({name: 'n1', bootStatus: 'REGISTERED'}),
  2329. Em.Object.create({name: 'n2', bootStatus: 'REGISTERED'})
  2330. ],
  2331. javaHome = '/java',
  2332. jdkLocation = '/jdk';
  2333. c.reopen({
  2334. bootHosts: bootHosts,
  2335. javaHome: javaHome,
  2336. jdkLocation: jdkLocation
  2337. });
  2338. c.doCheckJDK();
  2339. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check');
  2340. expect(args).exists;
  2341. });
  2342. });
  2343. describe('#doCheckJDKsuccessCallback', function () {
  2344. it('should set jdkRequestIndex if data provided', function () {
  2345. var data = {
  2346. href: '/a/b/c'
  2347. },
  2348. expected = 'c';
  2349. c.set('jdkRequestIndex', null);
  2350. c.doCheckJDKsuccessCallback(data);
  2351. expect(c.get('jdkRequestIndex')).to.equal(expected);
  2352. });
  2353. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function () {
  2354. var data = null,
  2355. expected = true;
  2356. c.set('isJDKWarningsLoaded', false);
  2357. c.set('jdkCategoryWarnings', {});
  2358. c.doCheckJDKsuccessCallback(data);
  2359. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  2360. });
  2361. it('should do request to ambari-server', function () {
  2362. var data = null,
  2363. jdkRequestIndex = 'jdkRequestIndex';
  2364. c.set('jdkRequestIndex', jdkRequestIndex);
  2365. c.set('jdkCategoryWarnings', null);
  2366. c.doCheckJDKsuccessCallback(data);
  2367. var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check.get_results');
  2368. expect(args).exists;
  2369. });
  2370. });
  2371. describe('#doCheckJDKerrorCallback', function () {
  2372. it('should set isJDKWarningsLoaded to true', function () {
  2373. c.set('isJDKWarningsLoaded', false);
  2374. c.doCheckJDKerrorCallback();
  2375. expect(c.get('isJDKWarningsLoaded')).to.be.true;
  2376. });
  2377. });
  2378. describe('#parseJDKCheckResults', function () {
  2379. beforeEach(function () {
  2380. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  2381. });
  2382. afterEach(function () {
  2383. c.doCheckJDKsuccessCallback.restore();
  2384. });
  2385. it('should set jdkCategoryWarnings to null if no data', function () {
  2386. var data = {Requests: {}};
  2387. c.set('jdkCategoryWarnings', {});
  2388. c.parseJDKCheckResults(data);
  2389. expect(c.get('jdkCategoryWarnings')).to.be.null;
  2390. });
  2391. it('should parse warnings (1)', function () {
  2392. var data = {
  2393. Requests: {
  2394. end_time: 1
  2395. },
  2396. tasks: []
  2397. };
  2398. c.set('jdkCategoryWarnings', {});
  2399. c.parseJDKCheckResults(data);
  2400. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  2401. });
  2402. it('should parse warnings (2)', function () {
  2403. var data = {
  2404. Requests: {
  2405. end_time: 1
  2406. },
  2407. tasks: [
  2408. {
  2409. Tasks: {
  2410. host_name: 'h1',
  2411. structured_out: {
  2412. java_home_check: {
  2413. exit_code: 1
  2414. }
  2415. }
  2416. }
  2417. },
  2418. {
  2419. Tasks: {
  2420. host_name: 'h2',
  2421. structured_out: {
  2422. java_home_check: {
  2423. exit_code: 0
  2424. }
  2425. }
  2426. }
  2427. }
  2428. ]
  2429. };
  2430. c.set('jdkCategoryWarnings', {});
  2431. c.parseJDKCheckResults(data);
  2432. var result = c.get('jdkCategoryWarnings');
  2433. expect(result.length).to.equal(1);
  2434. expect(result[0].hostsNames).to.eql(['h1']);
  2435. });
  2436. });
  2437. describe('#getHostCheckTasksSuccess', function() {
  2438. beforeEach(function() {
  2439. sinon.stub(c, 'getHostInfo', Em.K);
  2440. sinon.stub(c, 'parseHostNameResolution', Em.K);
  2441. sinon.stub(c, 'getGeneralHostCheck', Em.K);
  2442. sinon.stub(c, 'getHostCheckTasks', Em.K);
  2443. });
  2444. afterEach(function() {
  2445. c.getHostInfo.restore();
  2446. c.parseHostNameResolution.restore();
  2447. c.getGeneralHostCheck.restore();
  2448. c.getHostCheckTasks.restore();
  2449. });
  2450. var dataInProgress = {
  2451. Requests: {
  2452. request_status: "IN_PROGRESS"
  2453. }
  2454. };
  2455. it('run getHostCheckTasks', function() {
  2456. c.getHostCheckTasksSuccess(dataInProgress);
  2457. expect(c.getHostCheckTasks.calledOnce).to.be.true;
  2458. });
  2459. var hostResolutionCheckComplete = {
  2460. Requests: {
  2461. request_status: "COMPLETED",
  2462. inputs: "host_resolution_check"
  2463. }
  2464. };
  2465. it('run parseHostNameResolution and getGeneralHostCheck', function() {
  2466. c.getHostCheckTasksSuccess(hostResolutionCheckComplete);
  2467. expect(c.parseHostNameResolution.calledWith(hostResolutionCheckComplete)).to.be.true;
  2468. expect(c.getGeneralHostCheck.calledOnce).to.be.true;
  2469. });
  2470. var lastAgentEnvCheckComplete = {
  2471. Requests: {
  2472. request_status: "COMPLETED",
  2473. inputs: "last_agent_env_check"
  2474. },
  2475. tasks: [
  2476. {
  2477. Tasks: {
  2478. host_name: 'h1',
  2479. structured_out: {
  2480. "installed_packages": [
  2481. {
  2482. "version": "b1",
  2483. "name": "n1",
  2484. "repoName": "r1"
  2485. },
  2486. {
  2487. "version": "b2",
  2488. "name": "n2",
  2489. "repoName": "r2"
  2490. }
  2491. ]
  2492. }
  2493. }
  2494. }
  2495. ]
  2496. };
  2497. it('run getHostInfo', function() {
  2498. c.getHostCheckTasksSuccess(lastAgentEnvCheckComplete);
  2499. expect(c.get('stopChecking')).to.be.true;
  2500. expect(c.getHostInfo.calledOnce).to.be.true;
  2501. expect(JSON.parse(JSON.stringify(c.get('hostsPackagesData')))).eql([
  2502. {
  2503. hostName: 'h1',
  2504. installedPackages: [
  2505. {
  2506. "version": "b1",
  2507. "name": "n1",
  2508. "repoName": "r1"
  2509. },
  2510. {
  2511. "version": "b2",
  2512. "name": "n2",
  2513. "repoName": "r2"
  2514. }
  2515. ]
  2516. }
  2517. ]);
  2518. });
  2519. });
  2520. describe('#getDataForCheckRequest', function() {
  2521. var tests = [
  2522. {
  2523. bootHosts: [
  2524. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2525. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2526. ],
  2527. addHosts: true,
  2528. rez: {
  2529. RequestInfo: {
  2530. "action": "check_host",
  2531. "context": "Check host",
  2532. "parameters": {
  2533. "check_execute_list": 'checkExecuteList',
  2534. "jdk_location" : "jdk_location",
  2535. "threshold": "20",
  2536. "hosts": "h1"
  2537. }
  2538. },
  2539. resource_filters: {
  2540. "hosts": "h1"
  2541. }
  2542. },
  2543. m: 'with add host param'
  2544. },
  2545. {
  2546. bootHosts: [
  2547. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2548. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2549. ],
  2550. addHosts: false,
  2551. rez: {
  2552. RequestInfo: {
  2553. "action": "check_host",
  2554. "context": "Check host",
  2555. "parameters": {
  2556. "check_execute_list": 'checkExecuteList',
  2557. "jdk_location" : "jdk_location",
  2558. "threshold": "20"
  2559. }
  2560. },
  2561. resource_filters: {
  2562. "hosts": "h1"
  2563. }
  2564. },
  2565. m: 'without add host param'
  2566. },
  2567. {
  2568. bootHosts: [
  2569. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h1'}),
  2570. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2571. ],
  2572. rez: null,
  2573. m: 'with all hosts failed'
  2574. }
  2575. ];
  2576. beforeEach(function() {
  2577. sinon.stub(App.get('router'), 'get' , function(p) {
  2578. return p === 'clusterController.ambariProperties.jdk_location' ? 'jdk_location' : Em.get(App.get('router'), p);
  2579. })
  2580. });
  2581. afterEach(function() {
  2582. App.get('router').get.restore();
  2583. });
  2584. tests.forEach(function(t) {
  2585. it(t.m, function() {
  2586. c.set('bootHosts', t.bootHosts);
  2587. expect(c.getDataForCheckRequest('checkExecuteList', t.addHosts)).to.be.eql(t.rez);
  2588. });
  2589. })
  2590. });
  2591. describe('#isBackDisabled', function () {
  2592. var cases = [
  2593. {
  2594. inputData: {
  2595. isRegistrationInProgress: true,
  2596. isWarningsLoaded: true,
  2597. isBootstrapFailed: true
  2598. },
  2599. isBackDisabled: false
  2600. },
  2601. {
  2602. inputData: {
  2603. isRegistrationInProgress: true,
  2604. isWarningsLoaded: false,
  2605. isBootstrapFailed: false
  2606. },
  2607. isBackDisabled: true
  2608. },
  2609. {
  2610. inputData: {
  2611. isRegistrationInProgress: true,
  2612. isWarningsLoaded: true,
  2613. isBootstrapFailed: false
  2614. },
  2615. isBackDisabled: true
  2616. },
  2617. {
  2618. inputData: {
  2619. isRegistrationInProgress: true,
  2620. isWarningsLoaded: false,
  2621. isBootstrapFailed: true
  2622. },
  2623. isBackDisabled: false
  2624. },
  2625. {
  2626. inputData: {
  2627. isRegistrationInProgress: false,
  2628. isWarningsLoaded: true,
  2629. isBootstrapFailed: true
  2630. },
  2631. isBackDisabled: false
  2632. },
  2633. {
  2634. inputData: {
  2635. isRegistrationInProgress: false,
  2636. isWarningsLoaded: false,
  2637. isBootstrapFailed: false
  2638. },
  2639. isBackDisabled: true
  2640. },
  2641. {
  2642. inputData: {
  2643. isRegistrationInProgress: false,
  2644. isWarningsLoaded: true,
  2645. isBootstrapFailed: false
  2646. },
  2647. isBackDisabled: false
  2648. },
  2649. {
  2650. inputData: {
  2651. isRegistrationInProgress: false,
  2652. isWarningsLoaded: false,
  2653. isBootstrapFailed: true
  2654. },
  2655. isBackDisabled: false
  2656. }
  2657. ];
  2658. cases.forEach(function (item) {
  2659. var title = Em.keys(item.inputData).map(function (key) {
  2660. return key + ':' + item.inputData[key];
  2661. }).join(', ');
  2662. it(title, function () {
  2663. c.setProperties({
  2664. isRegistrationInProgress: item.inputData.isRegistrationInProgress,
  2665. isBootstrapFailed: item.inputData.isBootstrapFailed
  2666. });
  2667. c.reopen({
  2668. isWarningsLoaded: item.inputData.isWarningsLoaded
  2669. });
  2670. expect(c.get('isBackDisabled')).to.equal(item.isBackDisabled);
  2671. });
  2672. });
  2673. });
  2674. describe('#hostsInCluster', function () {
  2675. var hosts = {
  2676. host1: {isInstalled: true},
  2677. host2: {isInstalled: false},
  2678. host3: {isInstalled: true},
  2679. host4: {isInstalled: false}
  2680. };
  2681. beforeEach(function () {
  2682. c.set('content', {hosts: hosts});
  2683. c.propertyDidChange('hostsInCluster');
  2684. });
  2685. it('should take only installed hosts', function () {
  2686. expect(c.get('hostsInCluster')).to.be.eql(['host1', 'host3']);
  2687. });
  2688. });
  2689. describe('#filterHostsData', function () {
  2690. var bootHosts = [
  2691. Em.Object.create({name: 'c1'}),
  2692. Em.Object.create({name: 'c2'}),
  2693. Em.Object.create({name: 'c3'})
  2694. ];
  2695. var data = {
  2696. href: 'abc',
  2697. tasks: [
  2698. {Tasks: {host_name: 'c1'}},
  2699. {Tasks: {host_name: 'c2'}},
  2700. {Tasks: {host_name: 'c3'}},
  2701. {Tasks: {host_name: 'c2'}},
  2702. {Tasks: {host_name: 'c3'}},
  2703. {Tasks: {host_name: 'c4'}}
  2704. ]
  2705. };
  2706. beforeEach(function() {
  2707. c.set('bootHosts', bootHosts);
  2708. this.result = c.filterHostsData(data);
  2709. });
  2710. it('href is valid', function () {
  2711. expect(this.result.href).to.be.equal('abc');
  2712. });
  2713. it('tasks are valid', function () {
  2714. expect(this.result.tasks).to.be.eql([
  2715. {Tasks: {host_name: 'c1'}},
  2716. {Tasks: {host_name: 'c2'}},
  2717. {Tasks: {host_name: 'c3'}},
  2718. {Tasks: {host_name: 'c2'}},
  2719. {Tasks: {host_name: 'c3'}}
  2720. ]);
  2721. });
  2722. });
  2723. describe('#parseHostNameResolution', function () {
  2724. var data = {
  2725. tasks: [
  2726. {Tasks: {status: 'COMPLETED', host_name: 'h1', structured_out: {host_resolution_check: {failed_count: 2, failures: [{host: 'h2'}, {host: 'h3'}]}}}},
  2727. {Tasks: {status: 'COMPLETED', host_name: 'h4', structured_out: {host_resolution_check: {failed_count: 2, failures: [{host: 'h5'}, {host: 'h6'}]}}}},
  2728. {Tasks: {status: 'COMPLETED', host_name: 'h7', structured_out: {host_resolution_check: {failed_count: 1, failures: [{host: 'h8'}]}}}}
  2729. ]
  2730. };
  2731. var hostCheckWarnings = [];
  2732. beforeEach(function () {
  2733. c.set('hostCheckWarnings', hostCheckWarnings);
  2734. c.parseHostNameResolution(data);
  2735. this.warnings = c.get('hostCheckWarnings').findProperty('name', Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.error'));
  2736. });
  2737. it('Host check warnings for hostname resolutions exist', function () {
  2738. expect(this.warnings).to.exist;
  2739. });
  2740. it('hostsNames are ["h1", "h4", "h7"]', function () {
  2741. expect(this.warnings.hostsNames.toArray()).to.be.eql(['h1', 'h4', 'h7']);
  2742. });
  2743. it('warning appears on many hosts', function () {
  2744. expect(this.warnings.onSingleHost).to.be.false;
  2745. });
  2746. it('validation context for hosts is valid', function () {
  2747. var hosts = this.warnings.hosts;
  2748. var expected = [
  2749. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h1', 2 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.hosts')),
  2750. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h4', 2 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.hosts')),
  2751. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h7', 1 + ' ' + Em.I18n.t('installer.step3.hostWarningsPopup.host'))
  2752. ];
  2753. expect(hosts).to.be.eql(expected);
  2754. });
  2755. it('validation context (long) for hosts is valid', function () {
  2756. var hostsLong = this.warnings.hostsLong;
  2757. var expected = [
  2758. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h1', 'h2, h3'),
  2759. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h4', 'h5, h6'),
  2760. Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.context').format('h7', 'h8')
  2761. ];
  2762. expect(hostsLong).to.be.eql(expected);
  2763. });
  2764. });
  2765. describe('#getHostCheckTasksError', function () {
  2766. beforeEach(function () {
  2767. c.set('stopChecking', false);
  2768. });
  2769. it('should set `stopChecking` to true', function () {
  2770. c.getHostCheckTasksError();
  2771. expect(c.get('stopChecking')).to.be.true;
  2772. });
  2773. });
  2774. describe('#closeReloadPopupOnExit', function () {
  2775. var cases = [
  2776. {
  2777. stopBootstrap: true,
  2778. closeReloadPopupCallCount: 1,
  2779. title: 'bootstrap should be stopped'
  2780. },
  2781. {
  2782. stopBootstrap: false,
  2783. closeReloadPopupCallCount: 0,
  2784. title: 'bootstrap should not be stopped'
  2785. }
  2786. ];
  2787. beforeEach(function () {
  2788. sinon.stub(c, 'closeReloadPopup', Em.K);
  2789. });
  2790. afterEach(function () {
  2791. c.closeReloadPopup.restore();
  2792. });
  2793. cases.forEach(function (item) {
  2794. it(item.title, function () {
  2795. if (c.get('stopBootstrap') === item.stopBootstrap) {
  2796. c.propertyDidChange('stopBootstrap');
  2797. } else {
  2798. c.set('stopBootstrap', item.stopBootstrap);
  2799. }
  2800. expect(c.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
  2801. });
  2802. });
  2803. });
  2804. describe('#isNextButtonDisabled', function () {
  2805. var cases = [
  2806. {
  2807. btnClickInProgress: true,
  2808. isSubmitDisabled: true,
  2809. isNextButtonDisabled: true,
  2810. description: 'button clicked, submit disabled',
  2811. title: 'next button disabled'
  2812. },
  2813. {
  2814. btnClickInProgress: true,
  2815. isSubmitDisabled: false,
  2816. isNextButtonDisabled: true,
  2817. description: 'button clicked, submit not disabled',
  2818. title: 'next button disabled'
  2819. },
  2820. {
  2821. btnClickInProgress: false,
  2822. isSubmitDisabled: true,
  2823. isNextButtonDisabled: true,
  2824. description: 'no button clicked, submit disabled',
  2825. title: 'next button disabled'
  2826. },
  2827. {
  2828. btnClickInProgress: false,
  2829. isSubmitDisabled: false,
  2830. isNextButtonDisabled: false,
  2831. description: 'no button clicked, submit not disabled',
  2832. title: 'next button enabled'
  2833. }
  2834. ];
  2835. cases.forEach(function (item) {
  2836. describe(item.description, function () {
  2837. beforeEach(function () {
  2838. c.set('isSubmitDisabled', item.isSubmitDisabled);
  2839. sinon.stub(App, 'get').withArgs('router.btnClickInProgress').returns(item.btnClickInProgress);
  2840. c.propertyDidChange('isSubmitDisabled');
  2841. c.propertyDidChange('App.router.btnClickInProgress');
  2842. });
  2843. afterEach(function () {
  2844. App.get.restore();
  2845. });
  2846. it(item.title, function () {
  2847. expect(c.get('isNextButtonDisabled')).to.equal(item.isNextButtonDisabled);
  2848. });
  2849. });
  2850. });
  2851. });
  2852. describe('#isBackButtonDisabled', function () {
  2853. var cases = [
  2854. {
  2855. btnClickInProgress: true,
  2856. isBackDisabled: true,
  2857. isBackButtonDisabled: true,
  2858. description: 'button clicked, stepping back disabled',
  2859. title: 'back button disabled'
  2860. },
  2861. {
  2862. btnClickInProgress: true,
  2863. isBackDisabled: false,
  2864. isBackButtonDisabled: true,
  2865. description: 'button clicked, stepping back not disabled',
  2866. title: 'back button disabled'
  2867. },
  2868. {
  2869. btnClickInProgress: false,
  2870. isBackDisabled: true,
  2871. isBackButtonDisabled: true,
  2872. description: 'no button clicked, stepping back disabled',
  2873. title: 'back button disabled'
  2874. },
  2875. {
  2876. btnClickInProgress: false,
  2877. isBackDisabled: false,
  2878. isBackButtonDisabled: false,
  2879. description: 'no button clicked, stepping back not disabled',
  2880. title: 'back button enabled'
  2881. }
  2882. ];
  2883. cases.forEach(function (item) {
  2884. describe(item.description, function () {
  2885. beforeEach(function () {
  2886. c.reopen({
  2887. isBackDisabled: item.isBackDisabled
  2888. });
  2889. sinon.stub(App, 'get').withArgs('router.btnClickInProgress').returns(item.btnClickInProgress);
  2890. c.propertyDidChange('isBackDisabled');
  2891. c.propertyDidChange('App.router.btnClickInProgress');
  2892. });
  2893. afterEach(function () {
  2894. App.get.restore();
  2895. });
  2896. it(item.title, function () {
  2897. expect(c.get('isBackButtonDisabled')).to.equal(item.isBackButtonDisabled);
  2898. });
  2899. });
  2900. });
  2901. });
  2902. });