step3_test.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  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. agentUser: 'user'
  481. },
  482. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } }
  483. }
  484. });
  485. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  486. controller.setupBootStrap();
  487. App.get.restore();
  488. expect(installer.launchBootstrap.firstCall.args[0]).to.equal(JSON.stringify({
  489. verbose: true,
  490. sshKey: 'key',
  491. hosts: ['host0', 'host1'],
  492. user: 'root',
  493. userRunAs: item.userRunAs
  494. }));
  495. });
  496. });
  497. });
  498. describe('#retryHost', function () {
  499. beforeEach(function () {
  500. sinon.spy(c, 'retryHosts');
  501. sinon.stub(App.router, 'get', function () {
  502. return {launchBootstrap: Em.K}
  503. });
  504. sinon.stub(c, 'doBootstrap', Em.K);
  505. });
  506. afterEach(function () {
  507. c.retryHosts.restore();
  508. App.router.get.restore();
  509. c.doBootstrap.restore();
  510. });
  511. it('should callretryHosts with array as arg', function () {
  512. var host = {n: 'c'};
  513. c.set('content', {installOptions: {}});
  514. c.retryHost(host);
  515. expect(c.retryHosts.calledWith([host])).to.equal(true);
  516. });
  517. });
  518. describe('#retrySelectedHosts', function () {
  519. beforeEach(function () {
  520. sinon.spy(c, 'retryHosts');
  521. sinon.stub(App.router, 'get', function () {
  522. return {launchBootstrap: Em.K}
  523. });
  524. sinon.stub(c, 'doBootstrap', Em.K);
  525. });
  526. afterEach(function () {
  527. c.retryHosts.restore();
  528. App.router.get.restore();
  529. c.doBootstrap.restore();
  530. });
  531. it('shouldn\'t do nothing if isRetryDisabled is true', function () {
  532. c.set('isRetryDisabled', true);
  533. c.retrySelectedHosts();
  534. expect(c.retryHosts.called).to.equal(false);
  535. });
  536. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function () {
  537. c.set('isRetryDisabled', false);
  538. c.set('bootHosts', Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]));
  539. c.retrySelectedHosts();
  540. expect(c.retryHosts.calledWith([
  541. {name: 'c1', bootStatus: 'RUNNING'}
  542. ]));
  543. expect(c.get('isRetryDisabled')).to.equal(true);
  544. });
  545. });
  546. describe('#startBootstrap', function () {
  547. beforeEach(function () {
  548. sinon.stub(c, 'doBootstrap', Em.K);
  549. });
  550. afterEach(function () {
  551. c.doBootstrap.restore();
  552. });
  553. it('should drop numPolls and registrationStartedAt', function () {
  554. c.set('numPolls', 123);
  555. c.set('registrationStartedAt', 1234);
  556. c.startBootstrap();
  557. expect(c.get('numPolls')).to.equal(0);
  558. expect(c.get('registrationStartedAt')).to.be.null;
  559. });
  560. it('should drop numPolls and registrationStartedAt', function () {
  561. c.set('hosts', Em.A([
  562. {name: 'c1'},
  563. {name: 'c2'}
  564. ]));
  565. c.startBootstrap();
  566. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1', 'c2']);
  567. });
  568. });
  569. describe('#setRegistrationInProgress', function () {
  570. var tests = Em.A([
  571. {
  572. bootHosts: [],
  573. isLoaded: false,
  574. e: true,
  575. m: 'no bootHosts and isLoaded is false'
  576. },
  577. {
  578. bootHosts: [],
  579. isLoaded: true,
  580. e: false,
  581. m: 'no bootHosts and isLoaded is true'
  582. },
  583. {
  584. bootHosts: [
  585. Em.Object.create({bootStatus: 'RUNNING'}),
  586. Em.Object.create({bootStatus: 'RUNNING'})
  587. ],
  588. isLoaded: true,
  589. e: true,
  590. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  591. },
  592. {
  593. bootHosts: [
  594. Em.Object.create({bootStatus: 'RUNNING'}),
  595. Em.Object.create({bootStatus: 'RUNNING'})
  596. ],
  597. isLoaded: false,
  598. e: true,
  599. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  600. },
  601. {
  602. bootHosts: [
  603. Em.Object.create({bootStatus: 'REGISTERED'}),
  604. Em.Object.create({bootStatus: 'RUNNING'})
  605. ],
  606. isLoaded: false,
  607. e: true,
  608. m: 'bootHosts with one REGISTERED and isLoaded is false'
  609. },
  610. {
  611. bootHosts: [
  612. Em.Object.create({bootStatus: 'FAILED'}),
  613. Em.Object.create({bootStatus: 'RUNNING'})
  614. ],
  615. isLoaded: false,
  616. e: true,
  617. m: 'bootHosts with one FAILED and isLoaded is false'
  618. },
  619. {
  620. bootHosts: [
  621. Em.Object.create({bootStatus: 'REGISTERED'}),
  622. Em.Object.create({bootStatus: 'RUNNING'})
  623. ],
  624. isLoaded: true,
  625. e: true,
  626. m: 'bootHosts with one REGISTERED and isLoaded is true'
  627. },
  628. {
  629. bootHosts: [
  630. Em.Object.create({bootStatus: 'FAILED'}),
  631. Em.Object.create({bootStatus: 'RUNNING'})
  632. ],
  633. isLoaded: true,
  634. e: true,
  635. m: 'bootHosts with one FAILED and isLoaded is true'
  636. }
  637. ]);
  638. beforeEach(function () {
  639. sinon.stub(c, 'getAllRegisteredHosts', Em.K);
  640. sinon.stub(c, 'disablePreviousSteps', Em.K);
  641. sinon.stub(c, 'navigateStep', Em.K);
  642. });
  643. afterEach(function () {
  644. c.disablePreviousSteps.restore();
  645. c.getAllRegisteredHosts.restore();
  646. c.navigateStep.restore();
  647. });
  648. tests.forEach(function (test) {
  649. it(test.m, function () {
  650. c.set('bootHosts', test.bootHosts);
  651. c.set('isLoaded', test.isLoaded);
  652. c.setRegistrationInProgress();
  653. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  654. });
  655. });
  656. });
  657. describe('#doBootstrap()', function () {
  658. beforeEach(function () {
  659. sinon.spy(App.ajax, 'send');
  660. });
  661. afterEach(function () {
  662. App.ajax.send.restore();
  663. });
  664. it('shouldn\'t do nothing if stopBootstrap is true', function () {
  665. c.set('stopBootstrap', true);
  666. c.doBootstrap();
  667. expect(App.ajax.send.called).to.equal(false);
  668. });
  669. it('should increment numPolls if stopBootstrap is false', function () {
  670. c.set('numPolls', 0);
  671. c.set('stopBootstrap', false);
  672. c.doBootstrap();
  673. expect(App.ajax.send.calledOnce).to.be.true;
  674. expect(c.get('numPolls')).to.equal(1);
  675. });
  676. });
  677. describe('#startRegistration', function () {
  678. beforeEach(function () {
  679. sinon.spy(c, 'isHostsRegistered');
  680. });
  681. afterEach(function () {
  682. c.isHostsRegistered.restore();
  683. });
  684. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function () {
  685. c.set('registrationStartedAt', 1234);
  686. c.startRegistration();
  687. expect(c.isHostsRegistered.called).to.equal(false);
  688. expect(c.get('registrationStartedAt')).to.equal(1234);
  689. });
  690. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function () {
  691. c.set('registrationStartedAt', null);
  692. c.startRegistration();
  693. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  694. });
  695. });
  696. describe('#isHostsRegistered', function () {
  697. beforeEach(function () {
  698. sinon.stub(App.ajax, 'send', function () {
  699. return {retry: function () {
  700. return {then: Em.K}
  701. }}
  702. });
  703. });
  704. afterEach(function () {
  705. App.ajax.send.restore();
  706. });
  707. it('shouldn\'t do nothing if stopBootstrap is true', function () {
  708. c.set('stopBootstrap', true);
  709. c.isHostsRegistered();
  710. expect(App.ajax.send.called).to.equal(false);
  711. });
  712. it('should do ajax call if stopBootstrap is false', function () {
  713. c.set('stopBootstrap', false);
  714. c.isHostsRegistered();
  715. expect(App.ajax.send.called).to.equal(true);
  716. });
  717. });
  718. describe('#isHostsRegisteredSuccessCallback', function () {
  719. var tests = Em.A([
  720. {
  721. bootHosts: Em.A([
  722. Em.Object.create({bootStatus: 'DONE'})
  723. ]),
  724. data: {items: []},
  725. registrationStartedAt: 1000000,
  726. m: 'one host DONE',
  727. e: {
  728. bs: 'REGISTERING',
  729. getHostInfoCalled: false
  730. }
  731. },
  732. {
  733. bootHosts: Em.A([
  734. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  735. ]),
  736. data: {items: [
  737. {Hosts: {host_name: 'c1'}}
  738. ]},
  739. m: ' one host REGISTERING',
  740. e: {
  741. bs: 'REGISTERED',
  742. getHostInfoCalled: false
  743. }
  744. },
  745. {
  746. bootHosts: Em.A([
  747. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  748. ]),
  749. data: {items: [
  750. {Hosts: {host_name: 'c2'}}
  751. ]},
  752. registrationStartedAt: 0,
  753. m: 'one host REGISTERING but data missing info about it, timeout',
  754. e: {
  755. bs: 'FAILED',
  756. getHostInfoCalled: false
  757. }
  758. },
  759. {
  760. bootHosts: Em.A([
  761. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  762. ]),
  763. data: {items: [
  764. {Hosts: {host_name: 'c2'}}
  765. ]},
  766. registrationStartedAt: 1000000,
  767. m: 'one host REGISTERING but data missing info about it',
  768. e: {
  769. bs: 'REGISTERING',
  770. getHostInfoCalled: false
  771. }
  772. },
  773. {
  774. bootHosts: Em.A([
  775. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  776. ]),
  777. data: {items: [
  778. {Hosts: {host_name: 'c1'}}
  779. ]},
  780. m: ' one host RUNNING',
  781. e: {
  782. bs: 'RUNNING',
  783. getHostInfoCalled: false
  784. }
  785. }
  786. ]);
  787. beforeEach(function () {
  788. sinon.spy(c, 'getHostInfo');
  789. sinon.stub(App, 'dateTime').returns(1000000);
  790. });
  791. afterEach(function () {
  792. c.getHostInfo.restore();
  793. App.dateTime.restore();
  794. });
  795. tests.forEach(function (test) {
  796. it(test.m, function () {
  797. c.set('content.installedHosts', []);
  798. c.set('bootHosts', test.bootHosts);
  799. c.set('registrationStartedAt', test.registrationStartedAt);
  800. c.isHostsRegisteredSuccessCallback(test.data);
  801. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  802. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  803. });
  804. });
  805. });
  806. describe('#getAllRegisteredHosts', function () {
  807. beforeEach(function () {
  808. sinon.spy(App.ajax, 'send');
  809. });
  810. afterEach(function () {
  811. App.ajax.send.restore();
  812. });
  813. it('should call App.ajax.send', function () {
  814. c.getAllRegisteredHosts();
  815. expect(App.ajax.send.calledOnce).to.equal(true);
  816. });
  817. });
  818. describe('#getAllRegisteredHostsCallback', function () {
  819. var tests = Em.A([
  820. {
  821. hostsInCluster: ['c3'],
  822. bootHosts: [
  823. {name: 'c1'},
  824. {name: 'c2'}
  825. ],
  826. hosts: Em.A([
  827. {Hosts: {host_name: 'c1'}},
  828. {Hosts: {host_name: 'c2'}}
  829. ]),
  830. m: 'No registered hosts',
  831. e: {
  832. hasMoreRegisteredHosts: false,
  833. registeredHosts: ''
  834. }
  835. },
  836. {
  837. hostsInCluster: ['c4'],
  838. bootHosts: [
  839. {name: 'c3'},
  840. {name: 'c5'}
  841. ],
  842. hosts: Em.A([
  843. {Hosts: {host_name: 'c1'}},
  844. {Hosts: {host_name: 'c2'}}
  845. ]),
  846. m: '2 registered hosts',
  847. e: {
  848. hasMoreRegisteredHosts: true,
  849. registeredHosts: ['c1', 'c2']
  850. }
  851. },
  852. {
  853. hostsInCluster: ['c4'],
  854. bootHosts: [
  855. {name: 'c1'},
  856. {name: 'c5'}
  857. ],
  858. hosts: Em.A([
  859. {Hosts: {host_name: 'c1'}},
  860. {Hosts: {host_name: 'c2'}}
  861. ]),
  862. m: '1 registered host',
  863. e: {
  864. hasMoreRegisteredHosts: true,
  865. registeredHosts: ['c2']
  866. }
  867. },
  868. {
  869. hostsInCluster: ['c1'],
  870. bootHosts: [
  871. {name: 'c3'},
  872. {name: 'c5'}
  873. ],
  874. hosts: Em.A([
  875. {Hosts: {host_name: 'c1'}},
  876. {Hosts: {host_name: 'c2'}}
  877. ]),
  878. m: '1 registered host (2)',
  879. e: {
  880. hasMoreRegisteredHosts: true,
  881. registeredHosts: ['c2']
  882. }
  883. }
  884. ]);
  885. tests.forEach(function (test) {
  886. it(test.m, function () {
  887. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  888. c.set('bootHosts', test.bootHosts);
  889. c.getAllRegisteredHostsCallback({items: test.hosts});
  890. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  891. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  892. });
  893. });
  894. });
  895. describe('#registerErrPopup', function () {
  896. beforeEach(function () {
  897. sinon.spy(App.ModalPopup, 'show');
  898. });
  899. afterEach(function () {
  900. App.ModalPopup.show.restore();
  901. });
  902. it('should call App.ModalPopup.show', function () {
  903. c.registerErrPopup();
  904. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  905. });
  906. });
  907. describe('#getHostInfo', function () {
  908. beforeEach(function () {
  909. sinon.spy(App.ajax, 'send');
  910. });
  911. afterEach(function () {
  912. App.ajax.send.restore();
  913. });
  914. it('should do ajax request', function () {
  915. c.getHostInfo();
  916. expect(App.ajax.send.calledOnce).to.equal(true);
  917. });
  918. });
  919. describe('#getHostInfoErrorCallback', function () {
  920. beforeEach(function () {
  921. sinon.spy(c, 'registerErrPopup');
  922. });
  923. afterEach(function () {
  924. c.registerErrPopup.restore();
  925. });
  926. it('should call registerErrPopup', function () {
  927. c.getHostInfoErrorCallback();
  928. expect(c.registerErrPopup.calledOnce).to.equal(true);
  929. });
  930. });
  931. describe('#stopRegistration', function () {
  932. var tests = Em.A([
  933. {
  934. bootHosts: [
  935. Em.Object.create({bootStatus: 'REGISTERED'}),
  936. Em.Object.create({bootStatus: 'RUNNING'})
  937. ],
  938. e: {isSubmitDisabled: false}
  939. },
  940. {
  941. bootHosts: [
  942. Em.Object.create({bootStatus: 'FAILED'}),
  943. Em.Object.create({bootStatus: 'RUNNING'})
  944. ],
  945. e: {isSubmitDisabled: true}
  946. },
  947. {
  948. bootHosts: [
  949. Em.Object.create({bootStatus: 'FAILED'}),
  950. Em.Object.create({bootStatus: 'REGISTERED'})
  951. ],
  952. e: {isSubmitDisabled: false}
  953. },
  954. {
  955. bootHosts: [
  956. Em.Object.create({bootStatus: 'RUNNING'}),
  957. Em.Object.create({bootStatus: 'RUNNING'})
  958. ],
  959. e: {isSubmitDisabled: true}
  960. }
  961. ]);
  962. tests.forEach(function (test) {
  963. it(test.bootHosts.mapProperty('bootStatus').join(', '), function () {
  964. c.reopen({bootHosts: test.bootHosts});
  965. c.stopRegistration();
  966. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  967. });
  968. });
  969. });
  970. describe('#submit', function () {
  971. beforeEach(function () {
  972. sinon.spy(App.ModalPopup, 'show');
  973. });
  974. afterEach(function () {
  975. App.ModalPopup.show.restore();
  976. });
  977. it('if isHostHaveWarnings should show confirmation popup', function () {
  978. c.reopen({isHostHaveWarnings: true});
  979. c.submit();
  980. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  981. });
  982. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function () {
  983. var bootHosts = [
  984. Em.Object.create({name: 'c1'})
  985. ];
  986. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  987. c.submit().onPrimary();
  988. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  989. });
  990. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function () {
  991. var bootHosts = [
  992. Em.Object.create({name: 'c1'})
  993. ];
  994. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  995. c.submit();
  996. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  997. });
  998. });
  999. describe('#hostLogPopup', function () {
  1000. beforeEach(function () {
  1001. sinon.spy(App.ModalPopup, 'show');
  1002. });
  1003. afterEach(function () {
  1004. App.ModalPopup.show.restore();
  1005. });
  1006. it('should show App.ModalPopup', function () {
  1007. c.hostLogPopup({context: Em.Object.create({})});
  1008. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1009. });
  1010. });
  1011. describe('#rerunChecksSuccessCallback', function () {
  1012. beforeEach(function () {
  1013. sinon.stub(c, 'parseWarnings', Em.K);
  1014. });
  1015. afterEach(function () {
  1016. c.parseWarnings.restore();
  1017. });
  1018. it('should set checksUpdateProgress to 100', function () {
  1019. c.set('checksUpdateProgress', 0);
  1020. c.rerunChecksSuccessCallback({items: []});
  1021. expect(c.get('checksUpdateProgress')).to.equal(100);
  1022. });
  1023. it('should set checksUpdateStatus to SUCCESS', function () {
  1024. c.set('checksUpdateStatus', '');
  1025. c.rerunChecksSuccessCallback({items: []});
  1026. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  1027. });
  1028. it('should call parseWarnings', function () {
  1029. c.rerunChecksSuccessCallback({items: []});
  1030. expect(c.parseWarnings.calledOnce).to.equal(true);
  1031. });
  1032. });
  1033. describe('#rerunChecksErrorCallback', function () {
  1034. it('should set checksUpdateProgress to 100', function () {
  1035. c.set('checksUpdateProgress', 0);
  1036. c.rerunChecksErrorCallback({});
  1037. expect(c.get('checksUpdateProgress')).to.equal(100);
  1038. });
  1039. it('should set checksUpdateStatus to FAILED', function () {
  1040. c.set('checksUpdateStatus', '');
  1041. c.rerunChecksErrorCallback({});
  1042. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  1043. });
  1044. });
  1045. describe('#filterBootHosts', function () {
  1046. var tests = Em.A([
  1047. {
  1048. bootHosts: [
  1049. Em.Object.create({name: 'c1'}),
  1050. Em.Object.create({name: 'c2'})
  1051. ],
  1052. data: {
  1053. items: [
  1054. {Hosts: {host_name: 'c1'}}
  1055. ]
  1056. },
  1057. m: 'one host',
  1058. e: ['c1']
  1059. },
  1060. {
  1061. bootHosts: [
  1062. Em.Object.create({name: 'c1'}),
  1063. Em.Object.create({name: 'c2'})
  1064. ],
  1065. data: {
  1066. items: [
  1067. {Hosts: {host_name: 'c3'}}
  1068. ]
  1069. },
  1070. m: 'no hosts',
  1071. e: []
  1072. },
  1073. {
  1074. bootHosts: [
  1075. Em.Object.create({name: 'c1'}),
  1076. Em.Object.create({name: 'c2'})
  1077. ],
  1078. data: {
  1079. items: [
  1080. {Hosts: {host_name: 'c1'}},
  1081. {Hosts: {host_name: 'c2'}}
  1082. ]
  1083. },
  1084. m: 'many hosts',
  1085. e: ['c1', 'c2']
  1086. }
  1087. ]);
  1088. tests.forEach(function (test) {
  1089. it(test.m, function () {
  1090. c.reopen({bootHosts: test.bootHosts});
  1091. var filteredData = c.filterBootHosts(test.data);
  1092. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1093. });
  1094. });
  1095. });
  1096. describe('#hostWarningsPopup', function () {
  1097. beforeEach(function () {
  1098. sinon.spy(App.ModalPopup, 'show');
  1099. sinon.stub(c, 'rerunChecks', Em.K);
  1100. });
  1101. afterEach(function () {
  1102. App.ModalPopup.show.restore();
  1103. c.rerunChecks.restore();
  1104. });
  1105. it('should show App.ModalPopup', function () {
  1106. c.hostWarningsPopup();
  1107. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1108. });
  1109. it('should clear checksUpdateStatus on primary', function () {
  1110. c.set('checksUpdateStatus', 'not null value');
  1111. c.hostWarningsPopup().onPrimary();
  1112. expect(c.get('checksUpdateStatus')).to.be.null;
  1113. });
  1114. it('should clear checksUpdateStatus on close', function () {
  1115. c.set('checksUpdateStatus', 'not null value');
  1116. c.hostWarningsPopup().onClose();
  1117. expect(c.get('checksUpdateStatus')).to.be.null;
  1118. });
  1119. it('should rerunChecks onSecondary', function () {
  1120. c.hostWarningsPopup().onSecondary();
  1121. expect(c.rerunChecks.calledOnce).to.equal(true);
  1122. });
  1123. });
  1124. describe('#registeredHostsPopup', function () {
  1125. beforeEach(function () {
  1126. sinon.spy(App.ModalPopup, 'show');
  1127. });
  1128. afterEach(function () {
  1129. App.ModalPopup.show.restore();
  1130. });
  1131. it('should show App.ModalPopup', function () {
  1132. c.registeredHostsPopup();
  1133. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1134. });
  1135. });
  1136. describe('#parseWarnings', function () {
  1137. beforeEach(function () {
  1138. sinon.stub(App, 'get', function (k) {
  1139. if ('testMode' === k) return false;
  1140. return Em.get(App, k);
  1141. });
  1142. sinon.stub(c, 'filterBootHosts', function (k) {
  1143. return k;
  1144. });
  1145. });
  1146. afterEach(function () {
  1147. App.get.restore();
  1148. c.filterBootHosts.restore();
  1149. });
  1150. it('no warnings if last_agent_env isn\'t specified', function () {
  1151. c.set('warnings', [
  1152. {}
  1153. ]);
  1154. c.set('warningsByHost', [
  1155. {},
  1156. {}
  1157. ]);
  1158. c.parseWarnings({items: [
  1159. {Hosts: {host_name: 'c1'}}
  1160. ]});
  1161. expect(c.get('warnings')).to.eql([]);
  1162. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1163. });
  1164. Em.A([
  1165. {
  1166. m: 'parse stackFoldersAndFiles',
  1167. tests: Em.A([
  1168. {
  1169. items: [
  1170. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}
  1171. ],
  1172. m: 'empty stackFoldersAndFiles',
  1173. e: {
  1174. warnings: [],
  1175. warningsByHost: [0]
  1176. }
  1177. },
  1178. {
  1179. items: [
  1180. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1181. {name: 'n1'}
  1182. ]}}}
  1183. ],
  1184. m: 'not empty stackFoldersAndFiles',
  1185. e: {
  1186. warnings: [
  1187. {
  1188. name: 'n1',
  1189. hosts: ['c1'],
  1190. onSingleHost: true,
  1191. category: 'fileFolders'
  1192. }
  1193. ],
  1194. warningsByHost: [1]
  1195. }
  1196. },
  1197. {
  1198. items: [
  1199. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1200. {name: 'n1'}
  1201. ]}}},
  1202. {Hosts: {host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [
  1203. {name: 'n1'}
  1204. ]}}}
  1205. ],
  1206. m: 'not empty stackFoldersAndFiles on two hosts',
  1207. e: {
  1208. warnings: [
  1209. {
  1210. name: 'n1',
  1211. hosts: ['c1', 'c2'],
  1212. onSingleHost: false,
  1213. category: 'fileFolders'
  1214. }
  1215. ],
  1216. warningsByHost: [1]
  1217. }
  1218. }
  1219. ])
  1220. },
  1221. {
  1222. m: 'parse hostHealth.liveServices',
  1223. tests: Em.A([
  1224. {
  1225. items: [
  1226. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: []}}}
  1227. ],
  1228. m: 'empty hostHealth',
  1229. e: {
  1230. warnings: [],
  1231. warningsByHost: [0]
  1232. }
  1233. },
  1234. {
  1235. items: [
  1236. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: []}}}}
  1237. ],
  1238. m: 'empty liveServices',
  1239. e: {
  1240. warnings: [],
  1241. warningsByHost: [0]
  1242. }
  1243. },
  1244. {
  1245. items: [
  1246. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1247. {status: 'Unhealthy', name: 'n1'}
  1248. ]}}}}
  1249. ],
  1250. m: 'not empty hostHealth.liveServices',
  1251. e: {
  1252. warnings: [
  1253. {
  1254. name: 'n1',
  1255. hosts: ['c1'],
  1256. onSingleHost: true,
  1257. category: 'services'
  1258. }
  1259. ],
  1260. warningsByHost: [1]
  1261. }
  1262. },
  1263. {
  1264. items: [
  1265. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1266. {status: 'Unhealthy', name: 'n1'}
  1267. ]}}}},
  1268. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {liveServices: [
  1269. {status: 'Unhealthy', name: 'n1'}
  1270. ]}}}}
  1271. ],
  1272. m: 'not empty hostHealth.liveServices on two hosts',
  1273. e: {
  1274. warnings: [
  1275. {
  1276. name: 'n1',
  1277. hosts: ['c1', 'c2'],
  1278. onSingleHost: false,
  1279. category: 'services'
  1280. }
  1281. ],
  1282. warningsByHost: [1, 1]
  1283. }
  1284. }
  1285. ])
  1286. },
  1287. {
  1288. m: 'parse existingUsers',
  1289. tests: Em.A([
  1290. {
  1291. items: [
  1292. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: []}}}
  1293. ],
  1294. m: 'empty existingUsers',
  1295. e: {
  1296. warnings: [],
  1297. warningsByHost: [0]
  1298. }
  1299. },
  1300. {
  1301. items: [
  1302. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1303. {userName: 'n1'}
  1304. ]}}}
  1305. ],
  1306. m: 'not empty existingUsers',
  1307. e: {
  1308. warnings: [
  1309. {
  1310. name: 'n1',
  1311. hosts: ['c1'],
  1312. onSingleHost: true,
  1313. category: 'users'
  1314. }
  1315. ],
  1316. warningsByHost: [1]
  1317. }
  1318. },
  1319. {
  1320. items: [
  1321. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1322. {userName: 'n1'}
  1323. ]}}},
  1324. {Hosts: {host_name: 'c2', last_agent_env: {existingUsers: [
  1325. {userName: 'n1'}
  1326. ]}}}
  1327. ],
  1328. m: 'not empty existingUsers on two hosts',
  1329. e: {
  1330. warnings: [
  1331. {
  1332. name: 'n1',
  1333. hosts: ['c1', 'c2'],
  1334. onSingleHost: false,
  1335. category: 'users'
  1336. }
  1337. ],
  1338. warningsByHost: [1, 1]
  1339. }
  1340. }
  1341. ])
  1342. },
  1343. {
  1344. m: 'parse alternatives',
  1345. tests: Em.A([
  1346. {
  1347. items: [
  1348. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: []}}}
  1349. ],
  1350. m: 'empty alternatives',
  1351. e: {
  1352. warnings: [],
  1353. warningsByHost: [0]
  1354. }
  1355. },
  1356. {
  1357. items: [
  1358. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1359. {name: 'n1'}
  1360. ]}}}
  1361. ],
  1362. m: 'not empty alternatives',
  1363. e: {
  1364. warnings: [
  1365. {
  1366. name: 'n1',
  1367. hosts: ['c1'],
  1368. onSingleHost: true,
  1369. category: 'alternatives'
  1370. }
  1371. ],
  1372. warningsByHost: [1]
  1373. }
  1374. },
  1375. {
  1376. items: [
  1377. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1378. {name: 'n1'}
  1379. ]}}},
  1380. {Hosts: {host_name: 'c2', last_agent_env: {alternatives: [
  1381. {name: 'n1'}
  1382. ]}}}
  1383. ],
  1384. m: 'not empty alternatives on two hosts',
  1385. e: {
  1386. warnings: [
  1387. {
  1388. name: 'n1',
  1389. hosts: ['c1', 'c2'],
  1390. onSingleHost: false,
  1391. category: 'alternatives'
  1392. }
  1393. ],
  1394. warningsByHost: [1, 1]
  1395. }
  1396. }
  1397. ])
  1398. },
  1399. {
  1400. m: 'parse hostHealth.activeJavaProcs',
  1401. tests: Em.A([
  1402. {
  1403. items: [
  1404. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}
  1405. ],
  1406. m: 'empty hostHealth',
  1407. e: {
  1408. warnings: [],
  1409. warningsByHost: [0]
  1410. }
  1411. },
  1412. {
  1413. items: [
  1414. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: []}}}}
  1415. ],
  1416. m: 'empty activeJavaProcs',
  1417. e: {
  1418. warnings: [],
  1419. warningsByHost: [0]
  1420. }
  1421. },
  1422. {
  1423. items: [
  1424. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1425. {pid: 'n1', command: ''}
  1426. ]}}}}
  1427. ],
  1428. m: 'not empty hostHealth.activeJavaProcs',
  1429. e: {
  1430. warnings: [
  1431. {
  1432. pid: 'n1',
  1433. hosts: ['c1'],
  1434. onSingleHost: true,
  1435. category: 'processes'
  1436. }
  1437. ],
  1438. warningsByHost: [1]
  1439. }
  1440. },
  1441. {
  1442. items: [
  1443. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1444. {pid: 'n1', command: ''}
  1445. ]}}}},
  1446. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {activeJavaProcs: [
  1447. {pid: 'n1', command: ''}
  1448. ]}}}}
  1449. ],
  1450. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1451. e: {
  1452. warnings: [
  1453. {
  1454. pid: 'n1',
  1455. hosts: ['c1', 'c2'],
  1456. onSingleHost: false,
  1457. category: 'processes'
  1458. }
  1459. ],
  1460. warningsByHost: [1, 1]
  1461. }
  1462. }
  1463. ])
  1464. }
  1465. ]).forEach(function (category) {
  1466. describe(category.m, function () {
  1467. category.tests.forEach(function (test) {
  1468. it(test.m, function () {
  1469. c.parseWarnings({items: test.items});
  1470. c.get('warnings').forEach(function (w, i) {
  1471. Em.keys(test.e.warnings[i]).forEach(function (k) {
  1472. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1473. });
  1474. });
  1475. for (var i in test.e.warningsByHost) {
  1476. if (test.e.warningsByHost.hasOwnProperty(i)) {
  1477. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1478. }
  1479. }
  1480. });
  1481. });
  1482. });
  1483. });
  1484. it('should parse umask warnings', function () {
  1485. var items = [
  1486. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1487. {Hosts: {host_name: 'c2', last_agent_env: {umask: 1}}}
  1488. ];
  1489. c.parseWarnings({items: items});
  1490. var warnings = c.get('warnings');
  1491. expect(warnings.length).to.equal(1);
  1492. expect(warnings[0].hosts).to.eql(['c1']);
  1493. expect(warnings[0].onSingleHost).to.equal(true);
  1494. });
  1495. it('should parse umask warnings (2)', function () {
  1496. var items = [
  1497. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1498. {Hosts: {host_name: 'c2', last_agent_env: {umask: 25}}}
  1499. ];
  1500. c.parseWarnings({items: items});
  1501. var warnings = c.get('warnings');
  1502. expect(warnings.length).to.equal(2);
  1503. expect(warnings.mapProperty('hosts')).to.eql([
  1504. ['c1'],
  1505. ['c2']
  1506. ]);
  1507. });
  1508. it('should parse firewall warnings', function () {
  1509. var items = [
  1510. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1511. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: false, firewallName: "iptables"}}}
  1512. ];
  1513. c.parseWarnings({items: items});
  1514. var warnings = c.get('warnings');
  1515. expect(warnings.length).to.equal(1);
  1516. expect(warnings[0].hosts).to.eql(['c1']);
  1517. expect(warnings[0].onSingleHost).to.equal(true);
  1518. });
  1519. it('should parse firewall warnings (2)', function () {
  1520. var items = [
  1521. {Hosts: {host_name: 'c1', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}},
  1522. {Hosts: {host_name: 'c2', last_agent_env: {firewallRunning: true, firewallName: "iptables"}}}
  1523. ];
  1524. c.parseWarnings({items: items});
  1525. var warnings = c.get('warnings');
  1526. expect(warnings.length).to.equal(1);
  1527. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1528. expect(warnings[0].onSingleHost).to.equal(false);
  1529. });
  1530. it('should parse reverseLookup warnings', function () {
  1531. var items = [
  1532. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1533. ];
  1534. c.parseWarnings({items: items});
  1535. var warnings = c.get('warnings');
  1536. expect(warnings.length).to.equal(0);
  1537. });
  1538. it('should parse reverseLookup warnings (2)', function () {
  1539. var items = [
  1540. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1541. ];
  1542. c.parseWarnings({items: items});
  1543. var warnings = c.get('warnings');
  1544. expect(warnings.length).to.equal(1);
  1545. expect(warnings[0].hosts).to.eql(['c1']);
  1546. expect(warnings[0].onSingleHost).to.equal(true);
  1547. });
  1548. it('should parse reverseLookup warnings (3)', function () {
  1549. var items = [
  1550. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1551. {Hosts: {host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1552. ];
  1553. c.parseWarnings({items: items});
  1554. var warnings = c.get('warnings');
  1555. expect(warnings.length).to.equal(1);
  1556. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1557. expect(warnings[0].onSingleHost).to.equal(false);
  1558. });
  1559. });
  1560. describe('#navigateStep', function () {
  1561. beforeEach(function () {
  1562. sinon.stub(c, 'setupBootStrap', Em.K);
  1563. });
  1564. afterEach(function () {
  1565. c.setupBootStrap.restore();
  1566. });
  1567. Em.A([
  1568. {
  1569. isLoaded: true,
  1570. manualInstall: false,
  1571. bootStatus: false,
  1572. m: 'should call setupBootStrap',
  1573. e: true
  1574. },
  1575. {
  1576. isLoaded: true,
  1577. manualInstall: false,
  1578. bootStatus: true,
  1579. m: 'shouldn\'t call setupBootStrap (1)',
  1580. e: false
  1581. },
  1582. {
  1583. isLoaded: false,
  1584. manualInstall: false,
  1585. bootStatus: false,
  1586. m: 'shouldn\'t call setupBootStrap (2)',
  1587. e: false
  1588. },
  1589. {
  1590. isLoaded: false,
  1591. manualInstall: true,
  1592. bootStatus: false,
  1593. m: 'shouldn\'t call setupBootStrap (3)',
  1594. e: false
  1595. }
  1596. ]).forEach(function (test) {
  1597. it(test.m, function () {
  1598. c.reopen({
  1599. isLoaded: test.isLoaded,
  1600. content: {
  1601. installedHosts: [],
  1602. installOptions: {
  1603. manualInstall: test.manualInstall
  1604. }
  1605. },
  1606. wizardController: Em.Object.create({
  1607. getDBProperty: function () {
  1608. return test.bootStatus
  1609. }
  1610. })
  1611. });
  1612. c.navigateStep();
  1613. if (test.e) {
  1614. expect(c.setupBootStrap.calledOnce).to.equal(true);
  1615. }
  1616. else {
  1617. expect(c.setupBootStrap.called).to.equal(false);
  1618. }
  1619. });
  1620. });
  1621. it('should set test data if testMode is true', function () {
  1622. c.reopen({
  1623. isLoaded: true,
  1624. hosts: [
  1625. {},
  1626. {},
  1627. {}
  1628. ],
  1629. content: {
  1630. installedHosts: [],
  1631. installOptions: {
  1632. manualInstall: true
  1633. }
  1634. },
  1635. setRegistrationInProgress: Em.K
  1636. });
  1637. sinon.stub(App, 'get', function (k) {
  1638. if ('testMode' === k) return true;
  1639. return Em.get(App, k);
  1640. });
  1641. c.navigateStep();
  1642. App.get.restore();
  1643. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1644. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1645. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1646. expect(c.get('isSubmitDisabled')).to.equal(false);
  1647. });
  1648. it('should start registration', function () {
  1649. c.reopen({
  1650. isLoaded: true,
  1651. hosts: [
  1652. {},
  1653. {},
  1654. {}
  1655. ],
  1656. content: {
  1657. installedHosts: [],
  1658. installOptions: {
  1659. manualInstall: true
  1660. }
  1661. },
  1662. setRegistrationInProgress: Em.K,
  1663. startRegistration: Em.K
  1664. });
  1665. sinon.stub(App, 'get', function (k) {
  1666. if ('testMode' === k) return false;
  1667. return Em.get(App, k);
  1668. });
  1669. sinon.spy(c, 'startRegistration');
  1670. c.navigateStep();
  1671. App.get.restore();
  1672. expect(c.startRegistration.calledOnce).to.equal(true);
  1673. c.startRegistration.restore();
  1674. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1675. expect(c.get('registrationStartedAt')).to.be.null;
  1676. });
  1677. });
  1678. describe('#setupBootStrap', function () {
  1679. var cases = [
  1680. {
  1681. customizeAgentUserAccount: true,
  1682. userRunAs: 'user',
  1683. title: 'Ambari Agent user account customize enabled'
  1684. },
  1685. {
  1686. customizeAgentUserAccount: false,
  1687. userRunAs: 'root',
  1688. title: 'Ambari Agent user account customize disabled'
  1689. }
  1690. ],
  1691. controller = App.WizardStep3Controller.create({
  1692. content: {
  1693. installOptions: {
  1694. sshKey: 'key',
  1695. sshUser: 'root',
  1696. agentUser: 'user'
  1697. },
  1698. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } },
  1699. controllerName: 'installerController'
  1700. }
  1701. });
  1702. beforeEach(function () {
  1703. sinon.stub(App.router.get('installerController'), 'launchBootstrap', Em.K);
  1704. this.mock = sinon.stub(App, 'get');
  1705. });
  1706. afterEach(function () {
  1707. App.router.get('installerController').launchBootstrap.restore();
  1708. this.mock.restore();
  1709. });
  1710. cases.forEach(function (item) {
  1711. it(item.title, function () {
  1712. this.mock.withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  1713. controller.setupBootStrap();
  1714. expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
  1715. verbose: true,
  1716. sshKey: 'key',
  1717. hosts: ['host0', 'host1'],
  1718. user: 'root',
  1719. userRunAs: item.userRunAs
  1720. }));
  1721. });
  1722. });
  1723. });
  1724. describe('#checkHostDiskSpace', function () {
  1725. Em.A([
  1726. {
  1727. diskInfo: [
  1728. {
  1729. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1730. mountpoint: '/'
  1731. }
  1732. ],
  1733. m: 'available less than App.minDiskSpace',
  1734. e: false
  1735. },
  1736. {
  1737. diskInfo: [
  1738. {
  1739. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1740. mountpoint: '/usr'
  1741. }
  1742. ],
  1743. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1744. e: false
  1745. },
  1746. {
  1747. diskInfo: [
  1748. {
  1749. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1750. mountpoint: '/usr/lib'
  1751. }
  1752. ],
  1753. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1754. e: false
  1755. },
  1756. {
  1757. diskInfo: [
  1758. {
  1759. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1760. mountpoint: '/'
  1761. }
  1762. ],
  1763. m: 'available greater than App.minDiskSpace',
  1764. e: true
  1765. },
  1766. {
  1767. diskInfo: [
  1768. {
  1769. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1770. mountpoint: '/usr'
  1771. }
  1772. ],
  1773. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1774. e: true
  1775. },
  1776. {
  1777. diskInfo: [
  1778. {
  1779. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1780. mountpoint: '/usr/lib'
  1781. }
  1782. ],
  1783. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1784. e: true
  1785. },
  1786. {
  1787. diskInfo: [
  1788. {
  1789. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1790. mountpoint: '/home/tdk'
  1791. }
  1792. ],
  1793. m: 'mount point without free space checks',
  1794. e: true
  1795. }
  1796. ]).forEach(function (test) {
  1797. it(test.m, function () {
  1798. var r = c.checkHostDiskSpace('', test.diskInfo);
  1799. expect(Em.isEmpty(r)).to.equal(test.e);
  1800. });
  1801. });
  1802. });
  1803. describe('#checkHostOSType', function () {
  1804. it('should return empty string if no stacks provided', function () {
  1805. c.reopen({content: {stacks: null}});
  1806. expect(c.checkHostOSType()).to.equal('');
  1807. });
  1808. it('os type is valid', function () {
  1809. var osType = 'redhat6';
  1810. c.reopen({
  1811. content: {
  1812. stacks: [
  1813. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1814. ]
  1815. }
  1816. });
  1817. expect(c.checkHostOSType(osType, '')).to.equal('');
  1818. });
  1819. it('os type is invalid', function () {
  1820. var osType = 'os2';
  1821. c.reopen({
  1822. content: {
  1823. stacks: [
  1824. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1825. ]
  1826. }
  1827. });
  1828. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1829. });
  1830. });
  1831. describe('#getHostInfoSuccessCallback', function () {
  1832. beforeEach(function () {
  1833. sinon.stub(c, 'parseWarnings', Em.K);
  1834. sinon.stub(c, 'stopRegistration', Em.K);
  1835. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1836. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1837. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1838. });
  1839. afterEach(function () {
  1840. c.parseWarnings.restore();
  1841. c.stopRegistration.restore();
  1842. c.checkHostDiskSpace.restore();
  1843. c._setHostDataFromLoadedHostInfo.restore();
  1844. c._setHostDataWithSkipBootstrap.restore();
  1845. });
  1846. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function () {
  1847. sinon.stub(App, 'get', function (k) {
  1848. if ('skipBootstrap' === k) return true;
  1849. if ('testMode' === k) return false;
  1850. return Em.get(App, k);
  1851. });
  1852. c.reopen({
  1853. bootHosts: [Em.Object.create({name: 'h1'})]
  1854. });
  1855. var jsonData = {items: [
  1856. {Hosts: {host_name: 'h1'}}
  1857. ]};
  1858. c.getHostInfoSuccessCallback(jsonData);
  1859. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1860. App.get.restore();
  1861. });
  1862. it('should add repo warnings', function () {
  1863. var jsonData = {items: [
  1864. {Hosts: {host_name: 'h1'}}
  1865. ]};
  1866. sinon.stub(c, 'checkHostOSType', function () {
  1867. return 'not_null_value';
  1868. });
  1869. sinon.stub(App, 'get', function (k) {
  1870. if ('skipBootstrap' === k) return false;
  1871. if ('testMode' === k) return false;
  1872. return Em.get(App, k);
  1873. });
  1874. c.reopen({
  1875. bootHosts: [Em.Object.create({name: 'h1'})]
  1876. });
  1877. c.getHostInfoSuccessCallback(jsonData);
  1878. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1879. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1880. c.checkHostOSType.restore();
  1881. App.get.restore();
  1882. });
  1883. it('should add disk warnings', function () {
  1884. var jsonData = {items: [
  1885. {Hosts: {host_name: 'h1'}}
  1886. ]};
  1887. sinon.stub(App, 'get', function (k) {
  1888. if ('skipBootstrap' === k) return false;
  1889. if ('testMode' === k) return false;
  1890. return Em.get(App, k);
  1891. });
  1892. c.reopen({
  1893. bootHosts: [Em.Object.create({name: 'h1'})]
  1894. });
  1895. c.getHostInfoSuccessCallback(jsonData);
  1896. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1897. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1898. App.get.restore();
  1899. });
  1900. });
  1901. describe('#_setHostDataWithSkipBootstrap', function () {
  1902. it('should set mock-data', function () {
  1903. var host = Em.Object.create({});
  1904. c._setHostDataWithSkipBootstrap(host);
  1905. expect(host.get('cpu')).to.equal(2);
  1906. expect(host.get('memory')).to.equal('2000000.00');
  1907. expect(host.get('disk_info.length')).to.equal(4);
  1908. });
  1909. });
  1910. describe('#_setHostDataFromLoadedHostInfo', function () {
  1911. it('should set data from hostInfo', function () {
  1912. var host = Em.Object.create(),
  1913. hostInfo = {
  1914. Hosts: {
  1915. cpu_count: 2,
  1916. total_mem: 12345,
  1917. os_type: 't1',
  1918. os_arch: 'os1',
  1919. ip: '0.0.0.0',
  1920. disk_info: [
  1921. {mountpoint: '/boot'},
  1922. {mountpoint: '/usr'},
  1923. {mountpoint: '/no-boot'},
  1924. {mountpoint: '/boot'}
  1925. ]
  1926. }
  1927. };
  1928. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1929. expect(host.get('cpu')).to.equal(2);
  1930. expect(host.get('os_type')).to.equal('t1');
  1931. expect(host.get('os_arch')).to.equal('os1');
  1932. expect(host.get('ip')).to.equal('0.0.0.0');
  1933. expect(host.get('memory')).to.equal('12345.00');
  1934. expect(host.get('disk_info.length')).to.equal(2);
  1935. });
  1936. });
  1937. describe('#getJDKName', function () {
  1938. beforeEach(function () {
  1939. sinon.stub($, 'ajax', Em.K);
  1940. sinon.stub(App, 'get', function (k) {
  1941. if ('testMode' === k) return false;
  1942. return Em.get(App, k);
  1943. });
  1944. });
  1945. afterEach(function () {
  1946. $.ajax.restore();
  1947. App.get.restore();
  1948. });
  1949. it('should do proper request to ambari-server', function () {
  1950. c.getJDKName();
  1951. expect($.ajax.args[0][0].type).to.contain('GET');
  1952. 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');
  1953. });
  1954. });
  1955. describe('#getJDKNameSuccessCallback', function () {
  1956. it('should set proper data to controller properties', function () {
  1957. var expected = {
  1958. name: 'name',
  1959. home: 'home',
  1960. location: 'location'
  1961. },
  1962. data = {
  1963. RootServiceComponents: {
  1964. properties: {
  1965. 'jdk.name': expected.name,
  1966. 'java.home': expected.home,
  1967. 'jdk_location': expected.location
  1968. }
  1969. }
  1970. };
  1971. c.getJDKNameSuccessCallback(data);
  1972. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  1973. expect(c.get('jdkLocation')).to.equal(expected.location);
  1974. expect(c.get('javaHome')).to.equal(expected.home);
  1975. });
  1976. });
  1977. describe('#doCheckJDK', function () {
  1978. beforeEach(function () {
  1979. sinon.stub($, 'ajax', Em.K);
  1980. sinon.stub(App, 'get', function (k) {
  1981. if ('testMode' === k) return false;
  1982. return Em.get(App, k);
  1983. });
  1984. });
  1985. afterEach(function () {
  1986. $.ajax.restore();
  1987. App.get.restore();
  1988. });
  1989. it('should do proper request to the ambari-server', function () {
  1990. var bootHosts = [
  1991. Em.Object.create({name: 'n1', bootStatus: 'REGISTERED'}),
  1992. Em.Object.create({name: 'n2', bootStatus: 'REGISTERED'})
  1993. ],
  1994. javaHome = '/java',
  1995. jdkLocation = '/jdk';
  1996. c.reopen({
  1997. bootHosts: bootHosts,
  1998. javaHome: javaHome,
  1999. jdkLocation: jdkLocation
  2000. });
  2001. c.doCheckJDK();
  2002. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  2003. expect(request.type).to.equal('POST');
  2004. expect(request.url).to.contain('/requests');
  2005. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  2006. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  2007. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  2008. });
  2009. });
  2010. describe('#doCheckJDKsuccessCallback', function () {
  2011. beforeEach(function () {
  2012. sinon.stub($, 'ajax', Em.K);
  2013. sinon.stub(App, 'get', function (k) {
  2014. if ('testMode' === k) return false;
  2015. return Em.get(App, k);
  2016. });
  2017. });
  2018. afterEach(function () {
  2019. $.ajax.restore();
  2020. App.get.restore();
  2021. });
  2022. it('should set jdkRequestIndex if data provided', function () {
  2023. var data = {
  2024. href: '/a/b/c'
  2025. },
  2026. expected = 'c';
  2027. c.set('jdkRequestIndex', null);
  2028. c.doCheckJDKsuccessCallback(data);
  2029. expect(c.get('jdkRequestIndex')).to.equal(expected);
  2030. });
  2031. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function () {
  2032. var data = null,
  2033. expected = true;
  2034. c.set('isJDKWarningsLoaded', false);
  2035. c.set('jdkCategoryWarnings', {});
  2036. c.doCheckJDKsuccessCallback(data);
  2037. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  2038. });
  2039. it('should do propert request to ambari-server', function () {
  2040. var data = null,
  2041. jdkRequestIndex = 'jdkRequestIndex',
  2042. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  2043. c.set('jdkRequestIndex', jdkRequestIndex);
  2044. c.set('jdkCategoryWarnings', null);
  2045. c.doCheckJDKsuccessCallback(data);
  2046. expect($.ajax.args[0][0].type).to.equal('GET');
  2047. expect($.ajax.args[0][0].url).to.contain(url);
  2048. });
  2049. });
  2050. describe('#doCheckJDKerrorCallback', function () {
  2051. it('should set isJDKWarningsLoaded to true', function () {
  2052. c.set('isJDKWarningsLoaded', false);
  2053. c.doCheckJDKerrorCallback();
  2054. c.set('isJDKWarningsLoaded', true);
  2055. });
  2056. });
  2057. describe('#parseJDKCheckResults', function () {
  2058. beforeEach(function () {
  2059. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  2060. });
  2061. afterEach(function () {
  2062. c.doCheckJDKsuccessCallback.restore();
  2063. });
  2064. it('should set jdkCategoryWarnings to null if no data', function () {
  2065. var data = {Requests: {}};
  2066. c.set('jdkCategoryWarnings', {});
  2067. c.parseJDKCheckResults(data);
  2068. expect(c.get('jdkCategoryWarnings')).to.be.null;
  2069. });
  2070. it('should parse warnings (1)', function () {
  2071. var data = {
  2072. Requests: {
  2073. end_time: 1
  2074. },
  2075. tasks: []
  2076. };
  2077. c.set('jdkCategoryWarnings', {});
  2078. c.parseJDKCheckResults(data);
  2079. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  2080. });
  2081. it('should parse warnings (2)', function () {
  2082. var data = {
  2083. Requests: {
  2084. end_time: 1
  2085. },
  2086. tasks: [
  2087. {
  2088. Tasks: {
  2089. host_name: 'h1',
  2090. structured_out: {
  2091. java_home_check: {
  2092. exit_code: 1
  2093. }
  2094. }
  2095. }
  2096. },
  2097. {
  2098. Tasks: {
  2099. host_name: 'h2',
  2100. structured_out: {
  2101. java_home_check: {
  2102. exit_code: 0
  2103. }
  2104. }
  2105. }
  2106. }
  2107. ]
  2108. };
  2109. c.set('jdkCategoryWarnings', {});
  2110. c.parseJDKCheckResults(data);
  2111. var result = c.get('jdkCategoryWarnings');
  2112. expect(result.length).to.equal(1);
  2113. expect(result[0].hostsNames).to.eql(['h1']);
  2114. });
  2115. });
  2116. describe('#getHostCheckTasksSuccess', function() {
  2117. beforeEach(function() {
  2118. sinon.stub($, 'ajax', Em.K);
  2119. sinon.stub(c, 'getHostInfo', Em.K);
  2120. sinon.stub(c, 'parseHostNameResolution', Em.K);
  2121. sinon.stub(c, 'getGeneralHostCheck', Em.K);
  2122. sinon.stub(c, 'getHostCheckTasks', Em.K);
  2123. });
  2124. afterEach(function() {
  2125. $.ajax.restore();
  2126. c.getHostInfo.restore();
  2127. c.parseHostNameResolution.restore();
  2128. c.getGeneralHostCheck.restore();
  2129. c.getHostCheckTasks.restore();
  2130. });
  2131. var dataInProgress = {
  2132. Requests: {
  2133. request_status: "IN_PROGRESS"
  2134. }
  2135. };
  2136. it('run getHostCheckTasks', function() {
  2137. c.getHostCheckTasksSuccess(dataInProgress);
  2138. expect(c.getHostCheckTasks.calledOnce).to.be.true;
  2139. });
  2140. var hostResolutionCheckComplete = {
  2141. Requests: {
  2142. request_status: "COMPLETED",
  2143. inputs: "host_resolution_check"
  2144. }
  2145. };
  2146. it('run parseHostNameResolution and getGeneralHostCheck', function() {
  2147. c.getHostCheckTasksSuccess(hostResolutionCheckComplete);
  2148. expect(c.parseHostNameResolution.calledWith(hostResolutionCheckComplete)).to.be.true;
  2149. expect(c.getGeneralHostCheck.calledOnce).to.be.true;
  2150. });
  2151. var lastAgentEnvCheckComplete = {
  2152. Requests: {
  2153. request_status: "COMPLETED",
  2154. inputs: "last_agent_env_check"
  2155. },
  2156. tasks: [
  2157. {
  2158. Tasks: {
  2159. host_name: 'h1',
  2160. structured_out: {
  2161. "installed_packages": [
  2162. {
  2163. "version": "b1",
  2164. "name": "n1",
  2165. "repoName": "r1"
  2166. },
  2167. {
  2168. "version": "b2",
  2169. "name": "n2",
  2170. "repoName": "r2"
  2171. }
  2172. ]
  2173. }
  2174. }
  2175. }
  2176. ]
  2177. };
  2178. it('run getHostInfo', function() {
  2179. c.getHostCheckTasksSuccess(lastAgentEnvCheckComplete);
  2180. expect(c.get('stopChecking')).to.be.true;
  2181. expect(c.getHostInfo.calledOnce).to.be.true;
  2182. expect(c.get('hostsPackagesData')).eql([
  2183. {
  2184. hostName: 'h1',
  2185. installedPackages: [
  2186. {
  2187. "version": "b1",
  2188. "name": "n1",
  2189. "repoName": "r1"
  2190. },
  2191. {
  2192. "version": "b2",
  2193. "name": "n2",
  2194. "repoName": "r2"
  2195. }
  2196. ]
  2197. }
  2198. ]);
  2199. });
  2200. });
  2201. describe('#getDataForCheckRequest', function() {
  2202. var tests = [
  2203. {
  2204. bootHosts: [
  2205. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2206. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2207. ],
  2208. addHosts: true,
  2209. rez: {
  2210. RequestInfo: {
  2211. "action": "check_host",
  2212. "context": "Check host",
  2213. "parameters": {
  2214. "check_execute_list": 'checkExecuteList',
  2215. "jdk_location" : "jdk_location",
  2216. "threshold": "20",
  2217. "hosts": "h1"
  2218. }
  2219. },
  2220. resource_filters: {
  2221. "hosts": "h1"
  2222. }
  2223. },
  2224. m: 'with add host param'
  2225. },
  2226. {
  2227. bootHosts: [
  2228. Em.Object.create({'bootStatus': 'REGISTERED', 'name': 'h1'}),
  2229. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2230. ],
  2231. addHosts: false,
  2232. rez: {
  2233. RequestInfo: {
  2234. "action": "check_host",
  2235. "context": "Check host",
  2236. "parameters": {
  2237. "check_execute_list": 'checkExecuteList',
  2238. "jdk_location" : "jdk_location",
  2239. "threshold": "20"
  2240. }
  2241. },
  2242. resource_filters: {
  2243. "hosts": "h1"
  2244. }
  2245. },
  2246. m: 'without add host param'
  2247. },
  2248. {
  2249. bootHosts: [
  2250. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h1'}),
  2251. Em.Object.create({'bootStatus': 'FAILED', 'name': 'h2'})
  2252. ],
  2253. rez: null,
  2254. m: 'with all hosts failed'
  2255. }
  2256. ];
  2257. beforeEach(function() {
  2258. sinon.stub(App.get('router'), 'get' , function(p) {
  2259. return p === 'clusterController.ambariProperties.jdk_location' ? 'jdk_location' : Em.get(App.get('router'), p);
  2260. })
  2261. });
  2262. afterEach(function() {
  2263. App.get('router').get.restore();
  2264. });
  2265. tests.forEach(function(t) {
  2266. it(t.m, function() {
  2267. c.set('bootHosts', t.bootHosts);
  2268. expect(c.getDataForCheckRequest('checkExecuteList', t.addHosts)).to.be.eql(t.rez);
  2269. });
  2270. })
  2271. });
  2272. });