step3_test.js 73 KB

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