step3_test.js 85 KB

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