step3_test.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  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. var c = App.WizardStep3Controller.create({
  27. content: Em.Object.create({installedHosts: Em.A([]), installOptions: {}}),
  28. wizardController: App.InstallerController.create(),
  29. disablePreviousSteps: Em.K
  30. });
  31. beforeEach(function () {
  32. sinon.stub(App.db, 'getDisplayLength', Em.K);
  33. sinon.stub(App.db, 'getFilterConditions').returns([]);
  34. sinon.stub(App.router, 'send', Em.K);
  35. });
  36. afterEach(function() {
  37. App.db.getDisplayLength.restore();
  38. App.router.send.restore();
  39. App.db.getFilterConditions.restore();
  40. });
  41. describe('#getAllRegisteredHostsCallback', function () {
  42. it('One host is already in the cluster, one host is registered', function() {
  43. c.get('content.installedHosts').pushObject({
  44. name: 'wst3_host1'
  45. });
  46. c.reopen({
  47. bootHosts: [
  48. {name:'wst3_host1'},
  49. {name:'wst3_host2'}
  50. ]
  51. });
  52. var test_data = {
  53. items: [
  54. {
  55. Hosts: {
  56. host_name: 'wst3_host1'
  57. }
  58. },
  59. {
  60. Hosts: {
  61. host_name: 'wst3_host2'
  62. }
  63. },
  64. {
  65. Hosts: {
  66. host_name: 'wst3_host3'
  67. }
  68. }
  69. ]
  70. };
  71. c.getAllRegisteredHostsCallback(test_data);
  72. expect(c.get('hasMoreRegisteredHosts')).to.equal(true);
  73. expect(c.get('registeredHosts').length).to.equal(1);
  74. });
  75. it('All hosts are new', function() {
  76. c.get('content.installedHosts').pushObject({
  77. name: 'wst3_host1'
  78. });
  79. c.reopen({
  80. bootHosts: [
  81. {name:'wst3_host3'},
  82. {name:'wst3_host4'}
  83. ]
  84. });
  85. var test_data = {
  86. items: [
  87. {
  88. Hosts: {
  89. host_name: 'wst3_host3'
  90. }
  91. },
  92. {
  93. Hosts: {
  94. host_name: 'wst3_host4'
  95. }
  96. }
  97. ]
  98. };
  99. c.getAllRegisteredHostsCallback(test_data);
  100. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  101. expect(c.get('registeredHosts')).to.equal('');
  102. });
  103. it('No new hosts', function() {
  104. c.get('content.installedHosts').pushObject({
  105. name: 'wst3_host1'
  106. });
  107. c.reopen({
  108. bootHosts: [
  109. {name:'wst3_host1'}
  110. ]
  111. });
  112. var test_data = {
  113. items: [
  114. {
  115. Hosts: {
  116. host_name: 'wst3_host1'
  117. }
  118. }
  119. ]
  120. };
  121. c.getAllRegisteredHostsCallback(test_data);
  122. expect(c.get('hasMoreRegisteredHosts')).to.equal(false);
  123. expect(c.get('registeredHosts')).to.equal('');
  124. });
  125. });
  126. describe('#registrationTimeoutSecs', function() {
  127. it('Manual install', function() {
  128. c.set('content.installOptions.manualInstall', true);
  129. expect(c.get('registrationTimeoutSecs')).to.equal(15);
  130. });
  131. it('Not manual install', function() {
  132. c.set('content.installOptions.manualInstall', false);
  133. expect(c.get('registrationTimeoutSecs')).to.equal(120);
  134. });
  135. });
  136. describe('#isHostHaveWarnings', function() {
  137. var tests = [
  138. {
  139. warnings: [{},{}],
  140. m: 'Warnings exist',
  141. e: true
  142. },
  143. {
  144. warnings: [],
  145. m: 'Warnings don\'t exist',
  146. e: false
  147. }
  148. ];
  149. tests.forEach(function(test) {
  150. it(test.m, function() {
  151. c.set('warnings', test.warnings);
  152. expect(c.get('isHostHaveWarnings')).to.equal(test.e);
  153. });
  154. });
  155. });
  156. describe('#isWarningsBoxVisible', function() {
  157. afterEach(function() {
  158. App.get.restore();
  159. });
  160. it('for testMode should be always true', function() {
  161. sinon.stub(App, 'get', function(k) {
  162. if ('testMode' === k) return true;
  163. return Em.get(App, k);
  164. });
  165. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  166. });
  167. it('for "real" mode should be based on isRegistrationInProgress', function() {
  168. sinon.stub(App, 'get', function(k) {
  169. if ('testMode' === k) return false;
  170. return Em.get(App, k);
  171. });
  172. c.set('isRegistrationInProgress', false);
  173. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  174. c.set('isRegistrationInProgress', true);
  175. expect(c.get('isWarningsBoxVisible')).to.equal(false);
  176. });
  177. });
  178. describe('#clearStep', function() {
  179. it('should clear hosts', function() {
  180. c.set('hosts', [{}, {}]);
  181. c.clearStep();
  182. expect(c.get('hosts')).to.eql([]);
  183. });
  184. it('should clear bootHosts', function() {
  185. c.set('bootHosts', [{}, {}]);
  186. c.clearStep();
  187. expect(c.get('bootHosts').length).to.equal(0);
  188. });
  189. it('should set stopBootstrap to false', function() {
  190. c.set('stopBootstrap', true);
  191. c.clearStep();
  192. expect(c.get('stopBootstrap')).to.equal(false);
  193. });
  194. it('should set wizardController DBProperty bootStatus to false', function() {
  195. c.get('wizardController').setDBProperty('bootStatus', true);
  196. c.clearStep();
  197. expect(c.get('wizardController').getDBProperty('bootStatus')).to.equal(false);
  198. });
  199. it('should set isSubmitDisabled to true', function() {
  200. c.set('isSubmitDisabled', false);
  201. c.clearStep();
  202. expect(c.get('isSubmitDisabled')).to.equal(true);
  203. });
  204. it('should set isSubmitDisabled to true', function() {
  205. c.set('isRetryDisabled', false);
  206. c.clearStep();
  207. expect(c.get('isRetryDisabled')).to.equal(true);
  208. });
  209. });
  210. describe('#loadStep', function() {
  211. beforeEach(function() {
  212. sinon.stub(App.router, 'get').withArgs('clusterController').returns({
  213. loadAmbariProperties: Em.K
  214. });
  215. sinon.spy(c, 'clearStep');
  216. sinon.stub(c, 'loadHosts', Em.K);
  217. sinon.stub(c, 'disablePreviousSteps', Em.K);
  218. });
  219. afterEach(function() {
  220. App.router.get.restore();
  221. c.clearStep.restore();
  222. c.disablePreviousSteps.restore();
  223. c.loadHosts.restore();
  224. });
  225. it('should set registrationStartedAt to null', function() {
  226. c.set('registrationStartedAt', {});
  227. c.loadStep();
  228. expect(c.get('registrationStartedAt')).to.be.null;
  229. });
  230. it('should call clearStep', function() {
  231. c.loadStep();
  232. expect(c.get('clearStep').calledOnce).to.equal(true);
  233. });
  234. it('should call loadHosts', function() {
  235. c.loadStep();
  236. expect(c.get('loadHosts').calledOnce).to.equal(true);
  237. });
  238. it('should call disablePreviousSteps', function() {
  239. c.loadStep();
  240. expect(c.get('disablePreviousSteps').calledOnce).to.equal(true);
  241. });
  242. });
  243. describe('#loadHosts', function() {
  244. beforeEach(function(){
  245. sinon.stub(c, 'navigateStep');
  246. });
  247. afterEach(function() {
  248. c.navigateStep.restore();
  249. App.set('testMode', false);
  250. });
  251. it('should set isLoaded to true', function() {
  252. App.set('testMode', true);
  253. c.set('content', {hosts: {}});
  254. c.loadHosts();
  255. expect(c.get('isLoaded')).to.equal(true);
  256. });
  257. it('should set bootStatus REGISTERED on testMode', function() {
  258. App.set('testMode', true);
  259. c.set('content', {hosts: {c: {name: 'name'}}});
  260. c.loadHosts();
  261. expect(c.get('hosts').everyProperty('bootStatus', 'REGISTERED')).to.equal(true);
  262. });
  263. it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function() {
  264. App.set('testMode', false);
  265. c.set('content.installOptions', {manualInstall: true});
  266. c.set('content.hosts', {c: {name: 'name'}});
  267. c.loadHosts();
  268. expect(c.get('hosts').everyProperty('bootStatus', 'DONE')).to.equal(true);
  269. });
  270. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  271. App.set('testMode', false);
  272. c.set('content', {installOptions:{manualInstall: false}, hosts: {c: {name: 'name'}}});
  273. c.loadHosts();
  274. expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
  275. });
  276. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  277. App.set('testMode', true);
  278. c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
  279. c.loadHosts();
  280. expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
  281. });
  282. });
  283. describe('#parseHostInfo', function() {
  284. var tests = Em.A([
  285. {
  286. bootHosts: Em.A([
  287. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  288. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  289. Em.Object.create({name: 'c3', bootStatus: 'RUNNING', bootLog: ''})
  290. ]),
  291. hostsStatusFromServer: Em.A([
  292. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  293. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  294. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  295. ]),
  296. m: 'bootHosts not empty, hostsStatusFromServer not empty, one is RUNNING',
  297. e: {
  298. c: true,
  299. r: true
  300. }
  301. },
  302. {
  303. bootHosts: Em.A([]),
  304. hostsStatusFromServer: Em.A([
  305. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  306. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  307. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  308. ]),
  309. m: 'bootHosts is empty',
  310. e: {
  311. c: false,
  312. r: false
  313. }
  314. },
  315. {
  316. bootHosts: Em.A([
  317. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  318. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  319. Em.Object.create({name: 'c3', bootStatus: 'REGISTERED', bootLog: ''})
  320. ]),
  321. hostsStatusFromServer: Em.A([
  322. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  323. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  324. {hostName: 'c3', status: 'REGISTERED', log: 'c3'}
  325. ]),
  326. m: 'bootHosts not empty, hostsStatusFromServer not empty, no one is RUNNING',
  327. e: {
  328. c: true,
  329. r: false
  330. }
  331. }
  332. ]);
  333. tests.forEach(function(test) {
  334. it(test.m, function() {
  335. c.set('bootHosts', test.bootHosts);
  336. var r = c.parseHostInfo(test.hostsStatusFromServer);
  337. expect(r).to.equal(test.e.r);
  338. if (test.e.c) {
  339. test.hostsStatusFromServer.forEach(function(h) {
  340. var r = c.get('bootHosts').findProperty('name', h.hostName);
  341. if (!['REGISTERED', 'REGISTERING'].contains(r.get('bootStatus'))) {
  342. expect(r.get('bootStatus')).to.equal(h.status);
  343. expect(r.get('bootLog')).to.equal(h.log);
  344. }
  345. });
  346. }
  347. });
  348. });
  349. });
  350. describe('#removeHosts', function() {
  351. beforeEach(function(){
  352. sinon.spy(App, 'showConfirmationPopup');
  353. });
  354. afterEach(function(){
  355. App.showConfirmationPopup.restore();
  356. });
  357. it('should call App.showConfirmationPopup', function() {
  358. c.removeHosts(Em.A([]));
  359. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  360. });
  361. it('primary should disable Submit if no more hosts', function() {
  362. var hosts = [{}];
  363. c.set('hosts', hosts);
  364. var popup = c.removeHosts(hosts);
  365. popup.onPrimary();
  366. expect(c.get('isSubmitDisabled')).to.equal(true);
  367. });
  368. });
  369. describe('#removeHost', function() {
  370. before(function(){
  371. sinon.stub(c, 'removeHosts', Em.K);
  372. });
  373. after(function(){
  374. c.removeHosts.restore();
  375. });
  376. it('should call removeHosts with array as arg', function() {
  377. var host = {a:''};
  378. c.removeHost(host);
  379. expect(c.removeHosts.calledWith([host]));
  380. });
  381. });
  382. describe('#removeSelectedHosts', function() {
  383. before(function(){
  384. sinon.stub(c, 'removeHosts', Em.K);
  385. });
  386. after(function(){
  387. c.removeHosts.restore();
  388. });
  389. it('should remove selected hosts', function() {
  390. c.set('hosts', [
  391. {isChecked: true, name: 'c1'},
  392. {isChecked: false, name: 'c2'}
  393. ]);
  394. c.removeSelectedHosts();
  395. expect(c.removeHosts.calledWith([{isChecked: true, name: 'c1'}])).to.be.true;
  396. });
  397. });
  398. describe('#selectedHostsPopup', function() {
  399. it('should show App.ModalPopup', function() {
  400. sinon.spy(App.ModalPopup, 'show');
  401. c.selectedHostsPopup();
  402. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  403. App.ModalPopup.show.restore();
  404. });
  405. });
  406. describe('#retryHosts', function () {
  407. var s;
  408. var installer = {launchBootstrap: Em.K};
  409. beforeEach(function () {
  410. sinon.spy(installer, "launchBootstrap");
  411. s = sinon.stub(App.router, 'get', function () {
  412. return installer;
  413. });
  414. sinon.stub(c, 'doBootstrap', Em.K);
  415. });
  416. afterEach(function () {
  417. c.doBootstrap.restore();
  418. s.restore();
  419. installer.launchBootstrap.restore();
  420. });
  421. it('should set numPolls to 0', function () {
  422. c.set('content', {installOptions: {}});
  423. c.set('numPolls', 123);
  424. c.retryHosts(Em.A([]));
  425. expect(c.get('numPolls')).to.equal(0);
  426. });
  427. it('should set registrationStartedAt to null', function () {
  428. c.set('content', {installOptions: {}});
  429. c.retryHosts(Em.A([]));
  430. expect(c.get('registrationStartedAt')).to.be.null;
  431. });
  432. it('should startRegistration if installOptions.manualInstall is true', function () {
  433. sinon.spy(c, 'startRegistration');
  434. c.set('content', {installOptions: {manualInstall: true}});
  435. c.retryHosts(Em.A([]));
  436. expect(c.startRegistration.calledOnce).to.equal(true);
  437. c.startRegistration.restore();
  438. });
  439. it('should launchBootstrap if installOptions.manualInstall is false', function () {
  440. c.set('content', {installOptions: {manualInstall: false}});
  441. c.retryHosts(Em.A([]));
  442. expect(installer.launchBootstrap.calledOnce).to.be.true;
  443. });
  444. it('bootstrap data passed correctly', function () {
  445. var controller = App.WizardStep2Controller.create({
  446. sshKey: 'key',
  447. hostNameArr: ['host0', 'host1'],
  448. sshUser: 'root',
  449. agentUser: 'user'
  450. });
  451. controller.setupBootStrap();
  452. expect(installer.launchBootstrap.firstCall.args[0]).to.equal(JSON.stringify({
  453. verbose: true,
  454. sshKey: 'key',
  455. hosts: ['host0', 'host1'],
  456. user: 'root',
  457. userRunAs: 'user'
  458. }));
  459. });
  460. });
  461. describe('#retryHost', function() {
  462. before(function(){
  463. sinon.spy(c, 'retryHosts');
  464. sinon.stub(App.router, 'get', function() {
  465. return {launchBootstrap: Em.K}
  466. });
  467. sinon.stub(c, 'doBootstrap', Em.K);
  468. });
  469. after(function(){
  470. c.retryHosts.restore();
  471. App.router.get.restore();
  472. c.doBootstrap.restore();
  473. });
  474. it('should callretryHosts with array as arg', function() {
  475. var host = {n: 'c'};
  476. c.set('content', {installOptions: {}});
  477. c.retryHost(host);
  478. expect(c.retryHosts.calledWith([host])).to.equal(true);
  479. });
  480. });
  481. describe('#retrySelectedHosts', function() {
  482. beforeEach(function () {
  483. sinon.spy(c, 'retryHosts');
  484. sinon.stub(App.router, 'get', function () {
  485. return {launchBootstrap: Em.K}
  486. });
  487. sinon.stub(c, 'doBootstrap', Em.K);
  488. });
  489. afterEach(function () {
  490. c.retryHosts.restore();
  491. App.router.get.restore();
  492. c.doBootstrap.restore();
  493. });
  494. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  495. c.set('isRetryDisabled', true);
  496. c.retrySelectedHosts();
  497. expect(c.retryHosts.called).to.equal(false);
  498. });
  499. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  500. c.set('isRetryDisabled', false);
  501. c.set('bootHosts', Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]));
  502. c.retrySelectedHosts();
  503. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  504. expect(c.get('isRetryDisabled')).to.equal(true);
  505. });
  506. });
  507. describe('#startBootstrap', function() {
  508. beforeEach(function(){
  509. sinon.stub(c, 'doBootstrap', Em.K);
  510. });
  511. afterEach(function(){
  512. c.doBootstrap.restore();
  513. });
  514. it('should drop numPolls and registrationStartedAt', function() {
  515. c.set('numPolls', 123);
  516. c.set('registrationStartedAt', 1234);
  517. c.startBootstrap();
  518. expect(c.get('numPolls')).to.equal(0);
  519. expect(c.get('registrationStartedAt')).to.be.null;
  520. });
  521. it('should drop numPolls and registrationStartedAt', function() {
  522. c.set('hosts', Em.A([{name: 'c1'}, {name: 'c2'}]))
  523. c.startBootstrap();
  524. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  525. });
  526. });
  527. describe('#setRegistrationInProgressOnce', function() {
  528. before(function(){
  529. sinon.spy(Em.run, 'once');
  530. });
  531. after(function(){
  532. Em.run.once.restore();
  533. });
  534. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  535. c.setRegistrationInProgressOnce();
  536. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  537. });
  538. });
  539. describe('#setRegistrationInProgress', function() {
  540. var tests = Em.A([
  541. {
  542. bootHosts: [],
  543. isLoaded: false,
  544. e: true,
  545. m: 'no bootHosts and isLoaded is false'
  546. },
  547. {
  548. bootHosts: [],
  549. isLoaded: true,
  550. e: false,
  551. m: 'no bootHosts and isLoaded is true'
  552. },
  553. {
  554. bootHosts: [
  555. Em.Object.create({bootStatus: 'RUNNING'}),
  556. Em.Object.create({bootStatus: 'RUNNING'})
  557. ],
  558. isLoaded: true,
  559. e: true,
  560. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  561. },
  562. {
  563. bootHosts: [
  564. Em.Object.create({bootStatus: 'RUNNING'}),
  565. Em.Object.create({bootStatus: 'RUNNING'})
  566. ],
  567. isLoaded: false,
  568. e: true,
  569. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  570. },
  571. {
  572. bootHosts: [
  573. Em.Object.create({bootStatus: 'REGISTERED'}),
  574. Em.Object.create({bootStatus: 'RUNNING'})
  575. ],
  576. isLoaded: false,
  577. e: true,
  578. m: 'bootHosts with one REGISTERED and isLoaded is false'
  579. },
  580. {
  581. bootHosts: [
  582. Em.Object.create({bootStatus: 'FAILED'}),
  583. Em.Object.create({bootStatus: 'RUNNING'})
  584. ],
  585. isLoaded: false,
  586. e: true,
  587. m: 'bootHosts with one FAILED and isLoaded is false'
  588. },
  589. {
  590. bootHosts: [
  591. Em.Object.create({bootStatus: 'REGISTERED'}),
  592. Em.Object.create({bootStatus: 'RUNNING'})
  593. ],
  594. isLoaded: true,
  595. e: true,
  596. m: 'bootHosts with one REGISTERED and isLoaded is true'
  597. },
  598. {
  599. bootHosts: [
  600. Em.Object.create({bootStatus: 'FAILED'}),
  601. Em.Object.create({bootStatus: 'RUNNING'})
  602. ],
  603. isLoaded: true,
  604. e: true,
  605. m: 'bootHosts with one FAILED and isLoaded is true'
  606. }
  607. ]);
  608. beforeEach(function(){
  609. sinon.stub(c, 'getAllRegisteredHosts', Em.K);
  610. sinon.stub(c, 'disablePreviousSteps', Em.K);
  611. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  612. sinon.stub(c, 'navigateStep', Em.K);
  613. });
  614. afterEach(function(){
  615. c.disablePreviousSteps.restore();
  616. c.getAllRegisteredHosts.restore();
  617. c.setRegistrationInProgressOnce.restore();
  618. c.navigateStep.restore();
  619. });
  620. tests.forEach(function(test) {
  621. it(test.m, function() {
  622. c.set('bootHosts', test.bootHosts);
  623. c.set('isLoaded', test.isLoaded);
  624. c.setRegistrationInProgress();
  625. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  626. });
  627. });
  628. });
  629. describe('#doBootstrap()', function() {
  630. beforeEach(function() {
  631. sinon.spy(App.ajax, 'send');
  632. });
  633. afterEach(function() {
  634. App.ajax.send.restore();
  635. });
  636. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  637. c.set('stopBootstrap', true);
  638. c.doBootstrap();
  639. expect(App.ajax.send.called).to.equal(false);
  640. });
  641. it('should increment numPolls if stopBootstrap is false', function() {
  642. c.set('numPolls', 0);
  643. c.set('stopBootstrap', false);
  644. c.doBootstrap();
  645. expect(App.ajax.send.calledOnce).to.be.true;
  646. expect(c.get('numPolls')).to.equal(1);
  647. });
  648. });
  649. describe('#startRegistration', function() {
  650. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  651. c.set('registrationStartedAt', 1234);
  652. sinon.spy(c, 'isHostsRegistered');
  653. c.startRegistration();
  654. expect(c.isHostsRegistered.called).to.equal(false);
  655. expect(c.get('registrationStartedAt')).to.equal(1234);
  656. c.isHostsRegistered.restore();
  657. });
  658. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  659. c.set('registrationStartedAt', null);
  660. sinon.spy(c, 'isHostsRegistered');
  661. c.startRegistration();
  662. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  663. c.isHostsRegistered.restore();
  664. });
  665. });
  666. describe('#isHostsRegistered', function() {
  667. beforeEach(function() {
  668. sinon.stub(App.ajax, 'send', function() {return {retry: function() {return {then: Em.K}}}});
  669. });
  670. afterEach(function() {
  671. App.ajax.send.restore();
  672. });
  673. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  674. c.set('stopBootstrap', true);
  675. c.isHostsRegistered();
  676. expect(App.ajax.send.called).to.equal(false);
  677. });
  678. it('should do ajax call if stopBootstrap is false', function() {
  679. c.set('stopBootstrap', false);
  680. c.isHostsRegistered();
  681. expect(App.ajax.send.called).to.equal(true);
  682. });
  683. });
  684. describe('#isHostsRegisteredSuccessCallback', function() {
  685. var tests = Em.A([
  686. {
  687. bootHosts: Em.A([
  688. Em.Object.create({bootStatus: 'DONE'})
  689. ]),
  690. data: {items:[]},
  691. registrationStartedAt: 1000000,
  692. m: 'one host DONE',
  693. e: {
  694. bs: 'REGISTERING',
  695. getHostInfoCalled: false
  696. }
  697. },
  698. {
  699. bootHosts: Em.A([
  700. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  701. ]),
  702. data: {items:[{Hosts: {host_name: 'c1'}}]},
  703. m: ' one host REGISTERING',
  704. e: {
  705. bs: 'REGISTERED',
  706. getHostInfoCalled: false
  707. }
  708. },
  709. {
  710. bootHosts: Em.A([
  711. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  712. ]),
  713. data: {items:[{Hosts: {host_name: 'c2'}}]},
  714. registrationStartedAt: 0,
  715. m: 'one host REGISTERING but data missing info about it, timeout',
  716. e: {
  717. bs: 'FAILED',
  718. getHostInfoCalled: false
  719. }
  720. },
  721. {
  722. bootHosts: Em.A([
  723. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  724. ]),
  725. data: {items:[{Hosts: {host_name: 'c2'}}]},
  726. registrationStartedAt: 1000000,
  727. m: 'one host REGISTERING but data missing info about it',
  728. e: {
  729. bs: 'REGISTERING',
  730. getHostInfoCalled: false
  731. }
  732. },
  733. {
  734. bootHosts: Em.A([
  735. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  736. ]),
  737. data: {items:[{Hosts: {host_name: 'c1'}}]},
  738. m: ' one host RUNNING',
  739. e: {
  740. bs: 'RUNNING',
  741. getHostInfoCalled: false
  742. }
  743. }
  744. ]);
  745. beforeEach(function(){
  746. sinon.spy(c, 'getHostInfo');
  747. sinon.stub(App, 'dateTime').returns(1000000);
  748. });
  749. afterEach(function(){
  750. c.getHostInfo.restore();
  751. App.dateTime.restore();
  752. });
  753. tests.forEach(function(test) {
  754. it(test.m, function() {
  755. c.set('content.installedHosts', []);
  756. c.set('bootHosts', test.bootHosts);
  757. c.set('registrationStartedAt', test.registrationStartedAt);
  758. c.isHostsRegisteredSuccessCallback(test.data);
  759. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  760. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  761. });
  762. });
  763. });
  764. describe('#getAllRegisteredHosts', function() {
  765. it('should call App.ajax.send', function() {
  766. sinon.spy(App.ajax, 'send');
  767. c.getAllRegisteredHosts();
  768. expect(App.ajax.send.calledOnce).to.equal(true);
  769. App.ajax.send.restore();
  770. });
  771. });
  772. describe('#getAllRegisteredHostsCallback', function() {
  773. var tests = Em.A([
  774. {
  775. hostsInCluster: ['c3'],
  776. bootHosts: [{name:'c1'},{name:'c2'}],
  777. hosts: Em.A([
  778. {Hosts: {host_name:'c1'}},
  779. {Hosts: {host_name:'c2'}}
  780. ]),
  781. m: 'No registered hosts',
  782. e: {
  783. hasMoreRegisteredHosts: false,
  784. registeredHosts: ''
  785. }
  786. },
  787. {
  788. hostsInCluster: ['c4'],
  789. bootHosts: [{name:'c3'},{name:'c5'}],
  790. hosts: Em.A([
  791. {Hosts: {host_name:'c1'}},
  792. {Hosts: {host_name:'c2'}}
  793. ]),
  794. m: '2 registered hosts',
  795. e: {
  796. hasMoreRegisteredHosts: true,
  797. registeredHosts: ['c1','c2']
  798. }
  799. },
  800. {
  801. hostsInCluster: ['c4'],
  802. bootHosts: [{name:'c1'},{name:'c5'}],
  803. hosts: Em.A([
  804. {Hosts: {host_name:'c1'}},
  805. {Hosts: {host_name:'c2'}}
  806. ]),
  807. m: '1 registered host',
  808. e: {
  809. hasMoreRegisteredHosts: true,
  810. registeredHosts: ['c2']
  811. }
  812. },
  813. {
  814. hostsInCluster: ['c1'],
  815. bootHosts: [{name:'c3'},{name:'c5'}],
  816. hosts: Em.A([
  817. {Hosts: {host_name:'c1'}},
  818. {Hosts: {host_name:'c2'}}
  819. ]),
  820. m: '1 registered host (2)',
  821. e: {
  822. hasMoreRegisteredHosts: true,
  823. registeredHosts: ['c2']
  824. }
  825. }
  826. ]);
  827. tests.forEach(function(test) {
  828. it(test.m, function() {
  829. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  830. c.set('bootHosts', test.bootHosts);
  831. c.getAllRegisteredHostsCallback({items:test.hosts});
  832. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  833. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  834. });
  835. });
  836. });
  837. describe('#registerErrPopup', function() {
  838. it('should call App.ModalPopup.show', function() {
  839. sinon.spy(App.ModalPopup, 'show');
  840. c.registerErrPopup();
  841. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  842. App.ModalPopup.show.restore();
  843. });
  844. });
  845. describe('#getHostInfo', function() {
  846. it('should do ajax request', function() {
  847. sinon.spy(App.ajax, 'send');
  848. c.getHostInfo();
  849. expect(App.ajax.send.calledOnce).to.equal(true);
  850. App.ajax.send.restore();
  851. });
  852. });
  853. describe('#getHostInfoErrorCallback', function() {
  854. it('should call registerErrPopup', function() {
  855. sinon.spy(c, 'registerErrPopup');
  856. c.getHostInfoErrorCallback();
  857. expect(c.registerErrPopup.calledOnce).to.equal(true);
  858. c.registerErrPopup.restore();
  859. });
  860. });
  861. describe('#stopRegistration', function() {
  862. var tests = Em.A([
  863. {
  864. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  865. e: {isSubmitDisabled: false, isRetryDisabled: true}
  866. },
  867. {
  868. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  869. e: {isSubmitDisabled: true, isRetryDisabled: false}
  870. },
  871. {
  872. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  873. e: {isSubmitDisabled: false, isRetryDisabled: false}
  874. },
  875. {
  876. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  877. e: {isSubmitDisabled: true, isRetryDisabled: true}
  878. }
  879. ]);
  880. tests.forEach(function(test) {
  881. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  882. c.reopen({bootHosts: test.bootHosts});
  883. c.stopRegistration();
  884. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  885. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  886. });
  887. });
  888. });
  889. describe('#submit', function() {
  890. it('if isHostHaveWarnings should show confirmation popup', function() {
  891. c.reopen({isHostHaveWarnings: true});
  892. sinon.spy(App.ModalPopup, 'show');
  893. c.submit();
  894. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  895. App.ModalPopup.show.restore();
  896. });
  897. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  898. var bootHosts = [{name: 'c1'}];
  899. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  900. c.submit().onPrimary();
  901. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  902. });
  903. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  904. var bootHosts = [{name: 'c1'}];
  905. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  906. c.submit();
  907. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  908. });
  909. });
  910. describe('#hostLogPopup', function() {
  911. it('should show App.ModalPopup', function() {
  912. sinon.spy(App.ModalPopup, 'show');
  913. c.hostLogPopup({context:Em.Object.create({})});
  914. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  915. App.ModalPopup.show.restore();
  916. });
  917. });
  918. describe('#rerunChecksSuccessCallback', function() {
  919. beforeEach(function() {
  920. sinon.stub(c, 'parseWarnings', Em.K);
  921. });
  922. afterEach(function() {
  923. c.parseWarnings.restore();
  924. });
  925. it('should set checksUpdateProgress to 100', function() {
  926. c.set('checksUpdateProgress', 0);
  927. c.rerunChecksSuccessCallback({items: []});
  928. expect(c.get('checksUpdateProgress')).to.equal(100);
  929. });
  930. it('should set checksUpdateStatus to SUCCESS', function() {
  931. c.set('checksUpdateStatus', '');
  932. c.rerunChecksSuccessCallback({items: []});
  933. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  934. });
  935. it('should call parseWarnings', function() {
  936. c.rerunChecksSuccessCallback({items: []});
  937. expect(c.parseWarnings.calledOnce).to.equal(true);
  938. });
  939. });
  940. describe('#rerunChecksErrorCallback', function() {
  941. it('should set checksUpdateProgress to 100', function() {
  942. c.set('checksUpdateProgress', 0);
  943. c.rerunChecksErrorCallback({});
  944. expect(c.get('checksUpdateProgress')).to.equal(100);
  945. });
  946. it('should set checksUpdateStatus to FAILED', function() {
  947. c.set('checksUpdateStatus', '');
  948. c.rerunChecksErrorCallback({});
  949. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  950. });
  951. });
  952. describe('#filterBootHosts', function() {
  953. var tests = Em.A([
  954. {
  955. bootHosts: [
  956. Em.Object.create({name: 'c1'}),
  957. Em.Object.create({name: 'c2'})
  958. ],
  959. data: {
  960. items: [
  961. {Hosts: {host_name: 'c1'}}
  962. ]
  963. },
  964. m: 'one host',
  965. e: ['c1']
  966. },
  967. {
  968. bootHosts: [
  969. Em.Object.create({name: 'c1'}),
  970. Em.Object.create({name: 'c2'})
  971. ],
  972. data: {
  973. items: [
  974. {Hosts: {host_name: 'c3'}}
  975. ]
  976. },
  977. m: 'no hosts',
  978. e: []
  979. },
  980. {
  981. bootHosts: [
  982. Em.Object.create({name: 'c1'}),
  983. Em.Object.create({name: 'c2'})
  984. ],
  985. data: {
  986. items: [
  987. {Hosts: {host_name: 'c1'}},
  988. {Hosts: {host_name: 'c2'}}
  989. ]
  990. },
  991. m: 'many hosts',
  992. e: ['c1', 'c2']
  993. }
  994. ]);
  995. tests.forEach(function(test) {
  996. it(test.m, function() {
  997. c.reopen({bootHosts: test.bootHosts});
  998. var filteredData = c.filterBootHosts(test.data);
  999. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  1000. });
  1001. });
  1002. });
  1003. describe('#hostWarningsPopup', function() {
  1004. it('should show App.ModalPopup', function() {
  1005. sinon.stub(App.ModalPopup, 'show', Em.K);
  1006. c.hostWarningsPopup();
  1007. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1008. App.ModalPopup.show.restore();
  1009. });
  1010. it('should clear checksUpdateStatus on primary', function() {
  1011. c.set('checksUpdateStatus', 'not null value');
  1012. c.hostWarningsPopup().onPrimary();
  1013. expect(c.get('checksUpdateStatus')).to.be.null;
  1014. });
  1015. it('should clear checksUpdateStatus on close', function() {
  1016. c.set('checksUpdateStatus', 'not null value');
  1017. c.hostWarningsPopup().onClose();
  1018. expect(c.get('checksUpdateStatus')).to.be.null;
  1019. });
  1020. it('should rerunChecks onSecondary', function() {
  1021. sinon.stub(c, 'rerunChecks', Em.K);
  1022. c.hostWarningsPopup().onSecondary();
  1023. expect(c.rerunChecks.calledOnce).to.equal(true);
  1024. });
  1025. });
  1026. describe('#registeredHostsPopup', function() {
  1027. it('should show App.ModalPopup', function() {
  1028. sinon.spy(App.ModalPopup, 'show');
  1029. c.registeredHostsPopup();
  1030. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1031. App.ModalPopup.show.restore();
  1032. });
  1033. });
  1034. describe('#parseWarnings', function() {
  1035. beforeEach(function() {
  1036. sinon.stub(App, 'get', function(k) {
  1037. if ('testMode' === k) return false;
  1038. return Em.get(App, k);
  1039. });
  1040. sinon.stub(c, 'filterBootHosts', function(k) {return k;});
  1041. });
  1042. afterEach(function() {
  1043. App.get.restore();
  1044. c.filterBootHosts.restore();
  1045. });
  1046. it('no warnings if last_agent_env isn\'t specified', function() {
  1047. c.set('warnings', [{}]);
  1048. c.set('warningsByHost', [{},{}]);
  1049. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  1050. expect(c.get('warnings')).to.eql([]);
  1051. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1052. });
  1053. Em.A([
  1054. {
  1055. m: 'parse stackFoldersAndFiles',
  1056. tests : Em.A([
  1057. {
  1058. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  1059. m: 'empty stackFoldersAndFiles',
  1060. e: {
  1061. warnings: [],
  1062. warningsByHost: [0]
  1063. }
  1064. },
  1065. {
  1066. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  1067. m: 'not empty stackFoldersAndFiles',
  1068. e: {
  1069. warnings: [{
  1070. name: 'n1',
  1071. hosts: ['c1'],
  1072. onSingleHost: true,
  1073. category: 'fileFolders'
  1074. }],
  1075. warningsByHost: [1]
  1076. }
  1077. },
  1078. {
  1079. items: [
  1080. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1081. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1082. ],
  1083. m: 'not empty stackFoldersAndFiles on two hosts',
  1084. e: {
  1085. warnings: [{
  1086. name: 'n1',
  1087. hosts: ['c1', 'c2'],
  1088. onSingleHost: false,
  1089. category: 'fileFolders'
  1090. }],
  1091. warningsByHost: [1]
  1092. }
  1093. }
  1094. ])
  1095. },
  1096. {
  1097. m: 'parse installedPackages',
  1098. tests : Em.A([
  1099. {
  1100. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1101. m: 'empty installedPackages',
  1102. e: {
  1103. warnings: [],
  1104. warningsByHost: [0]
  1105. }
  1106. },
  1107. {
  1108. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1109. m: 'not empty installedPackages',
  1110. e: {
  1111. warnings: [{
  1112. name: 'n1',
  1113. hosts: ['c1'],
  1114. onSingleHost: true,
  1115. category: 'packages'
  1116. }],
  1117. warningsByHost: [1]
  1118. }
  1119. },
  1120. {
  1121. items: [
  1122. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1123. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1124. ],
  1125. m: 'not empty installedPackages on two hosts',
  1126. e: {
  1127. warnings: [{
  1128. name: 'n1',
  1129. hosts: ['c1', 'c2'],
  1130. onSingleHost: false,
  1131. category: 'packages'
  1132. }],
  1133. warningsByHost: [1]
  1134. }
  1135. }
  1136. ])
  1137. },
  1138. {
  1139. m: 'parse hostHealth.liveServices',
  1140. tests : Em.A([
  1141. {
  1142. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1143. m: 'empty hostHealth',
  1144. e: {
  1145. warnings: [],
  1146. warningsByHost: [0]
  1147. }
  1148. },
  1149. {
  1150. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1151. m: 'empty liveServices',
  1152. e: {
  1153. warnings: [],
  1154. warningsByHost: [0]
  1155. }
  1156. },
  1157. {
  1158. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1159. m: 'not empty hostHealth.liveServices',
  1160. e: {
  1161. warnings: [{
  1162. name: 'n1',
  1163. hosts: ['c1'],
  1164. onSingleHost: true,
  1165. category: 'services'
  1166. }],
  1167. warningsByHost: [1]
  1168. }
  1169. },
  1170. {
  1171. items: [
  1172. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1173. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1174. ],
  1175. m: 'not empty hostHealth.liveServices on two hosts',
  1176. e: {
  1177. warnings: [{
  1178. name: 'n1',
  1179. hosts: ['c1', 'c2'],
  1180. onSingleHost: false,
  1181. category: 'services'
  1182. }],
  1183. warningsByHost: [1, 1]
  1184. }
  1185. }
  1186. ])
  1187. },
  1188. {
  1189. m: 'parse existingUsers',
  1190. tests : Em.A([
  1191. {
  1192. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1193. m: 'empty existingUsers',
  1194. e: {
  1195. warnings: [],
  1196. warningsByHost: [0]
  1197. }
  1198. },
  1199. {
  1200. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1201. m: 'not empty existingUsers',
  1202. e: {
  1203. warnings: [{
  1204. name: 'n1',
  1205. hosts: ['c1'],
  1206. onSingleHost: true,
  1207. category: 'users'
  1208. }],
  1209. warningsByHost: [1]
  1210. }
  1211. },
  1212. {
  1213. items: [
  1214. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1215. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1216. ],
  1217. m: 'not empty existingUsers on two hosts',
  1218. e: {
  1219. warnings: [{
  1220. name: 'n1',
  1221. hosts: ['c1', 'c2'],
  1222. onSingleHost: false,
  1223. category: 'users'
  1224. }],
  1225. warningsByHost: [1, 1]
  1226. }
  1227. }
  1228. ])
  1229. },
  1230. {
  1231. m: 'parse alternatives',
  1232. tests : Em.A([
  1233. {
  1234. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1235. m: 'empty alternatives',
  1236. e: {
  1237. warnings: [],
  1238. warningsByHost: [0]
  1239. }
  1240. },
  1241. {
  1242. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1243. m: 'not empty alternatives',
  1244. e: {
  1245. warnings: [{
  1246. name: 'n1',
  1247. hosts: ['c1'],
  1248. onSingleHost: true,
  1249. category: 'alternatives'
  1250. }],
  1251. warningsByHost: [1]
  1252. }
  1253. },
  1254. {
  1255. items: [
  1256. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1257. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1258. ],
  1259. m: 'not empty alternatives on two hosts',
  1260. e: {
  1261. warnings: [{
  1262. name: 'n1',
  1263. hosts: ['c1', 'c2'],
  1264. onSingleHost: false,
  1265. category: 'alternatives'
  1266. }],
  1267. warningsByHost: [1, 1]
  1268. }
  1269. }
  1270. ])
  1271. },
  1272. {
  1273. m: 'parse hostHealth.activeJavaProcs',
  1274. tests : Em.A([
  1275. {
  1276. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1277. m: 'empty hostHealth',
  1278. e: {
  1279. warnings: [],
  1280. warningsByHost: [0]
  1281. }
  1282. },
  1283. {
  1284. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1285. m: 'empty activeJavaProcs',
  1286. e: {
  1287. warnings: [],
  1288. warningsByHost: [0]
  1289. }
  1290. },
  1291. {
  1292. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1293. m: 'not empty hostHealth.activeJavaProcs',
  1294. e: {
  1295. warnings: [{
  1296. pid: 'n1',
  1297. hosts: ['c1'],
  1298. onSingleHost: true,
  1299. category: 'processes'
  1300. }],
  1301. warningsByHost: [1]
  1302. }
  1303. },
  1304. {
  1305. items: [
  1306. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1307. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1308. ],
  1309. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1310. e: {
  1311. warnings: [{
  1312. pid: 'n1',
  1313. hosts: ['c1', 'c2'],
  1314. onSingleHost: false,
  1315. category: 'processes'
  1316. }],
  1317. warningsByHost: [1, 1]
  1318. }
  1319. }
  1320. ])
  1321. }
  1322. ]).forEach(function(category) {
  1323. describe(category.m, function() {
  1324. category.tests.forEach(function(test) {
  1325. it(test.m, function() {
  1326. c.parseWarnings({items: test.items});
  1327. c.get('warnings').forEach(function(w, i) {
  1328. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1329. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1330. });
  1331. });
  1332. for(var i in test.e.warningsByHost) {
  1333. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1334. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1335. }
  1336. }
  1337. });
  1338. });
  1339. });
  1340. });
  1341. it('should parse umask warnings', function() {
  1342. var items = [
  1343. {Hosts:{host_name: 'c1', last_agent_env: {umask: 18}}},
  1344. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1345. ];
  1346. c.parseWarnings({items: items});
  1347. var warnings = c.get('warnings');
  1348. expect(warnings.length).to.equal(1);
  1349. expect(warnings[0].hosts).to.eql(['c2']);
  1350. expect(warnings[0].onSingleHost).to.equal(true);
  1351. });
  1352. it('should parse umask warnings (2)', function() {
  1353. var items = [
  1354. {Hosts:{host_name: 'c1', last_agent_env: {umask: 8}}},
  1355. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1356. ];
  1357. c.parseWarnings({items: items});
  1358. var warnings = c.get('warnings');
  1359. expect(warnings.length).to.equal(2);
  1360. expect(warnings.mapProperty('hosts')).to.eql([['c1'], ['c2']]);
  1361. });
  1362. it('should parse firewall warnings', function() {
  1363. var items = [
  1364. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1365. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
  1366. ];
  1367. c.parseWarnings({items: items});
  1368. var warnings = c.get('warnings');
  1369. expect(warnings.length).to.equal(1);
  1370. expect(warnings[0].hosts).to.eql(['c1']);
  1371. expect(warnings[0].onSingleHost).to.equal(true);
  1372. });
  1373. it('should parse firewall warnings (2)', function() {
  1374. var items = [
  1375. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1376. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
  1377. ];
  1378. c.parseWarnings({items: items});
  1379. var warnings = c.get('warnings');
  1380. expect(warnings.length).to.equal(1);
  1381. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1382. expect(warnings[0].onSingleHost).to.equal(false);
  1383. });
  1384. it('should parse reverseLookup warnings', function() {
  1385. var items = [
  1386. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1387. ];
  1388. c.parseWarnings({items: items});
  1389. var warnings = c.get('warnings');
  1390. expect(warnings.length).to.equal(0);
  1391. });
  1392. it('should parse reverseLookup warnings (2)', function() {
  1393. var items = [
  1394. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1395. ];
  1396. c.parseWarnings({items: items});
  1397. var warnings = c.get('warnings');
  1398. expect(warnings.length).to.equal(1);
  1399. expect(warnings[0].hosts).to.eql(['c1']);
  1400. expect(warnings[0].onSingleHost).to.equal(true);
  1401. });
  1402. it('should parse reverseLookup warnings (3)', function() {
  1403. var items = [
  1404. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1405. {Hosts:{host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1406. ];
  1407. c.parseWarnings({items: items});
  1408. var warnings = c.get('warnings');
  1409. expect(warnings.length).to.equal(1);
  1410. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1411. expect(warnings[0].onSingleHost).to.equal(false);
  1412. });
  1413. });
  1414. describe('#navigateStep', function() {
  1415. beforeEach(function(){
  1416. sinon.stub(c, 'startBootstrap', Em.K);
  1417. });
  1418. afterEach(function(){
  1419. c.startBootstrap.restore();
  1420. });
  1421. Em.A([
  1422. {
  1423. isLoaded: true,
  1424. manualInstall: false,
  1425. bootStatus: false,
  1426. m: 'should call startBootstrap',
  1427. e: true
  1428. },
  1429. {
  1430. isLoaded: true,
  1431. manualInstall: false,
  1432. bootStatus: true,
  1433. m: 'shouldn\'t call startBootstrap (1)',
  1434. e: false
  1435. },
  1436. {
  1437. isLoaded: false,
  1438. manualInstall: false,
  1439. bootStatus: false,
  1440. m: 'shouldn\'t call startBootstrap (2)',
  1441. e: false
  1442. },
  1443. {
  1444. isLoaded: false,
  1445. manualInstall: true,
  1446. bootStatus: false,
  1447. m: 'shouldn\'t call startBootstrap (3)',
  1448. e: false
  1449. }
  1450. ]).forEach(function(test) {
  1451. it(test.m, function() {
  1452. c.reopen({
  1453. isLoaded: test.isLoaded,
  1454. content: {
  1455. installedHosts: [],
  1456. installOptions: {
  1457. manualInstall: test.manualInstall
  1458. }
  1459. },
  1460. wizardController: Em.Object.create({
  1461. getDBProperty: function() {
  1462. return test.bootStatus
  1463. }
  1464. })
  1465. });
  1466. c.navigateStep();
  1467. if(test.e) {
  1468. expect(c.startBootstrap.calledOnce).to.equal(true);
  1469. }
  1470. else {
  1471. expect(c.startBootstrap.called).to.equal(false);
  1472. }
  1473. });
  1474. });
  1475. it('should set test data if testMode is true', function() {
  1476. c.reopen({
  1477. isLoaded: true,
  1478. hosts: [{}, {}, {}],
  1479. content: {
  1480. installedHosts: [],
  1481. installOptions: {
  1482. manualInstall: true
  1483. }
  1484. },
  1485. setRegistrationInProgress: Em.K
  1486. });
  1487. sinon.stub(App, 'get', function(k) {
  1488. if('testMode' === k) return true;
  1489. return Em.get(App, k);
  1490. });
  1491. c.navigateStep();
  1492. App.get.restore();
  1493. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1494. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1495. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1496. expect(c.get('isSubmitDisabled')).to.equal(false);
  1497. });
  1498. it('should start registration', function() {
  1499. c.reopen({
  1500. isLoaded: true,
  1501. hosts: [{}, {}, {}],
  1502. content: {
  1503. installedHosts: [],
  1504. installOptions: {
  1505. manualInstall: true
  1506. }
  1507. },
  1508. setRegistrationInProgress: Em.K,
  1509. startRegistration: Em.K
  1510. });
  1511. sinon.spy(c, 'startRegistration');
  1512. sinon.stub(App, 'get', function(k) {
  1513. if('testMode' === k) return false;
  1514. return Em.get(App, k);
  1515. });
  1516. c.navigateStep();
  1517. App.get.restore();
  1518. expect(c.startRegistration.calledOnce).to.equal(true);
  1519. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1520. expect(c.get('registrationStartedAt')).to.be.null;
  1521. c.startRegistration.restore();
  1522. });
  1523. });
  1524. describe('#checkHostDiskSpace', function() {
  1525. Em.A([
  1526. {
  1527. diskInfo: [
  1528. {
  1529. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1530. mountpoint: '/'
  1531. }
  1532. ],
  1533. m: 'available less than App.minDiskSpace',
  1534. e: false
  1535. },
  1536. {
  1537. diskInfo: [
  1538. {
  1539. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1540. mountpoint: '/usr'
  1541. }
  1542. ],
  1543. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1544. e: false
  1545. },
  1546. {
  1547. diskInfo: [
  1548. {
  1549. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1550. mountpoint: '/usr/lib'
  1551. }
  1552. ],
  1553. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1554. e: false
  1555. },
  1556. {
  1557. diskInfo: [
  1558. {
  1559. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1560. mountpoint: '/'
  1561. }
  1562. ],
  1563. m: 'available greater than App.minDiskSpace',
  1564. e: true
  1565. },
  1566. {
  1567. diskInfo: [
  1568. {
  1569. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1570. mountpoint: '/usr'
  1571. }
  1572. ],
  1573. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1574. e: true
  1575. },
  1576. {
  1577. diskInfo: [
  1578. {
  1579. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1580. mountpoint: '/usr/lib'
  1581. }
  1582. ],
  1583. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1584. e: true
  1585. },
  1586. {
  1587. diskInfo: [
  1588. {
  1589. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1590. mountpoint: '/home/tdk'
  1591. }
  1592. ],
  1593. m: 'mount point without free space checks',
  1594. e: true
  1595. }
  1596. ]).forEach(function (test) {
  1597. it(test.m, function () {
  1598. var r = c.checkHostDiskSpace('', test.diskInfo);
  1599. expect(Em.isEmpty(r)).to.equal(test.e);
  1600. });
  1601. });
  1602. });
  1603. describe('#checkHostOSType', function() {
  1604. it('should return empty string if no stacks provided', function() {
  1605. c.reopen({content: {stacks: null}});
  1606. expect(c.checkHostOSType()).to.equal('');
  1607. });
  1608. it('os type is valid', function() {
  1609. var osType = 'redhat6';
  1610. c.reopen({
  1611. content: {
  1612. stacks: [
  1613. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1614. ]
  1615. }
  1616. });
  1617. expect(c.checkHostOSType(osType, '')).to.equal('');
  1618. });
  1619. it('os type is invalid', function() {
  1620. var osType = 'os2';
  1621. c.reopen({
  1622. content: {
  1623. stacks: [
  1624. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1625. ]
  1626. }
  1627. });
  1628. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1629. });
  1630. });
  1631. describe('#getHostInfoSuccessCallback', function() {
  1632. beforeEach(function() {
  1633. sinon.stub(c, 'parseWarnings', Em.K);
  1634. sinon.stub(c, 'stopRegistration', Em.K);
  1635. });
  1636. afterEach(function() {
  1637. c.parseWarnings.restore();
  1638. c.stopRegistration.restore();
  1639. });
  1640. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1641. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1642. sinon.stub(App, 'get', function(k) {
  1643. if ('skipBootstrap' === k) return true;
  1644. if ('testMode' === k) return false;
  1645. return Em.get(App, k);
  1646. });
  1647. c.reopen({
  1648. bootHosts: [Em.Object.create({name: 'h1'})]
  1649. });
  1650. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1651. c.getHostInfoSuccessCallback(jsonData);
  1652. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1653. App.get.restore();
  1654. c._setHostDataWithSkipBootstrap.restore();
  1655. });
  1656. it('should add repo warnings', function() {
  1657. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1658. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1659. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1660. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1661. sinon.stub(App, 'get', function(k) {
  1662. if ('skipBootstrap' === k) return false;
  1663. if ('testMode' === k) return false;
  1664. return Em.get(App, k);
  1665. });
  1666. c.reopen({
  1667. bootHosts: [Em.Object.create({name: 'h1'})]
  1668. });
  1669. c.getHostInfoSuccessCallback(jsonData);
  1670. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1671. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1672. c.checkHostOSType.restore();
  1673. c.checkHostDiskSpace.restore();
  1674. c._setHostDataFromLoadedHostInfo.restore();
  1675. App.get.restore();
  1676. });
  1677. it('should add disk warnings', function() {
  1678. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1679. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1680. sinon.stub(c, 'checkHostOSType', Em.K);
  1681. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1682. sinon.stub(App, 'get', function(k) {
  1683. if ('skipBootstrap' === k) return false;
  1684. if ('testMode' === k) return false;
  1685. return Em.get(App, k);
  1686. });
  1687. c.reopen({
  1688. bootHosts: [Em.Object.create({name: 'h1'})]
  1689. });
  1690. c.getHostInfoSuccessCallback(jsonData);
  1691. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1692. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1693. c.checkHostOSType.restore();
  1694. c.checkHostDiskSpace.restore();
  1695. c._setHostDataFromLoadedHostInfo.restore();
  1696. App.get.restore();
  1697. });
  1698. });
  1699. describe('#_setHostDataWithSkipBootstrap', function() {
  1700. it('should set mock-data', function() {
  1701. var host = Em.Object.create({});
  1702. c._setHostDataWithSkipBootstrap(host);
  1703. expect(host.get('cpu')).to.equal(2);
  1704. expect(host.get('memory')).to.equal('2000000.00');
  1705. expect(host.get('disk_info.length')).to.equal(4);
  1706. });
  1707. });
  1708. describe('#_setHostDataFromLoadedHostInfo', function() {
  1709. it('should set data from hostInfo', function() {
  1710. var host = Em.Object.create(),
  1711. hostInfo = {
  1712. Hosts: {
  1713. cpu_count: 2,
  1714. total_mem: 12345,
  1715. os_type: 't1',
  1716. os_arch: 'os1',
  1717. ip: '0.0.0.0',
  1718. disk_info: [
  1719. {mountpoint: '/boot'},
  1720. {mountpoint: '/usr'},
  1721. {mountpoint: '/no-boot'},
  1722. {mountpoint: '/boot'}
  1723. ]
  1724. }
  1725. };
  1726. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1727. expect(host.get('cpu')).to.equal(2);
  1728. expect(host.get('os_type')).to.equal('t1');
  1729. expect(host.get('os_arch')).to.equal('os1');
  1730. expect(host.get('ip')).to.equal('0.0.0.0');
  1731. expect(host.get('memory')).to.equal('12345.00');
  1732. expect(host.get('disk_info.length')).to.equal(2);
  1733. });
  1734. });
  1735. describe('#getJDKName', function() {
  1736. beforeEach(function() {
  1737. sinon.stub($, 'ajax', Em.K);
  1738. sinon.stub(App, 'get', function(k) {
  1739. if ('testMode' === k) return false;
  1740. return Em.get(App, k);
  1741. });
  1742. });
  1743. afterEach(function() {
  1744. $.ajax.restore();
  1745. App.get.restore();
  1746. });
  1747. it('should do proper request to ambari-server', function() {
  1748. c.getJDKName();
  1749. expect($.ajax.args[0][0].type).to.contain('GET');
  1750. 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');
  1751. });
  1752. });
  1753. describe('#getJDKNameSuccessCallback', function() {
  1754. it('should set proper data to controller properties', function() {
  1755. var expected = {
  1756. name: 'name',
  1757. home: 'home',
  1758. location: 'location'
  1759. },
  1760. data = {
  1761. RootServiceComponents: {
  1762. properties: {
  1763. 'jdk.name': expected.name,
  1764. 'java.home': expected.home,
  1765. 'jdk_location': expected.location
  1766. }
  1767. }
  1768. };
  1769. c.getJDKNameSuccessCallback(data);
  1770. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  1771. expect(c.get('jdkLocation')).to.equal(expected.location);
  1772. expect(c.get('javaHome')).to.equal(expected.home);
  1773. });
  1774. });
  1775. describe('#doCheckJDK', function() {
  1776. beforeEach(function() {
  1777. sinon.stub($, 'ajax', Em.K);
  1778. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  1779. sinon.stub(App, 'get', function(k) {
  1780. if ('testMode' === k) return false;
  1781. return Em.get(App, k);
  1782. });
  1783. });
  1784. afterEach(function() {
  1785. $.ajax.restore();
  1786. c.setRegistrationInProgressOnce.restore();
  1787. App.get.restore();
  1788. });
  1789. it('should do proper request to the ambari-server', function() {
  1790. var bootHosts = [{name: 'n1'}, {name: 'n2'}],
  1791. javaHome = '/java',
  1792. jdkLocation = '/jdk';
  1793. c.reopen({
  1794. bootHosts: bootHosts,
  1795. javaHome: javaHome,
  1796. jdkLocation: jdkLocation
  1797. });
  1798. c.doCheckJDK();
  1799. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  1800. expect(request.type).to.equal('POST');
  1801. expect(request.url).to.contain('/requests');
  1802. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  1803. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  1804. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  1805. });
  1806. });
  1807. describe('#doCheckJDKsuccessCallback', function() {
  1808. beforeEach(function() {
  1809. sinon.stub($, 'ajax', Em.K);
  1810. sinon.stub(App, 'get', function(k) {
  1811. if ('testMode' === k) return false;
  1812. return Em.get(App, k);
  1813. });
  1814. });
  1815. afterEach(function() {
  1816. $.ajax.restore();
  1817. App.get.restore();
  1818. });
  1819. it('should set jdkRequestIndex if data provided', function() {
  1820. var data = {
  1821. href: '/a/b/c'
  1822. },
  1823. expected = 'c';
  1824. c.set('jdkRequestIndex', null);
  1825. c.doCheckJDKsuccessCallback(data);
  1826. expect(c.get('jdkRequestIndex')).to.equal(expected);
  1827. });
  1828. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function() {
  1829. var data = null,
  1830. expected = true;
  1831. c.set('isJDKWarningsLoaded', false);
  1832. c.set('jdkCategoryWarnings', {});
  1833. c.doCheckJDKsuccessCallback(data);
  1834. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  1835. });
  1836. it('should do propert request to ambari-server', function() {
  1837. var data = null,
  1838. jdkRequestIndex = 'jdkRequestIndex',
  1839. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  1840. c.set('jdkRequestIndex', jdkRequestIndex);
  1841. c.set('jdkCategoryWarnings', null);
  1842. c.doCheckJDKsuccessCallback(data);
  1843. expect($.ajax.args[0][0].type).to.equal('GET');
  1844. expect($.ajax.args[0][0].url).to.contain(url);
  1845. });
  1846. });
  1847. describe('#doCheckJDKerrorCallback', function() {
  1848. it('should set isJDKWarningsLoaded to true', function() {
  1849. c.set('isJDKWarningsLoaded', false);
  1850. c.doCheckJDKerrorCallback();
  1851. c.set('isJDKWarningsLoaded', true);
  1852. });
  1853. });
  1854. describe('#parseJDKCheckResults', function() {
  1855. beforeEach(function() {
  1856. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  1857. });
  1858. afterEach(function() {
  1859. c.doCheckJDKsuccessCallback.restore();
  1860. });
  1861. it('should set jdkCategoryWarnings to null if no data', function() {
  1862. var data = {Requests: {}};
  1863. c.set('jdkCategoryWarnings', {});
  1864. c.parseJDKCheckResults(data);
  1865. expect(c.get('jdkCategoryWarnings')).to.be.null;
  1866. });
  1867. it('should parse warnings (1)', function() {
  1868. var data = {
  1869. Requests: {
  1870. end_time: 1
  1871. },
  1872. tasks: []
  1873. };
  1874. c.set('jdkCategoryWarnings', {});
  1875. c.parseJDKCheckResults(data);
  1876. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  1877. });
  1878. it('should parse warnings (2)', function() {
  1879. var data = {
  1880. Requests: {
  1881. end_time: 1
  1882. },
  1883. tasks: [
  1884. {
  1885. Tasks: {
  1886. host_name: 'h1',
  1887. structured_out: {
  1888. java_home_check: {
  1889. exit_code: 1
  1890. }
  1891. }
  1892. }
  1893. },
  1894. {
  1895. Tasks: {
  1896. host_name: 'h2',
  1897. structured_out: {
  1898. java_home_check: {
  1899. exit_code: 0
  1900. }
  1901. }
  1902. }
  1903. }
  1904. ]
  1905. };
  1906. c.set('jdkCategoryWarnings', {});
  1907. c.parseJDKCheckResults(data);
  1908. var result = c.get('jdkCategoryWarnings');
  1909. expect(result.length).to.equal(1);
  1910. expect(result[0].hostsNames).to.eql(['h1']);
  1911. });
  1912. });
  1913. });