step3_test.js 89 KB

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