step3_test.js 90 KB

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