step3_test.js 88 KB

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