step3_test.js 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535
  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. },
  481. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } }
  482. },
  483. agentUser: 'user'
  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, isRetryDisabled: true}
  939. },
  940. {
  941. bootHosts: [
  942. Em.Object.create({bootStatus: 'FAILED'}),
  943. Em.Object.create({bootStatus: 'RUNNING'})
  944. ],
  945. e: {isSubmitDisabled: true, isRetryDisabled: false}
  946. },
  947. {
  948. bootHosts: [
  949. Em.Object.create({bootStatus: 'FAILED'}),
  950. Em.Object.create({bootStatus: 'REGISTERED'})
  951. ],
  952. e: {isSubmitDisabled: false, isRetryDisabled: false}
  953. },
  954. {
  955. bootHosts: [
  956. Em.Object.create({bootStatus: 'RUNNING'}),
  957. Em.Object.create({bootStatus: 'RUNNING'})
  958. ],
  959. e: {isSubmitDisabled: true, isRetryDisabled: 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. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  968. });
  969. });
  970. });
  971. describe('#submit', function () {
  972. beforeEach(function () {
  973. sinon.spy(App.ModalPopup, 'show');
  974. });
  975. afterEach(function () {
  976. App.ModalPopup.show.restore();
  977. });
  978. it('if isHostHaveWarnings should show confirmation popup', function () {
  979. c.reopen({isHostHaveWarnings: true});
  980. c.submit();
  981. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  982. });
  983. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function () {
  984. var bootHosts = [
  985. Em.Object.create({name: 'c1'})
  986. ];
  987. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  988. c.submit().onPrimary();
  989. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  990. });
  991. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function () {
  992. var bootHosts = [
  993. Em.Object.create({name: 'c1'})
  994. ];
  995. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  996. c.submit();
  997. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  998. });
  999. });
  1000. describe('#hostLogPopup', function () {
  1001. beforeEach(function () {
  1002. sinon.spy(App.ModalPopup, 'show');
  1003. });
  1004. afterEach(function () {
  1005. App.ModalPopup.show.restore();
  1006. });
  1007. it('should show App.ModalPopup', function () {
  1008. c.hostLogPopup({context: Em.Object.create({})});
  1009. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1010. });
  1011. });
  1012. describe('#rerunChecksSuccessCallback', function () {
  1013. beforeEach(function () {
  1014. sinon.stub(c, 'parseWarnings', Em.K);
  1015. });
  1016. afterEach(function () {
  1017. c.parseWarnings.restore();
  1018. });
  1019. it('should set checksUpdateProgress to 100', function () {
  1020. c.set('checksUpdateProgress', 0);
  1021. c.rerunChecksSuccessCallback({items: []});
  1022. expect(c.get('checksUpdateProgress')).to.equal(100);
  1023. });
  1024. it('should set checksUpdateStatus to SUCCESS', function () {
  1025. c.set('checksUpdateStatus', '');
  1026. c.rerunChecksSuccessCallback({items: []});
  1027. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  1028. });
  1029. it('should call parseWarnings', function () {
  1030. c.rerunChecksSuccessCallback({items: []});
  1031. expect(c.parseWarnings.calledOnce).to.equal(true);
  1032. });
  1033. });
  1034. describe('#rerunChecksErrorCallback', function () {
  1035. it('should set checksUpdateProgress to 100', function () {
  1036. c.set('checksUpdateProgress', 0);
  1037. c.rerunChecksErrorCallback({});
  1038. expect(c.get('checksUpdateProgress')).to.equal(100);
  1039. });
  1040. it('should set checksUpdateStatus to FAILED', function () {
  1041. c.set('checksUpdateStatus', '');
  1042. c.rerunChecksErrorCallback({});
  1043. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  1044. });
  1045. });
  1046. describe('#filterBootHosts', function () {
  1047. var tests = Em.A([
  1048. {
  1049. bootHosts: [
  1050. Em.Object.create({name: 'c1'}),
  1051. Em.Object.create({name: 'c2'})
  1052. ],
  1053. data: {
  1054. items: [
  1055. {Hosts: {host_name: 'c1'}}
  1056. ]
  1057. },
  1058. m: 'one host',
  1059. e: ['c1']
  1060. },
  1061. {
  1062. bootHosts: [
  1063. Em.Object.create({name: 'c1'}),
  1064. Em.Object.create({name: 'c2'})
  1065. ],
  1066. data: {
  1067. items: [
  1068. {Hosts: {host_name: 'c3'}}
  1069. ]
  1070. },
  1071. m: 'no hosts',
  1072. e: []
  1073. },
  1074. {
  1075. bootHosts: [
  1076. Em.Object.create({name: 'c1'}),
  1077. Em.Object.create({name: 'c2'})
  1078. ],
  1079. data: {
  1080. items: [
  1081. {Hosts: {host_name: 'c1'}},
  1082. {Hosts: {host_name: 'c2'}}
  1083. ]
  1084. },
  1085. m: 'many hosts',
  1086. e: ['c1', 'c2']
  1087. }
  1088. ]);
  1089. tests.forEach(function (test) {
  1090. it(test.m, function () {
  1091. c.reopen({bootHosts: test.bootHosts});
  1092. var filteredData = c.filterBootHosts(test.data);
  1093. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1094. });
  1095. });
  1096. });
  1097. describe('#hostWarningsPopup', function () {
  1098. beforeEach(function () {
  1099. sinon.spy(App.ModalPopup, 'show');
  1100. sinon.stub(c, 'rerunChecks', Em.K);
  1101. });
  1102. afterEach(function () {
  1103. App.ModalPopup.show.restore();
  1104. c.rerunChecks.restore();
  1105. });
  1106. it('should show App.ModalPopup', function () {
  1107. c.hostWarningsPopup();
  1108. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1109. });
  1110. it('should clear checksUpdateStatus on primary', function () {
  1111. c.set('checksUpdateStatus', 'not null value');
  1112. c.hostWarningsPopup().onPrimary();
  1113. expect(c.get('checksUpdateStatus')).to.be.null;
  1114. });
  1115. it('should clear checksUpdateStatus on close', function () {
  1116. c.set('checksUpdateStatus', 'not null value');
  1117. c.hostWarningsPopup().onClose();
  1118. expect(c.get('checksUpdateStatus')).to.be.null;
  1119. });
  1120. it('should rerunChecks onSecondary', function () {
  1121. c.hostWarningsPopup().onSecondary();
  1122. expect(c.rerunChecks.calledOnce).to.equal(true);
  1123. });
  1124. });
  1125. describe('#registeredHostsPopup', function () {
  1126. beforeEach(function () {
  1127. sinon.spy(App.ModalPopup, 'show');
  1128. });
  1129. afterEach(function () {
  1130. App.ModalPopup.show.restore();
  1131. });
  1132. it('should show App.ModalPopup', function () {
  1133. c.registeredHostsPopup();
  1134. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1135. });
  1136. });
  1137. describe('#parseWarnings', function () {
  1138. beforeEach(function () {
  1139. sinon.stub(App, 'get', function (k) {
  1140. if ('testMode' === k) return false;
  1141. return Em.get(App, k);
  1142. });
  1143. sinon.stub(c, 'filterBootHosts', function (k) {
  1144. return k;
  1145. });
  1146. });
  1147. afterEach(function () {
  1148. App.get.restore();
  1149. c.filterBootHosts.restore();
  1150. });
  1151. it('no warnings if last_agent_env isn\'t specified', function () {
  1152. c.set('warnings', [
  1153. {}
  1154. ]);
  1155. c.set('warningsByHost', [
  1156. {},
  1157. {}
  1158. ]);
  1159. c.parseWarnings({items: [
  1160. {Hosts: {host_name: 'c1'}}
  1161. ]});
  1162. expect(c.get('warnings')).to.eql([]);
  1163. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1164. });
  1165. Em.A([
  1166. {
  1167. m: 'parse stackFoldersAndFiles',
  1168. tests: Em.A([
  1169. {
  1170. items: [
  1171. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}
  1172. ],
  1173. m: 'empty stackFoldersAndFiles',
  1174. e: {
  1175. warnings: [],
  1176. warningsByHost: [0]
  1177. }
  1178. },
  1179. {
  1180. items: [
  1181. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1182. {name: 'n1'}
  1183. ]}}}
  1184. ],
  1185. m: 'not empty stackFoldersAndFiles',
  1186. e: {
  1187. warnings: [
  1188. {
  1189. name: 'n1',
  1190. hosts: ['c1'],
  1191. onSingleHost: true,
  1192. category: 'fileFolders'
  1193. }
  1194. ],
  1195. warningsByHost: [1]
  1196. }
  1197. },
  1198. {
  1199. items: [
  1200. {Hosts: {host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [
  1201. {name: 'n1'}
  1202. ]}}},
  1203. {Hosts: {host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [
  1204. {name: 'n1'}
  1205. ]}}}
  1206. ],
  1207. m: 'not empty stackFoldersAndFiles on two hosts',
  1208. e: {
  1209. warnings: [
  1210. {
  1211. name: 'n1',
  1212. hosts: ['c1', 'c2'],
  1213. onSingleHost: false,
  1214. category: 'fileFolders'
  1215. }
  1216. ],
  1217. warningsByHost: [1]
  1218. }
  1219. }
  1220. ])
  1221. },
  1222. {
  1223. m: 'parse installedPackages',
  1224. tests: Em.A([
  1225. {
  1226. items: [
  1227. {Hosts: {host_name: 'c1', last_agent_env: {installedPackages: []}}}
  1228. ],
  1229. m: 'empty installedPackages',
  1230. e: {
  1231. warnings: [],
  1232. warningsByHost: [0]
  1233. }
  1234. },
  1235. {
  1236. items: [
  1237. {Hosts: {host_name: 'c1', last_agent_env: {installedPackages: [
  1238. {name: 'n1'}
  1239. ]}}}
  1240. ],
  1241. m: 'not empty installedPackages',
  1242. e: {
  1243. warnings: [
  1244. {
  1245. name: 'n1',
  1246. hosts: ['c1'],
  1247. onSingleHost: true,
  1248. category: 'packages'
  1249. }
  1250. ],
  1251. warningsByHost: [1]
  1252. }
  1253. },
  1254. {
  1255. items: [
  1256. {Hosts: {host_name: 'c1', last_agent_env: {installedPackages: [
  1257. {name: 'n1'}
  1258. ]}}},
  1259. {Hosts: {host_name: 'c2', last_agent_env: {installedPackages: [
  1260. {name: 'n1'}
  1261. ]}}}
  1262. ],
  1263. m: 'not empty installedPackages on two hosts',
  1264. e: {
  1265. warnings: [
  1266. {
  1267. name: 'n1',
  1268. hosts: ['c1', 'c2'],
  1269. onSingleHost: false,
  1270. category: 'packages'
  1271. }
  1272. ],
  1273. warningsByHost: [1]
  1274. }
  1275. }
  1276. ])
  1277. },
  1278. {
  1279. m: 'parse hostHealth.liveServices',
  1280. tests: Em.A([
  1281. {
  1282. items: [
  1283. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: []}}}
  1284. ],
  1285. m: 'empty hostHealth',
  1286. e: {
  1287. warnings: [],
  1288. warningsByHost: [0]
  1289. }
  1290. },
  1291. {
  1292. items: [
  1293. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: []}}}}
  1294. ],
  1295. m: 'empty liveServices',
  1296. e: {
  1297. warnings: [],
  1298. warningsByHost: [0]
  1299. }
  1300. },
  1301. {
  1302. items: [
  1303. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1304. {status: 'Unhealthy', name: 'n1'}
  1305. ]}}}}
  1306. ],
  1307. m: 'not empty hostHealth.liveServices',
  1308. e: {
  1309. warnings: [
  1310. {
  1311. name: 'n1',
  1312. hosts: ['c1'],
  1313. onSingleHost: true,
  1314. category: 'services'
  1315. }
  1316. ],
  1317. warningsByHost: [1]
  1318. }
  1319. },
  1320. {
  1321. items: [
  1322. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {liveServices: [
  1323. {status: 'Unhealthy', name: 'n1'}
  1324. ]}}}},
  1325. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {liveServices: [
  1326. {status: 'Unhealthy', name: 'n1'}
  1327. ]}}}}
  1328. ],
  1329. m: 'not empty hostHealth.liveServices on two hosts',
  1330. e: {
  1331. warnings: [
  1332. {
  1333. name: 'n1',
  1334. hosts: ['c1', 'c2'],
  1335. onSingleHost: false,
  1336. category: 'services'
  1337. }
  1338. ],
  1339. warningsByHost: [1, 1]
  1340. }
  1341. }
  1342. ])
  1343. },
  1344. {
  1345. m: 'parse existingUsers',
  1346. tests: Em.A([
  1347. {
  1348. items: [
  1349. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: []}}}
  1350. ],
  1351. m: 'empty existingUsers',
  1352. e: {
  1353. warnings: [],
  1354. warningsByHost: [0]
  1355. }
  1356. },
  1357. {
  1358. items: [
  1359. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1360. {userName: 'n1'}
  1361. ]}}}
  1362. ],
  1363. m: 'not empty existingUsers',
  1364. e: {
  1365. warnings: [
  1366. {
  1367. name: 'n1',
  1368. hosts: ['c1'],
  1369. onSingleHost: true,
  1370. category: 'users'
  1371. }
  1372. ],
  1373. warningsByHost: [1]
  1374. }
  1375. },
  1376. {
  1377. items: [
  1378. {Hosts: {host_name: 'c1', last_agent_env: {existingUsers: [
  1379. {userName: 'n1'}
  1380. ]}}},
  1381. {Hosts: {host_name: 'c2', last_agent_env: {existingUsers: [
  1382. {userName: 'n1'}
  1383. ]}}}
  1384. ],
  1385. m: 'not empty existingUsers on two hosts',
  1386. e: {
  1387. warnings: [
  1388. {
  1389. name: 'n1',
  1390. hosts: ['c1', 'c2'],
  1391. onSingleHost: false,
  1392. category: 'users'
  1393. }
  1394. ],
  1395. warningsByHost: [1, 1]
  1396. }
  1397. }
  1398. ])
  1399. },
  1400. {
  1401. m: 'parse alternatives',
  1402. tests: Em.A([
  1403. {
  1404. items: [
  1405. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: []}}}
  1406. ],
  1407. m: 'empty alternatives',
  1408. e: {
  1409. warnings: [],
  1410. warningsByHost: [0]
  1411. }
  1412. },
  1413. {
  1414. items: [
  1415. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1416. {name: 'n1'}
  1417. ]}}}
  1418. ],
  1419. m: 'not empty alternatives',
  1420. e: {
  1421. warnings: [
  1422. {
  1423. name: 'n1',
  1424. hosts: ['c1'],
  1425. onSingleHost: true,
  1426. category: 'alternatives'
  1427. }
  1428. ],
  1429. warningsByHost: [1]
  1430. }
  1431. },
  1432. {
  1433. items: [
  1434. {Hosts: {host_name: 'c1', last_agent_env: {alternatives: [
  1435. {name: 'n1'}
  1436. ]}}},
  1437. {Hosts: {host_name: 'c2', last_agent_env: {alternatives: [
  1438. {name: 'n1'}
  1439. ]}}}
  1440. ],
  1441. m: 'not empty alternatives on two hosts',
  1442. e: {
  1443. warnings: [
  1444. {
  1445. name: 'n1',
  1446. hosts: ['c1', 'c2'],
  1447. onSingleHost: false,
  1448. category: 'alternatives'
  1449. }
  1450. ],
  1451. warningsByHost: [1, 1]
  1452. }
  1453. }
  1454. ])
  1455. },
  1456. {
  1457. m: 'parse hostHealth.activeJavaProcs',
  1458. tests: Em.A([
  1459. {
  1460. items: [
  1461. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}
  1462. ],
  1463. m: 'empty hostHealth',
  1464. e: {
  1465. warnings: [],
  1466. warningsByHost: [0]
  1467. }
  1468. },
  1469. {
  1470. items: [
  1471. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: []}}}}
  1472. ],
  1473. m: 'empty activeJavaProcs',
  1474. e: {
  1475. warnings: [],
  1476. warningsByHost: [0]
  1477. }
  1478. },
  1479. {
  1480. items: [
  1481. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1482. {pid: 'n1', command: ''}
  1483. ]}}}}
  1484. ],
  1485. m: 'not empty hostHealth.activeJavaProcs',
  1486. e: {
  1487. warnings: [
  1488. {
  1489. pid: 'n1',
  1490. hosts: ['c1'],
  1491. onSingleHost: true,
  1492. category: 'processes'
  1493. }
  1494. ],
  1495. warningsByHost: [1]
  1496. }
  1497. },
  1498. {
  1499. items: [
  1500. {Hosts: {host_name: 'c1', last_agent_env: {hostHealth: {activeJavaProcs: [
  1501. {pid: 'n1', command: ''}
  1502. ]}}}},
  1503. {Hosts: {host_name: 'c2', last_agent_env: {hostHealth: {activeJavaProcs: [
  1504. {pid: 'n1', command: ''}
  1505. ]}}}}
  1506. ],
  1507. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1508. e: {
  1509. warnings: [
  1510. {
  1511. pid: 'n1',
  1512. hosts: ['c1', 'c2'],
  1513. onSingleHost: false,
  1514. category: 'processes'
  1515. }
  1516. ],
  1517. warningsByHost: [1, 1]
  1518. }
  1519. }
  1520. ])
  1521. }
  1522. ]).forEach(function (category) {
  1523. describe(category.m, function () {
  1524. category.tests.forEach(function (test) {
  1525. it(test.m, function () {
  1526. c.parseWarnings({items: test.items});
  1527. c.get('warnings').forEach(function (w, i) {
  1528. Em.keys(test.e.warnings[i]).forEach(function (k) {
  1529. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1530. });
  1531. });
  1532. for (var i in test.e.warningsByHost) {
  1533. if (test.e.warningsByHost.hasOwnProperty(i)) {
  1534. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1535. }
  1536. }
  1537. });
  1538. });
  1539. });
  1540. });
  1541. it('should parse umask warnings', function () {
  1542. var items = [
  1543. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1544. {Hosts: {host_name: 'c2', last_agent_env: {umask: 1}}}
  1545. ];
  1546. c.parseWarnings({items: items});
  1547. var warnings = c.get('warnings');
  1548. expect(warnings.length).to.equal(1);
  1549. expect(warnings[0].hosts).to.eql(['c1']);
  1550. expect(warnings[0].onSingleHost).to.equal(true);
  1551. });
  1552. it('should parse umask warnings (2)', function () {
  1553. var items = [
  1554. {Hosts: {host_name: 'c1', last_agent_env: {umask: 24}}},
  1555. {Hosts: {host_name: 'c2', last_agent_env: {umask: 25}}}
  1556. ];
  1557. c.parseWarnings({items: items});
  1558. var warnings = c.get('warnings');
  1559. expect(warnings.length).to.equal(2);
  1560. expect(warnings.mapProperty('hosts')).to.eql([
  1561. ['c1'],
  1562. ['c2']
  1563. ]);
  1564. });
  1565. it('should parse firewall warnings', function () {
  1566. var items = [
  1567. {Hosts: {host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1568. {Hosts: {host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
  1569. ];
  1570. c.parseWarnings({items: items});
  1571. var warnings = c.get('warnings');
  1572. expect(warnings.length).to.equal(1);
  1573. expect(warnings[0].hosts).to.eql(['c1']);
  1574. expect(warnings[0].onSingleHost).to.equal(true);
  1575. });
  1576. it('should parse firewall warnings (2)', function () {
  1577. var items = [
  1578. {Hosts: {host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1579. {Hosts: {host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
  1580. ];
  1581. c.parseWarnings({items: items});
  1582. var warnings = c.get('warnings');
  1583. expect(warnings.length).to.equal(1);
  1584. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1585. expect(warnings[0].onSingleHost).to.equal(false);
  1586. });
  1587. it('should parse reverseLookup warnings', function () {
  1588. var items = [
  1589. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1590. ];
  1591. c.parseWarnings({items: items});
  1592. var warnings = c.get('warnings');
  1593. expect(warnings.length).to.equal(0);
  1594. });
  1595. it('should parse reverseLookup warnings (2)', function () {
  1596. var items = [
  1597. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1598. ];
  1599. c.parseWarnings({items: items});
  1600. var warnings = c.get('warnings');
  1601. expect(warnings.length).to.equal(1);
  1602. expect(warnings[0].hosts).to.eql(['c1']);
  1603. expect(warnings[0].onSingleHost).to.equal(true);
  1604. });
  1605. it('should parse reverseLookup warnings (3)', function () {
  1606. var items = [
  1607. {Hosts: {host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1608. {Hosts: {host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1609. ];
  1610. c.parseWarnings({items: items});
  1611. var warnings = c.get('warnings');
  1612. expect(warnings.length).to.equal(1);
  1613. expect(warnings[0].hosts).to.eql(['c1', 'c2']);
  1614. expect(warnings[0].onSingleHost).to.equal(false);
  1615. });
  1616. });
  1617. describe('#navigateStep', function () {
  1618. beforeEach(function () {
  1619. sinon.stub(c, 'setupBootStrap', Em.K);
  1620. });
  1621. afterEach(function () {
  1622. c.setupBootStrap.restore();
  1623. });
  1624. Em.A([
  1625. {
  1626. isLoaded: true,
  1627. manualInstall: false,
  1628. bootStatus: false,
  1629. m: 'should call setupBootStrap',
  1630. e: true
  1631. },
  1632. {
  1633. isLoaded: true,
  1634. manualInstall: false,
  1635. bootStatus: true,
  1636. m: 'shouldn\'t call setupBootStrap (1)',
  1637. e: false
  1638. },
  1639. {
  1640. isLoaded: false,
  1641. manualInstall: false,
  1642. bootStatus: false,
  1643. m: 'shouldn\'t call setupBootStrap (2)',
  1644. e: false
  1645. },
  1646. {
  1647. isLoaded: false,
  1648. manualInstall: true,
  1649. bootStatus: false,
  1650. m: 'shouldn\'t call setupBootStrap (3)',
  1651. e: false
  1652. }
  1653. ]).forEach(function (test) {
  1654. it(test.m, function () {
  1655. c.reopen({
  1656. isLoaded: test.isLoaded,
  1657. content: {
  1658. installedHosts: [],
  1659. installOptions: {
  1660. manualInstall: test.manualInstall
  1661. }
  1662. },
  1663. wizardController: Em.Object.create({
  1664. getDBProperty: function () {
  1665. return test.bootStatus
  1666. }
  1667. })
  1668. });
  1669. c.navigateStep();
  1670. if (test.e) {
  1671. expect(c.setupBootStrap.calledOnce).to.equal(true);
  1672. }
  1673. else {
  1674. expect(c.setupBootStrap.called).to.equal(false);
  1675. }
  1676. });
  1677. });
  1678. it('should set test data if testMode is true', function () {
  1679. c.reopen({
  1680. isLoaded: true,
  1681. hosts: [
  1682. {},
  1683. {},
  1684. {}
  1685. ],
  1686. content: {
  1687. installedHosts: [],
  1688. installOptions: {
  1689. manualInstall: true
  1690. }
  1691. },
  1692. setRegistrationInProgress: Em.K
  1693. });
  1694. sinon.stub(App, 'get', function (k) {
  1695. if ('testMode' === k) return true;
  1696. return Em.get(App, k);
  1697. });
  1698. c.navigateStep();
  1699. App.get.restore();
  1700. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1701. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1702. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1703. expect(c.get('isSubmitDisabled')).to.equal(false);
  1704. });
  1705. it('should start registration', function () {
  1706. c.reopen({
  1707. isLoaded: true,
  1708. hosts: [
  1709. {},
  1710. {},
  1711. {}
  1712. ],
  1713. content: {
  1714. installedHosts: [],
  1715. installOptions: {
  1716. manualInstall: true
  1717. }
  1718. },
  1719. setRegistrationInProgress: Em.K,
  1720. startRegistration: Em.K
  1721. });
  1722. sinon.stub(App, 'get', function (k) {
  1723. if ('testMode' === k) return false;
  1724. return Em.get(App, k);
  1725. });
  1726. sinon.spy(c, 'startRegistration');
  1727. c.navigateStep();
  1728. App.get.restore();
  1729. expect(c.startRegistration.calledOnce).to.equal(true);
  1730. c.startRegistration.restore();
  1731. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1732. expect(c.get('registrationStartedAt')).to.be.null;
  1733. });
  1734. });
  1735. describe('#setupBootStrap', function () {
  1736. var cases = [
  1737. {
  1738. customizeAgentUserAccount: true,
  1739. userRunAs: 'user',
  1740. title: 'Ambari Agent user account customize enabled'
  1741. },
  1742. {
  1743. customizeAgentUserAccount: false,
  1744. userRunAs: 'root',
  1745. title: 'Ambari Agent user account customize disabled'
  1746. }
  1747. ],
  1748. controller = App.WizardStep3Controller.create({
  1749. content: {
  1750. installOptions: {
  1751. sshKey: 'key',
  1752. sshUser: 'root'
  1753. },
  1754. hosts: { "host0": { "name": "host0" }, "host1": { "name": "host1" } },
  1755. controllerName: 'installerController'
  1756. },
  1757. agentUser: 'user'
  1758. });
  1759. beforeEach(function () {
  1760. sinon.stub(App.router.get('installerController'), 'launchBootstrap', Em.K);
  1761. this.mock = sinon.stub(App, 'get');
  1762. });
  1763. afterEach(function () {
  1764. App.router.get('installerController').launchBootstrap.restore();
  1765. this.mock.restore();
  1766. });
  1767. cases.forEach(function (item) {
  1768. it(item.title, function () {
  1769. this.mock.withArgs('supports.customizeAgentUserAccount').returns(item.customizeAgentUserAccount);
  1770. controller.setupBootStrap();
  1771. expect(App.router.get('installerController.launchBootstrap').firstCall.args[0]).to.equal(JSON.stringify({
  1772. verbose: true,
  1773. sshKey: 'key',
  1774. hosts: ['host0', 'host1'],
  1775. user: 'root',
  1776. userRunAs: item.userRunAs
  1777. }));
  1778. });
  1779. });
  1780. });
  1781. describe('#checkHostDiskSpace', function () {
  1782. Em.A([
  1783. {
  1784. diskInfo: [
  1785. {
  1786. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1787. mountpoint: '/'
  1788. }
  1789. ],
  1790. m: 'available less than App.minDiskSpace',
  1791. e: false
  1792. },
  1793. {
  1794. diskInfo: [
  1795. {
  1796. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1797. mountpoint: '/usr'
  1798. }
  1799. ],
  1800. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1801. e: false
  1802. },
  1803. {
  1804. diskInfo: [
  1805. {
  1806. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1807. mountpoint: '/usr/lib'
  1808. }
  1809. ],
  1810. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1811. e: false
  1812. },
  1813. {
  1814. diskInfo: [
  1815. {
  1816. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1817. mountpoint: '/'
  1818. }
  1819. ],
  1820. m: 'available greater than App.minDiskSpace',
  1821. e: true
  1822. },
  1823. {
  1824. diskInfo: [
  1825. {
  1826. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1827. mountpoint: '/usr'
  1828. }
  1829. ],
  1830. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1831. e: true
  1832. },
  1833. {
  1834. diskInfo: [
  1835. {
  1836. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1837. mountpoint: '/usr/lib'
  1838. }
  1839. ],
  1840. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1841. e: true
  1842. },
  1843. {
  1844. diskInfo: [
  1845. {
  1846. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1847. mountpoint: '/home/tdk'
  1848. }
  1849. ],
  1850. m: 'mount point without free space checks',
  1851. e: true
  1852. }
  1853. ]).forEach(function (test) {
  1854. it(test.m, function () {
  1855. var r = c.checkHostDiskSpace('', test.diskInfo);
  1856. expect(Em.isEmpty(r)).to.equal(test.e);
  1857. });
  1858. });
  1859. });
  1860. describe('#checkHostOSType', function () {
  1861. it('should return empty string if no stacks provided', function () {
  1862. c.reopen({content: {stacks: null}});
  1863. expect(c.checkHostOSType()).to.equal('');
  1864. });
  1865. it('os type is valid', function () {
  1866. var osType = 'redhat6';
  1867. c.reopen({
  1868. content: {
  1869. stacks: [
  1870. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1871. ]
  1872. }
  1873. });
  1874. expect(c.checkHostOSType(osType, '')).to.equal('');
  1875. });
  1876. it('os type is invalid', function () {
  1877. var osType = 'os2';
  1878. c.reopen({
  1879. content: {
  1880. stacks: [
  1881. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1882. ]
  1883. }
  1884. });
  1885. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1886. });
  1887. });
  1888. describe('#getHostInfoSuccessCallback', function () {
  1889. beforeEach(function () {
  1890. sinon.stub(c, 'parseWarnings', Em.K);
  1891. sinon.stub(c, 'stopRegistration', Em.K);
  1892. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1893. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1894. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1895. });
  1896. afterEach(function () {
  1897. c.parseWarnings.restore();
  1898. c.stopRegistration.restore();
  1899. c.checkHostDiskSpace.restore();
  1900. c._setHostDataFromLoadedHostInfo.restore();
  1901. c._setHostDataWithSkipBootstrap.restore();
  1902. });
  1903. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function () {
  1904. sinon.stub(App, 'get', function (k) {
  1905. if ('skipBootstrap' === k) return true;
  1906. if ('testMode' === k) return false;
  1907. return Em.get(App, k);
  1908. });
  1909. c.reopen({
  1910. bootHosts: [Em.Object.create({name: 'h1'})]
  1911. });
  1912. var jsonData = {items: [
  1913. {Hosts: {host_name: 'h1'}}
  1914. ]};
  1915. c.getHostInfoSuccessCallback(jsonData);
  1916. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1917. App.get.restore();
  1918. });
  1919. it('should add repo warnings', function () {
  1920. var jsonData = {items: [
  1921. {Hosts: {host_name: 'h1'}}
  1922. ]};
  1923. sinon.stub(c, 'checkHostOSType', function () {
  1924. return 'not_null_value';
  1925. });
  1926. sinon.stub(App, 'get', function (k) {
  1927. if ('skipBootstrap' === k) return false;
  1928. if ('testMode' === k) return false;
  1929. return Em.get(App, k);
  1930. });
  1931. c.reopen({
  1932. bootHosts: [Em.Object.create({name: 'h1'})]
  1933. });
  1934. c.getHostInfoSuccessCallback(jsonData);
  1935. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1936. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1937. c.checkHostOSType.restore();
  1938. App.get.restore();
  1939. });
  1940. it('should add disk warnings', function () {
  1941. var jsonData = {items: [
  1942. {Hosts: {host_name: 'h1'}}
  1943. ]};
  1944. sinon.stub(App, 'get', function (k) {
  1945. if ('skipBootstrap' === k) return false;
  1946. if ('testMode' === k) return false;
  1947. return Em.get(App, k);
  1948. });
  1949. c.reopen({
  1950. bootHosts: [Em.Object.create({name: 'h1'})]
  1951. });
  1952. c.getHostInfoSuccessCallback(jsonData);
  1953. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1954. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1955. App.get.restore();
  1956. });
  1957. });
  1958. describe('#_setHostDataWithSkipBootstrap', function () {
  1959. it('should set mock-data', function () {
  1960. var host = Em.Object.create({});
  1961. c._setHostDataWithSkipBootstrap(host);
  1962. expect(host.get('cpu')).to.equal(2);
  1963. expect(host.get('memory')).to.equal('2000000.00');
  1964. expect(host.get('disk_info.length')).to.equal(4);
  1965. });
  1966. });
  1967. describe('#_setHostDataFromLoadedHostInfo', function () {
  1968. it('should set data from hostInfo', function () {
  1969. var host = Em.Object.create(),
  1970. hostInfo = {
  1971. Hosts: {
  1972. cpu_count: 2,
  1973. total_mem: 12345,
  1974. os_type: 't1',
  1975. os_arch: 'os1',
  1976. ip: '0.0.0.0',
  1977. disk_info: [
  1978. {mountpoint: '/boot'},
  1979. {mountpoint: '/usr'},
  1980. {mountpoint: '/no-boot'},
  1981. {mountpoint: '/boot'}
  1982. ]
  1983. }
  1984. };
  1985. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1986. expect(host.get('cpu')).to.equal(2);
  1987. expect(host.get('os_type')).to.equal('t1');
  1988. expect(host.get('os_arch')).to.equal('os1');
  1989. expect(host.get('ip')).to.equal('0.0.0.0');
  1990. expect(host.get('memory')).to.equal('12345.00');
  1991. expect(host.get('disk_info.length')).to.equal(2);
  1992. });
  1993. });
  1994. describe('#getJDKName', function () {
  1995. beforeEach(function () {
  1996. sinon.stub($, 'ajax', Em.K);
  1997. sinon.stub(App, 'get', function (k) {
  1998. if ('testMode' === k) return false;
  1999. return Em.get(App, k);
  2000. });
  2001. });
  2002. afterEach(function () {
  2003. $.ajax.restore();
  2004. App.get.restore();
  2005. });
  2006. it('should do proper request to ambari-server', function () {
  2007. c.getJDKName();
  2008. expect($.ajax.args[0][0].type).to.contain('GET');
  2009. 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');
  2010. });
  2011. });
  2012. describe('#getJDKNameSuccessCallback', function () {
  2013. it('should set proper data to controller properties', function () {
  2014. var expected = {
  2015. name: 'name',
  2016. home: 'home',
  2017. location: 'location'
  2018. },
  2019. data = {
  2020. RootServiceComponents: {
  2021. properties: {
  2022. 'jdk.name': expected.name,
  2023. 'java.home': expected.home,
  2024. 'jdk_location': expected.location
  2025. }
  2026. }
  2027. };
  2028. c.getJDKNameSuccessCallback(data);
  2029. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  2030. expect(c.get('jdkLocation')).to.equal(expected.location);
  2031. expect(c.get('javaHome')).to.equal(expected.home);
  2032. });
  2033. });
  2034. describe('#doCheckJDK', function () {
  2035. beforeEach(function () {
  2036. sinon.stub($, 'ajax', Em.K);
  2037. sinon.stub(App, 'get', function (k) {
  2038. if ('testMode' === k) return false;
  2039. return Em.get(App, k);
  2040. });
  2041. });
  2042. afterEach(function () {
  2043. $.ajax.restore();
  2044. App.get.restore();
  2045. });
  2046. it('should do proper request to the ambari-server', function () {
  2047. var bootHosts = [
  2048. Em.Object.create({name: 'n1', bootStatus: 'REGISTERED'}),
  2049. Em.Object.create({name: 'n2', bootStatus: 'REGISTERED'})
  2050. ],
  2051. javaHome = '/java',
  2052. jdkLocation = '/jdk';
  2053. c.reopen({
  2054. bootHosts: bootHosts,
  2055. javaHome: javaHome,
  2056. jdkLocation: jdkLocation
  2057. });
  2058. c.doCheckJDK();
  2059. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  2060. expect(request.type).to.equal('POST');
  2061. expect(request.url).to.contain('/requests');
  2062. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  2063. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  2064. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  2065. });
  2066. });
  2067. describe('#doCheckJDKsuccessCallback', function () {
  2068. beforeEach(function () {
  2069. sinon.stub($, 'ajax', Em.K);
  2070. sinon.stub(App, 'get', function (k) {
  2071. if ('testMode' === k) return false;
  2072. return Em.get(App, k);
  2073. });
  2074. });
  2075. afterEach(function () {
  2076. $.ajax.restore();
  2077. App.get.restore();
  2078. });
  2079. it('should set jdkRequestIndex if data provided', function () {
  2080. var data = {
  2081. href: '/a/b/c'
  2082. },
  2083. expected = 'c';
  2084. c.set('jdkRequestIndex', null);
  2085. c.doCheckJDKsuccessCallback(data);
  2086. expect(c.get('jdkRequestIndex')).to.equal(expected);
  2087. });
  2088. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function () {
  2089. var data = null,
  2090. expected = true;
  2091. c.set('isJDKWarningsLoaded', false);
  2092. c.set('jdkCategoryWarnings', {});
  2093. c.doCheckJDKsuccessCallback(data);
  2094. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  2095. });
  2096. it('should do propert request to ambari-server', function () {
  2097. var data = null,
  2098. jdkRequestIndex = 'jdkRequestIndex',
  2099. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  2100. c.set('jdkRequestIndex', jdkRequestIndex);
  2101. c.set('jdkCategoryWarnings', null);
  2102. c.doCheckJDKsuccessCallback(data);
  2103. expect($.ajax.args[0][0].type).to.equal('GET');
  2104. expect($.ajax.args[0][0].url).to.contain(url);
  2105. });
  2106. });
  2107. describe('#doCheckJDKerrorCallback', function () {
  2108. it('should set isJDKWarningsLoaded to true', function () {
  2109. c.set('isJDKWarningsLoaded', false);
  2110. c.doCheckJDKerrorCallback();
  2111. c.set('isJDKWarningsLoaded', true);
  2112. });
  2113. });
  2114. describe('#parseJDKCheckResults', function () {
  2115. beforeEach(function () {
  2116. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  2117. });
  2118. afterEach(function () {
  2119. c.doCheckJDKsuccessCallback.restore();
  2120. });
  2121. it('should set jdkCategoryWarnings to null if no data', function () {
  2122. var data = {Requests: {}};
  2123. c.set('jdkCategoryWarnings', {});
  2124. c.parseJDKCheckResults(data);
  2125. expect(c.get('jdkCategoryWarnings')).to.be.null;
  2126. });
  2127. it('should parse warnings (1)', function () {
  2128. var data = {
  2129. Requests: {
  2130. end_time: 1
  2131. },
  2132. tasks: []
  2133. };
  2134. c.set('jdkCategoryWarnings', {});
  2135. c.parseJDKCheckResults(data);
  2136. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  2137. });
  2138. it('should parse warnings (2)', function () {
  2139. var data = {
  2140. Requests: {
  2141. end_time: 1
  2142. },
  2143. tasks: [
  2144. {
  2145. Tasks: {
  2146. host_name: 'h1',
  2147. structured_out: {
  2148. java_home_check: {
  2149. exit_code: 1
  2150. }
  2151. }
  2152. }
  2153. },
  2154. {
  2155. Tasks: {
  2156. host_name: 'h2',
  2157. structured_out: {
  2158. java_home_check: {
  2159. exit_code: 0
  2160. }
  2161. }
  2162. }
  2163. }
  2164. ]
  2165. };
  2166. c.set('jdkCategoryWarnings', {});
  2167. c.parseJDKCheckResults(data);
  2168. var result = c.get('jdkCategoryWarnings');
  2169. expect(result.length).to.equal(1);
  2170. expect(result[0].hostsNames).to.eql(['h1']);
  2171. });
  2172. });
  2173. describe('#getHostCheckTasksSuccess', function() {
  2174. beforeEach(function() {
  2175. sinon.stub($, 'ajax', Em.K);
  2176. sinon.stub(c, 'getHostInfo', Em.K);
  2177. sinon.stub(c, 'parseHostNameResolution', Em.K);
  2178. sinon.stub(c, 'getGeneralHostCheck', Em.K);
  2179. sinon.stub(c, 'getHostCheckTasks', Em.K);
  2180. });
  2181. afterEach(function() {
  2182. $.ajax.restore();
  2183. c.getHostInfo.restore();
  2184. c.parseHostNameResolution.restore();
  2185. c.getGeneralHostCheck.restore();
  2186. c.getHostCheckTasks.restore();
  2187. });
  2188. var dataInProgress = {
  2189. Requests: {
  2190. request_status: "IN_PROGRESS"
  2191. }
  2192. };
  2193. it('run getHostCheckTasks', function() {
  2194. c.getHostCheckTasksSuccess(dataInProgress);
  2195. expect(c.getHostCheckTasks.calledOnce).to.be.true;
  2196. });
  2197. var hostResolutionCheckComplete = {
  2198. Requests: {
  2199. request_status: "COMPLETED",
  2200. inputs: "host_resolution_check"
  2201. }
  2202. };
  2203. it('run parseHostNameResolution and getGeneralHostCheck', function() {
  2204. c.getHostCheckTasksSuccess(hostResolutionCheckComplete);
  2205. expect(c.parseHostNameResolution.calledWith(hostResolutionCheckComplete)).to.be.true;
  2206. expect(c.getGeneralHostCheck.calledOnce).to.be.true;
  2207. });
  2208. var lastAgentEnvCheckComplete = {
  2209. Requests: {
  2210. request_status: "COMPLETED",
  2211. inputs: "last_agent_env_check"
  2212. }
  2213. };
  2214. it('run getHostInfo', function() {
  2215. c.getHostCheckTasksSuccess(lastAgentEnvCheckComplete);
  2216. expect(c.get('stopChecking')).to.be.true;
  2217. expect(c.getHostInfo.calledOnce).to.be.true;
  2218. });
  2219. });
  2220. });