step3_test.js 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177
  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. });