step3_test.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  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. });
  445. describe('#retryHost', function() {
  446. before(function(){
  447. sinon.spy(c, 'retryHosts');
  448. sinon.stub(App.router, 'get', function() {
  449. return {launchBootstrap: Em.K}
  450. });
  451. sinon.stub(c, 'doBootstrap', Em.K);
  452. });
  453. after(function(){
  454. c.retryHosts.restore();
  455. App.router.get.restore();
  456. c.doBootstrap.restore();
  457. });
  458. it('should callretryHosts with array as arg', function() {
  459. var host = {n: 'c'};
  460. c.set('content', {installOptions: {}});
  461. c.retryHost(host);
  462. expect(c.retryHosts.calledWith([host])).to.equal(true);
  463. });
  464. });
  465. describe('#retrySelectedHosts', function() {
  466. beforeEach(function () {
  467. sinon.spy(c, 'retryHosts');
  468. sinon.stub(App.router, 'get', function () {
  469. return {launchBootstrap: Em.K}
  470. });
  471. sinon.stub(c, 'doBootstrap', Em.K);
  472. });
  473. afterEach(function () {
  474. c.retryHosts.restore();
  475. App.router.get.restore();
  476. c.doBootstrap.restore();
  477. });
  478. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  479. c.set('isRetryDisabled', true);
  480. c.retrySelectedHosts();
  481. expect(c.retryHosts.called).to.equal(false);
  482. });
  483. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  484. c.set('isRetryDisabled', false);
  485. c.set('bootHosts', Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]));
  486. c.retrySelectedHosts();
  487. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  488. expect(c.get('isRetryDisabled')).to.equal(true);
  489. });
  490. });
  491. describe('#startBootstrap', function() {
  492. beforeEach(function(){
  493. sinon.stub(c, 'doBootstrap', Em.K);
  494. });
  495. afterEach(function(){
  496. c.doBootstrap.restore();
  497. });
  498. it('should drop numPolls and registrationStartedAt', function() {
  499. c.set('numPolls', 123);
  500. c.set('registrationStartedAt', 1234);
  501. c.startBootstrap();
  502. expect(c.get('numPolls')).to.equal(0);
  503. expect(c.get('registrationStartedAt')).to.be.null;
  504. });
  505. it('should drop numPolls and registrationStartedAt', function() {
  506. c.set('hosts', Em.A([{name: 'c1'}, {name: 'c2'}]))
  507. c.startBootstrap();
  508. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  509. });
  510. });
  511. describe('#setRegistrationInProgressOnce', function() {
  512. before(function(){
  513. sinon.spy(Em.run, 'once');
  514. });
  515. after(function(){
  516. Em.run.once.restore();
  517. });
  518. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  519. c.setRegistrationInProgressOnce();
  520. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  521. });
  522. });
  523. describe('#setRegistrationInProgress', function() {
  524. var tests = Em.A([
  525. {
  526. bootHosts: [],
  527. isLoaded: false,
  528. e: true,
  529. m: 'no bootHosts and isLoaded is false'
  530. },
  531. {
  532. bootHosts: [],
  533. isLoaded: true,
  534. e: false,
  535. m: 'no bootHosts and isLoaded is true'
  536. },
  537. {
  538. bootHosts: [
  539. Em.Object.create({bootStatus: 'RUNNING'}),
  540. Em.Object.create({bootStatus: 'RUNNING'})
  541. ],
  542. isLoaded: true,
  543. e: true,
  544. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  545. },
  546. {
  547. bootHosts: [
  548. Em.Object.create({bootStatus: 'RUNNING'}),
  549. Em.Object.create({bootStatus: 'RUNNING'})
  550. ],
  551. isLoaded: false,
  552. e: true,
  553. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  554. },
  555. {
  556. bootHosts: [
  557. Em.Object.create({bootStatus: 'REGISTERED'}),
  558. Em.Object.create({bootStatus: 'RUNNING'})
  559. ],
  560. isLoaded: false,
  561. e: true,
  562. m: 'bootHosts with one REGISTERED and isLoaded is false'
  563. },
  564. {
  565. bootHosts: [
  566. Em.Object.create({bootStatus: 'FAILED'}),
  567. Em.Object.create({bootStatus: 'RUNNING'})
  568. ],
  569. isLoaded: false,
  570. e: true,
  571. m: 'bootHosts with one FAILED and isLoaded is false'
  572. },
  573. {
  574. bootHosts: [
  575. Em.Object.create({bootStatus: 'REGISTERED'}),
  576. Em.Object.create({bootStatus: 'RUNNING'})
  577. ],
  578. isLoaded: true,
  579. e: true,
  580. m: 'bootHosts with one REGISTERED and isLoaded is true'
  581. },
  582. {
  583. bootHosts: [
  584. Em.Object.create({bootStatus: 'FAILED'}),
  585. Em.Object.create({bootStatus: 'RUNNING'})
  586. ],
  587. isLoaded: true,
  588. e: true,
  589. m: 'bootHosts with one FAILED and isLoaded is true'
  590. }
  591. ]);
  592. beforeEach(function(){
  593. sinon.stub(c, 'getAllRegisteredHosts', Em.K);
  594. sinon.stub(c, 'disablePreviousSteps', Em.K);
  595. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  596. sinon.stub(c, 'navigateStep', Em.K);
  597. });
  598. afterEach(function(){
  599. c.disablePreviousSteps.restore();
  600. c.getAllRegisteredHosts.restore();
  601. c.setRegistrationInProgressOnce.restore();
  602. c.navigateStep.restore();
  603. });
  604. tests.forEach(function(test) {
  605. it(test.m, function() {
  606. c.set('bootHosts', test.bootHosts);
  607. c.set('isLoaded', test.isLoaded);
  608. c.setRegistrationInProgress();
  609. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  610. });
  611. });
  612. });
  613. describe('#doBootstrap()', function() {
  614. beforeEach(function() {
  615. sinon.spy(App.ajax, 'send');
  616. });
  617. afterEach(function() {
  618. App.ajax.send.restore();
  619. });
  620. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  621. c.set('stopBootstrap', true);
  622. c.doBootstrap();
  623. expect(App.ajax.send.called).to.equal(false);
  624. });
  625. it('should increment numPolls if stopBootstrap is false', function() {
  626. c.set('numPolls', 0);
  627. c.set('stopBootstrap', false);
  628. c.doBootstrap();
  629. expect(App.ajax.send.calledOnce).to.be.true;
  630. expect(c.get('numPolls')).to.equal(1);
  631. });
  632. });
  633. describe('#startRegistration', function() {
  634. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  635. c.set('registrationStartedAt', 1234);
  636. sinon.spy(c, 'isHostsRegistered');
  637. c.startRegistration();
  638. expect(c.isHostsRegistered.called).to.equal(false);
  639. expect(c.get('registrationStartedAt')).to.equal(1234);
  640. c.isHostsRegistered.restore();
  641. });
  642. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  643. c.set('registrationStartedAt', null);
  644. sinon.spy(c, 'isHostsRegistered');
  645. c.startRegistration();
  646. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  647. c.isHostsRegistered.restore();
  648. });
  649. });
  650. describe('#isHostsRegistered', function() {
  651. beforeEach(function() {
  652. sinon.stub(App.ajax, 'send', function() {return {retry: function() {return {then: Em.K}}}});
  653. });
  654. afterEach(function() {
  655. App.ajax.send.restore();
  656. });
  657. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  658. c.set('stopBootstrap', true);
  659. c.isHostsRegistered();
  660. expect(App.ajax.send.called).to.equal(false);
  661. });
  662. it('should do ajax call if stopBootstrap is false', function() {
  663. c.set('stopBootstrap', false);
  664. c.isHostsRegistered();
  665. expect(App.ajax.send.called).to.equal(true);
  666. });
  667. });
  668. describe('#isHostsRegisteredSuccessCallback', function() {
  669. var tests = Em.A([
  670. {
  671. bootHosts: Em.A([
  672. Em.Object.create({bootStatus: 'DONE'})
  673. ]),
  674. data: {items:[]},
  675. registrationStartedAt: 1000000,
  676. m: 'one host DONE',
  677. e: {
  678. bs: 'REGISTERING',
  679. getHostInfoCalled: false
  680. }
  681. },
  682. {
  683. bootHosts: Em.A([
  684. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  685. ]),
  686. data: {items:[{Hosts: {host_name: 'c1'}}]},
  687. m: ' one host REGISTERING',
  688. e: {
  689. bs: 'REGISTERED',
  690. getHostInfoCalled: false
  691. }
  692. },
  693. {
  694. bootHosts: Em.A([
  695. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  696. ]),
  697. data: {items:[{Hosts: {host_name: 'c2'}}]},
  698. registrationStartedAt: 0,
  699. m: 'one host REGISTERING but data missing info about it, timeout',
  700. e: {
  701. bs: 'FAILED',
  702. getHostInfoCalled: false
  703. }
  704. },
  705. {
  706. bootHosts: Em.A([
  707. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  708. ]),
  709. data: {items:[{Hosts: {host_name: 'c2'}}]},
  710. registrationStartedAt: 1000000,
  711. m: 'one host REGISTERING but data missing info about it',
  712. e: {
  713. bs: 'REGISTERING',
  714. getHostInfoCalled: false
  715. }
  716. },
  717. {
  718. bootHosts: Em.A([
  719. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  720. ]),
  721. data: {items:[{Hosts: {host_name: 'c1'}}]},
  722. m: ' one host RUNNING',
  723. e: {
  724. bs: 'RUNNING',
  725. getHostInfoCalled: false
  726. }
  727. }
  728. ]);
  729. beforeEach(function(){
  730. sinon.spy(c, 'getHostInfo');
  731. sinon.stub(App, 'dateTime').returns(1000000);
  732. });
  733. afterEach(function(){
  734. c.getHostInfo.restore();
  735. App.dateTime.restore();
  736. });
  737. tests.forEach(function(test) {
  738. it(test.m, function() {
  739. c.set('content.installedHosts', []);
  740. c.set('bootHosts', test.bootHosts);
  741. c.set('registrationStartedAt', test.registrationStartedAt);
  742. c.isHostsRegisteredSuccessCallback(test.data);
  743. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  744. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  745. });
  746. });
  747. });
  748. describe('#getAllRegisteredHosts', function() {
  749. it('should call App.ajax.send', function() {
  750. sinon.spy(App.ajax, 'send');
  751. c.getAllRegisteredHosts();
  752. expect(App.ajax.send.calledOnce).to.equal(true);
  753. App.ajax.send.restore();
  754. });
  755. });
  756. describe('#getAllRegisteredHostsCallback', function() {
  757. var tests = Em.A([
  758. {
  759. hostsInCluster: ['c3'],
  760. bootHosts: [{name:'c1'},{name:'c2'}],
  761. hosts: Em.A([
  762. {Hosts: {host_name:'c1'}},
  763. {Hosts: {host_name:'c2'}}
  764. ]),
  765. m: 'No registered hosts',
  766. e: {
  767. hasMoreRegisteredHosts: false,
  768. registeredHosts: ''
  769. }
  770. },
  771. {
  772. hostsInCluster: ['c4'],
  773. bootHosts: [{name:'c3'},{name:'c5'}],
  774. hosts: Em.A([
  775. {Hosts: {host_name:'c1'}},
  776. {Hosts: {host_name:'c2'}}
  777. ]),
  778. m: '2 registered hosts',
  779. e: {
  780. hasMoreRegisteredHosts: true,
  781. registeredHosts: ['c1','c2']
  782. }
  783. },
  784. {
  785. hostsInCluster: ['c4'],
  786. bootHosts: [{name:'c1'},{name:'c5'}],
  787. hosts: Em.A([
  788. {Hosts: {host_name:'c1'}},
  789. {Hosts: {host_name:'c2'}}
  790. ]),
  791. m: '1 registered host',
  792. e: {
  793. hasMoreRegisteredHosts: true,
  794. registeredHosts: ['c2']
  795. }
  796. },
  797. {
  798. hostsInCluster: ['c1'],
  799. bootHosts: [{name:'c3'},{name:'c5'}],
  800. hosts: Em.A([
  801. {Hosts: {host_name:'c1'}},
  802. {Hosts: {host_name:'c2'}}
  803. ]),
  804. m: '1 registered host (2)',
  805. e: {
  806. hasMoreRegisteredHosts: true,
  807. registeredHosts: ['c2']
  808. }
  809. }
  810. ]);
  811. tests.forEach(function(test) {
  812. it(test.m, function() {
  813. c.reopen({setRegistrationInProgress: Em.K, hostsInCluster: test.hostsInCluster});
  814. c.set('bootHosts', test.bootHosts);
  815. c.getAllRegisteredHostsCallback({items:test.hosts});
  816. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  817. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  818. });
  819. });
  820. });
  821. describe('#registerErrPopup', function() {
  822. it('should call App.ModalPopup.show', function() {
  823. sinon.spy(App.ModalPopup, 'show');
  824. c.registerErrPopup();
  825. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  826. App.ModalPopup.show.restore();
  827. });
  828. });
  829. describe('#getHostInfo', function() {
  830. it('should do ajax request', function() {
  831. sinon.spy(App.ajax, 'send');
  832. c.getHostInfo();
  833. expect(App.ajax.send.calledOnce).to.equal(true);
  834. App.ajax.send.restore();
  835. });
  836. });
  837. describe('#getHostInfoErrorCallback', function() {
  838. it('should call registerErrPopup', function() {
  839. sinon.spy(c, 'registerErrPopup');
  840. c.getHostInfoErrorCallback();
  841. expect(c.registerErrPopup.calledOnce).to.equal(true);
  842. c.registerErrPopup.restore();
  843. });
  844. });
  845. describe('#stopRegistration', function() {
  846. var tests = Em.A([
  847. {
  848. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  849. e: {isSubmitDisabled: false, isRetryDisabled: true}
  850. },
  851. {
  852. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  853. e: {isSubmitDisabled: true, isRetryDisabled: false}
  854. },
  855. {
  856. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  857. e: {isSubmitDisabled: false, isRetryDisabled: false}
  858. },
  859. {
  860. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  861. e: {isSubmitDisabled: true, isRetryDisabled: true}
  862. }
  863. ]);
  864. tests.forEach(function(test) {
  865. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  866. c.reopen({bootHosts: test.bootHosts});
  867. c.stopRegistration();
  868. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  869. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  870. });
  871. });
  872. });
  873. describe('#submit', function() {
  874. it('if isHostHaveWarnings should show confirmation popup', function() {
  875. c.reopen({isHostHaveWarnings: true});
  876. sinon.spy(App.ModalPopup, 'show');
  877. c.submit();
  878. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  879. App.ModalPopup.show.restore();
  880. });
  881. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  882. var bootHosts = [{name: 'c1'}];
  883. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  884. c.submit().onPrimary();
  885. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  886. });
  887. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  888. var bootHosts = [{name: 'c1'}];
  889. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  890. c.submit();
  891. expect(c.get('confirmedHosts')).to.eql(bootHosts);
  892. });
  893. });
  894. describe('#hostLogPopup', function() {
  895. it('should show App.ModalPopup', function() {
  896. sinon.spy(App.ModalPopup, 'show');
  897. c.hostLogPopup({context:Em.Object.create({})});
  898. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  899. App.ModalPopup.show.restore();
  900. });
  901. });
  902. describe('#rerunChecksSuccessCallback', function() {
  903. beforeEach(function() {
  904. sinon.stub(c, 'parseWarnings', Em.K);
  905. });
  906. afterEach(function() {
  907. c.parseWarnings.restore();
  908. });
  909. it('should set checksUpdateProgress to 100', function() {
  910. c.set('checksUpdateProgress', 0);
  911. c.rerunChecksSuccessCallback({items: []});
  912. expect(c.get('checksUpdateProgress')).to.equal(100);
  913. });
  914. it('should set checksUpdateStatus to SUCCESS', function() {
  915. c.set('checksUpdateStatus', '');
  916. c.rerunChecksSuccessCallback({items: []});
  917. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  918. });
  919. it('should call parseWarnings', function() {
  920. c.rerunChecksSuccessCallback({items: []});
  921. expect(c.parseWarnings.calledOnce).to.equal(true);
  922. });
  923. });
  924. describe('#rerunChecksErrorCallback', function() {
  925. it('should set checksUpdateProgress to 100', function() {
  926. c.set('checksUpdateProgress', 0);
  927. c.rerunChecksErrorCallback({});
  928. expect(c.get('checksUpdateProgress')).to.equal(100);
  929. });
  930. it('should set checksUpdateStatus to FAILED', function() {
  931. c.set('checksUpdateStatus', '');
  932. c.rerunChecksErrorCallback({});
  933. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  934. });
  935. });
  936. describe('#filterBootHosts', function() {
  937. var tests = Em.A([
  938. {
  939. bootHosts: [
  940. Em.Object.create({name: 'c1'}),
  941. Em.Object.create({name: 'c2'})
  942. ],
  943. data: {
  944. items: [
  945. {Hosts: {host_name: 'c1'}}
  946. ]
  947. },
  948. m: 'one host',
  949. e: ['c1']
  950. },
  951. {
  952. bootHosts: [
  953. Em.Object.create({name: 'c1'}),
  954. Em.Object.create({name: 'c2'})
  955. ],
  956. data: {
  957. items: [
  958. {Hosts: {host_name: 'c3'}}
  959. ]
  960. },
  961. m: 'no hosts',
  962. e: []
  963. },
  964. {
  965. bootHosts: [
  966. Em.Object.create({name: 'c1'}),
  967. Em.Object.create({name: 'c2'})
  968. ],
  969. data: {
  970. items: [
  971. {Hosts: {host_name: 'c1'}},
  972. {Hosts: {host_name: 'c2'}}
  973. ]
  974. },
  975. m: 'many hosts',
  976. e: ['c1', 'c2']
  977. }
  978. ]);
  979. tests.forEach(function(test) {
  980. it(test.m, function() {
  981. c.reopen({bootHosts: test.bootHosts});
  982. var filteredData = c.filterBootHosts(test.data);
  983. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  984. });
  985. });
  986. });
  987. describe('#hostWarningsPopup', function() {
  988. it('should show App.ModalPopup', function() {
  989. sinon.stub(App.ModalPopup, 'show', Em.K);
  990. c.hostWarningsPopup();
  991. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  992. App.ModalPopup.show.restore();
  993. });
  994. it('should clear checksUpdateStatus on primary', function() {
  995. c.set('checksUpdateStatus', 'not null value');
  996. c.hostWarningsPopup().onPrimary();
  997. expect(c.get('checksUpdateStatus')).to.be.null;
  998. });
  999. it('should clear checksUpdateStatus on close', function() {
  1000. c.set('checksUpdateStatus', 'not null value');
  1001. c.hostWarningsPopup().onClose();
  1002. expect(c.get('checksUpdateStatus')).to.be.null;
  1003. });
  1004. it('should rerunChecks onSecondary', function() {
  1005. sinon.stub(c, 'rerunChecks', Em.K);
  1006. c.hostWarningsPopup().onSecondary();
  1007. expect(c.rerunChecks.calledOnce).to.equal(true);
  1008. });
  1009. });
  1010. describe('#registeredHostsPopup', function() {
  1011. it('should show App.ModalPopup', function() {
  1012. sinon.spy(App.ModalPopup, 'show');
  1013. c.registeredHostsPopup();
  1014. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1015. App.ModalPopup.show.restore();
  1016. });
  1017. });
  1018. describe('#parseWarnings', function() {
  1019. beforeEach(function() {
  1020. sinon.stub(App, 'get', function(k) {
  1021. if ('testMode' === k) return false;
  1022. return Em.get(App, k);
  1023. });
  1024. sinon.stub(c, 'filterBootHosts', function(k) {return k;});
  1025. });
  1026. afterEach(function() {
  1027. App.get.restore();
  1028. c.filterBootHosts.restore();
  1029. });
  1030. it('no warnings if last_agent_env isn\'t specified', function() {
  1031. c.set('warnings', [{}]);
  1032. c.set('warningsByHost', [{},{}]);
  1033. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  1034. expect(c.get('warnings')).to.eql([]);
  1035. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  1036. });
  1037. Em.A([
  1038. {
  1039. m: 'parse stackFoldersAndFiles',
  1040. tests : Em.A([
  1041. {
  1042. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  1043. m: 'empty stackFoldersAndFiles',
  1044. e: {
  1045. warnings: [],
  1046. warningsByHost: [0]
  1047. }
  1048. },
  1049. {
  1050. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  1051. m: 'not empty stackFoldersAndFiles',
  1052. e: {
  1053. warnings: [{
  1054. name: 'n1',
  1055. hosts: ['c1'],
  1056. onSingleHost: true,
  1057. category: 'fileFolders'
  1058. }],
  1059. warningsByHost: [1]
  1060. }
  1061. },
  1062. {
  1063. items: [
  1064. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  1065. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  1066. ],
  1067. m: 'not empty stackFoldersAndFiles on two hosts',
  1068. e: {
  1069. warnings: [{
  1070. name: 'n1',
  1071. hosts: ['c1', 'c2'],
  1072. onSingleHost: false,
  1073. category: 'fileFolders'
  1074. }],
  1075. warningsByHost: [1]
  1076. }
  1077. }
  1078. ])
  1079. },
  1080. {
  1081. m: 'parse installedPackages',
  1082. tests : Em.A([
  1083. {
  1084. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1085. m: 'empty installedPackages',
  1086. e: {
  1087. warnings: [],
  1088. warningsByHost: [0]
  1089. }
  1090. },
  1091. {
  1092. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1093. m: 'not empty installedPackages',
  1094. e: {
  1095. warnings: [{
  1096. name: 'n1',
  1097. hosts: ['c1'],
  1098. onSingleHost: true,
  1099. category: 'packages'
  1100. }],
  1101. warningsByHost: [1]
  1102. }
  1103. },
  1104. {
  1105. items: [
  1106. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1107. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1108. ],
  1109. m: 'not empty installedPackages on two hosts',
  1110. e: {
  1111. warnings: [{
  1112. name: 'n1',
  1113. hosts: ['c1', 'c2'],
  1114. onSingleHost: false,
  1115. category: 'packages'
  1116. }],
  1117. warningsByHost: [1]
  1118. }
  1119. }
  1120. ])
  1121. },
  1122. {
  1123. m: 'parse hostHealth.liveServices',
  1124. tests : Em.A([
  1125. {
  1126. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1127. m: 'empty hostHealth',
  1128. e: {
  1129. warnings: [],
  1130. warningsByHost: [0]
  1131. }
  1132. },
  1133. {
  1134. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1135. m: 'empty liveServices',
  1136. e: {
  1137. warnings: [],
  1138. warningsByHost: [0]
  1139. }
  1140. },
  1141. {
  1142. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1143. m: 'not empty hostHealth.liveServices',
  1144. e: {
  1145. warnings: [{
  1146. name: 'n1',
  1147. hosts: ['c1'],
  1148. onSingleHost: true,
  1149. category: 'services'
  1150. }],
  1151. warningsByHost: [1]
  1152. }
  1153. },
  1154. {
  1155. items: [
  1156. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1157. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1158. ],
  1159. m: 'not empty hostHealth.liveServices on two hosts',
  1160. e: {
  1161. warnings: [{
  1162. name: 'n1',
  1163. hosts: ['c1', 'c2'],
  1164. onSingleHost: false,
  1165. category: 'services'
  1166. }],
  1167. warningsByHost: [1, 1]
  1168. }
  1169. }
  1170. ])
  1171. },
  1172. {
  1173. m: 'parse existingUsers',
  1174. tests : Em.A([
  1175. {
  1176. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1177. m: 'empty existingUsers',
  1178. e: {
  1179. warnings: [],
  1180. warningsByHost: [0]
  1181. }
  1182. },
  1183. {
  1184. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1185. m: 'not empty existingUsers',
  1186. e: {
  1187. warnings: [{
  1188. name: 'n1',
  1189. hosts: ['c1'],
  1190. onSingleHost: true,
  1191. category: 'users'
  1192. }],
  1193. warningsByHost: [1]
  1194. }
  1195. },
  1196. {
  1197. items: [
  1198. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1199. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1200. ],
  1201. m: 'not empty existingUsers on two hosts',
  1202. e: {
  1203. warnings: [{
  1204. name: 'n1',
  1205. hosts: ['c1', 'c2'],
  1206. onSingleHost: false,
  1207. category: 'users'
  1208. }],
  1209. warningsByHost: [1, 1]
  1210. }
  1211. }
  1212. ])
  1213. },
  1214. {
  1215. m: 'parse alternatives',
  1216. tests : Em.A([
  1217. {
  1218. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1219. m: 'empty alternatives',
  1220. e: {
  1221. warnings: [],
  1222. warningsByHost: [0]
  1223. }
  1224. },
  1225. {
  1226. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1227. m: 'not empty alternatives',
  1228. e: {
  1229. warnings: [{
  1230. name: 'n1',
  1231. hosts: ['c1'],
  1232. onSingleHost: true,
  1233. category: 'alternatives'
  1234. }],
  1235. warningsByHost: [1]
  1236. }
  1237. },
  1238. {
  1239. items: [
  1240. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1241. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1242. ],
  1243. m: 'not empty alternatives on two hosts',
  1244. e: {
  1245. warnings: [{
  1246. name: 'n1',
  1247. hosts: ['c1', 'c2'],
  1248. onSingleHost: false,
  1249. category: 'alternatives'
  1250. }],
  1251. warningsByHost: [1, 1]
  1252. }
  1253. }
  1254. ])
  1255. },
  1256. {
  1257. m: 'parse hostHealth.activeJavaProcs',
  1258. tests : Em.A([
  1259. {
  1260. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1261. m: 'empty hostHealth',
  1262. e: {
  1263. warnings: [],
  1264. warningsByHost: [0]
  1265. }
  1266. },
  1267. {
  1268. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1269. m: 'empty activeJavaProcs',
  1270. e: {
  1271. warnings: [],
  1272. warningsByHost: [0]
  1273. }
  1274. },
  1275. {
  1276. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1277. m: 'not empty hostHealth.activeJavaProcs',
  1278. e: {
  1279. warnings: [{
  1280. pid: 'n1',
  1281. hosts: ['c1'],
  1282. onSingleHost: true,
  1283. category: 'processes'
  1284. }],
  1285. warningsByHost: [1]
  1286. }
  1287. },
  1288. {
  1289. items: [
  1290. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1291. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1292. ],
  1293. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1294. e: {
  1295. warnings: [{
  1296. pid: 'n1',
  1297. hosts: ['c1', 'c2'],
  1298. onSingleHost: false,
  1299. category: 'processes'
  1300. }],
  1301. warningsByHost: [1, 1]
  1302. }
  1303. }
  1304. ])
  1305. }
  1306. ]).forEach(function(category) {
  1307. describe(category.m, function() {
  1308. category.tests.forEach(function(test) {
  1309. it(test.m, function() {
  1310. c.parseWarnings({items: test.items});
  1311. c.get('warnings').forEach(function(w, i) {
  1312. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1313. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1314. });
  1315. });
  1316. for(var i in test.e.warningsByHost) {
  1317. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1318. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1319. }
  1320. }
  1321. });
  1322. });
  1323. });
  1324. });
  1325. it('should parse umask warnings', function() {
  1326. var items = [
  1327. {Hosts:{host_name: 'c1', last_agent_env: {umask: 18}}},
  1328. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1329. ];
  1330. c.parseWarnings({items: items});
  1331. var warnings = c.get('warnings');
  1332. expect(warnings.length).to.equal(1);
  1333. expect(warnings[0].hosts).to.eql(['c2']);
  1334. expect(warnings[0].onSingleHost).to.equal(true);
  1335. });
  1336. it('should parse umask warnings (2)', function() {
  1337. var items = [
  1338. {Hosts:{host_name: 'c1', last_agent_env: {umask: 8}}},
  1339. {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
  1340. ];
  1341. c.parseWarnings({items: items});
  1342. var warnings = c.get('warnings');
  1343. expect(warnings.length).to.equal(2);
  1344. expect(warnings.mapProperty('hosts')).to.eql([['c1'], ['c2']]);
  1345. });
  1346. it('should parse firewall warnings', function() {
  1347. var items = [
  1348. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1349. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
  1350. ];
  1351. c.parseWarnings({items: items});
  1352. var warnings = c.get('warnings');
  1353. expect(warnings.length).to.equal(1);
  1354. expect(warnings[0].hosts).to.eql(['c1']);
  1355. expect(warnings[0].onSingleHost).to.equal(true);
  1356. });
  1357. it('should parse firewall warnings (2)', function() {
  1358. var items = [
  1359. {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
  1360. {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
  1361. ];
  1362. c.parseWarnings({items: items});
  1363. var warnings = c.get('warnings');
  1364. expect(warnings.length).to.equal(1);
  1365. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1366. expect(warnings[0].onSingleHost).to.equal(false);
  1367. });
  1368. it('should parse reverseLookup warnings', function() {
  1369. var items = [
  1370. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: true}}}
  1371. ];
  1372. c.parseWarnings({items: items});
  1373. var warnings = c.get('warnings');
  1374. expect(warnings.length).to.equal(0);
  1375. });
  1376. it('should parse reverseLookup warnings (2)', function() {
  1377. var items = [
  1378. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}}
  1379. ];
  1380. c.parseWarnings({items: items});
  1381. var warnings = c.get('warnings');
  1382. expect(warnings.length).to.equal(1);
  1383. expect(warnings[0].hosts).to.eql(['c1']);
  1384. expect(warnings[0].onSingleHost).to.equal(true);
  1385. });
  1386. it('should parse reverseLookup warnings (3)', function() {
  1387. var items = [
  1388. {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}},
  1389. {Hosts:{host_name: 'c2', last_agent_env: {reverseLookup: false}}}
  1390. ];
  1391. c.parseWarnings({items: items});
  1392. var warnings = c.get('warnings');
  1393. expect(warnings.length).to.equal(1);
  1394. expect(warnings[0].hosts).to.eql(['c1','c2']);
  1395. expect(warnings[0].onSingleHost).to.equal(false);
  1396. });
  1397. });
  1398. describe('#navigateStep', function() {
  1399. beforeEach(function(){
  1400. sinon.stub(c, 'startBootstrap', Em.K);
  1401. });
  1402. afterEach(function(){
  1403. c.startBootstrap.restore();
  1404. });
  1405. Em.A([
  1406. {
  1407. isLoaded: true,
  1408. manualInstall: false,
  1409. bootStatus: false,
  1410. m: 'should call startBootstrap',
  1411. e: true
  1412. },
  1413. {
  1414. isLoaded: true,
  1415. manualInstall: false,
  1416. bootStatus: true,
  1417. m: 'shouldn\'t call startBootstrap (1)',
  1418. e: false
  1419. },
  1420. {
  1421. isLoaded: false,
  1422. manualInstall: false,
  1423. bootStatus: false,
  1424. m: 'shouldn\'t call startBootstrap (2)',
  1425. e: false
  1426. },
  1427. {
  1428. isLoaded: false,
  1429. manualInstall: true,
  1430. bootStatus: false,
  1431. m: 'shouldn\'t call startBootstrap (3)',
  1432. e: false
  1433. }
  1434. ]).forEach(function(test) {
  1435. it(test.m, function() {
  1436. c.reopen({
  1437. isLoaded: test.isLoaded,
  1438. content: {
  1439. installedHosts: [],
  1440. installOptions: {
  1441. manualInstall: test.manualInstall
  1442. }
  1443. },
  1444. wizardController: Em.Object.create({
  1445. getDBProperty: function() {
  1446. return test.bootStatus
  1447. }
  1448. })
  1449. });
  1450. c.navigateStep();
  1451. if(test.e) {
  1452. expect(c.startBootstrap.calledOnce).to.equal(true);
  1453. }
  1454. else {
  1455. expect(c.startBootstrap.called).to.equal(false);
  1456. }
  1457. });
  1458. });
  1459. it('should set test data if testMode is true', function() {
  1460. c.reopen({
  1461. isLoaded: true,
  1462. hosts: [{}, {}, {}],
  1463. content: {
  1464. installedHosts: [],
  1465. installOptions: {
  1466. manualInstall: true
  1467. }
  1468. },
  1469. setRegistrationInProgress: Em.K
  1470. });
  1471. sinon.stub(App, 'get', function(k) {
  1472. if('testMode' === k) return true;
  1473. return Em.get(App, k);
  1474. });
  1475. c.navigateStep();
  1476. App.get.restore();
  1477. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1478. expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
  1479. expect(c.get('bootHosts').everyProperty('memory', '2000000')).to.equal(true);
  1480. expect(c.get('isSubmitDisabled')).to.equal(false);
  1481. });
  1482. it('should start registration', function() {
  1483. c.reopen({
  1484. isLoaded: true,
  1485. hosts: [{}, {}, {}],
  1486. content: {
  1487. installedHosts: [],
  1488. installOptions: {
  1489. manualInstall: true
  1490. }
  1491. },
  1492. setRegistrationInProgress: Em.K,
  1493. startRegistration: Em.K
  1494. });
  1495. sinon.spy(c, 'startRegistration');
  1496. sinon.stub(App, 'get', function(k) {
  1497. if('testMode' === k) return false;
  1498. return Em.get(App, k);
  1499. });
  1500. c.navigateStep();
  1501. App.get.restore();
  1502. expect(c.startRegistration.calledOnce).to.equal(true);
  1503. expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
  1504. expect(c.get('registrationStartedAt')).to.be.null;
  1505. c.startRegistration.restore();
  1506. });
  1507. });
  1508. describe('#checkHostDiskSpace', function() {
  1509. Em.A([
  1510. {
  1511. diskInfo: [
  1512. {
  1513. available: App.minDiskSpace * 1024 * 1024 - 1024,
  1514. mountpoint: '/'
  1515. }
  1516. ],
  1517. m: 'available less than App.minDiskSpace',
  1518. e: false
  1519. },
  1520. {
  1521. diskInfo: [
  1522. {
  1523. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1524. mountpoint: '/usr'
  1525. }
  1526. ],
  1527. m: 'available less than App.minDiskSpaceUsrLib (1)',
  1528. e: false
  1529. },
  1530. {
  1531. diskInfo: [
  1532. {
  1533. available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
  1534. mountpoint: '/usr/lib'
  1535. }
  1536. ],
  1537. m: 'available less than App.minDiskSpaceUsrLib (2)',
  1538. e: false
  1539. },
  1540. {
  1541. diskInfo: [
  1542. {
  1543. available: App.minDiskSpace * 1024 * 1024 + 1024,
  1544. mountpoint: '/'
  1545. }
  1546. ],
  1547. m: 'available greater than App.minDiskSpace',
  1548. e: true
  1549. },
  1550. {
  1551. diskInfo: [
  1552. {
  1553. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1554. mountpoint: '/usr'
  1555. }
  1556. ],
  1557. m: 'available greater than App.minDiskSpaceUsrLib (1)',
  1558. e: true
  1559. },
  1560. {
  1561. diskInfo: [
  1562. {
  1563. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1564. mountpoint: '/usr/lib'
  1565. }
  1566. ],
  1567. m: 'available greater than App.minDiskSpaceUsrLib (2)',
  1568. e: true
  1569. },
  1570. {
  1571. diskInfo: [
  1572. {
  1573. available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
  1574. mountpoint: '/home/tdk'
  1575. }
  1576. ],
  1577. m: 'mount point without free space checks',
  1578. e: true
  1579. }
  1580. ]).forEach(function (test) {
  1581. it(test.m, function () {
  1582. var r = c.checkHostDiskSpace('', test.diskInfo);
  1583. expect(Em.isEmpty(r)).to.equal(test.e);
  1584. });
  1585. });
  1586. });
  1587. describe('#checkHostOSType', function() {
  1588. it('should return empty string if no stacks provided', function() {
  1589. c.reopen({content: {stacks: null}});
  1590. expect(c.checkHostOSType()).to.equal('');
  1591. });
  1592. it('os type is valid', function() {
  1593. var osType = 'redhat6';
  1594. c.reopen({
  1595. content: {
  1596. stacks: [
  1597. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: osType})]})
  1598. ]
  1599. }
  1600. });
  1601. expect(c.checkHostOSType(osType, '')).to.equal('');
  1602. });
  1603. it('os type is invalid', function() {
  1604. var osType = 'os2';
  1605. c.reopen({
  1606. content: {
  1607. stacks: [
  1608. Em.Object.create({isSelected: true, operatingSystems: [Em.Object.create({isSelected: true, osType: 'os1'})]})
  1609. ]
  1610. }
  1611. });
  1612. expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
  1613. });
  1614. });
  1615. describe('#getHostInfoSuccessCallback', function() {
  1616. beforeEach(function() {
  1617. sinon.stub(c, 'parseWarnings', Em.K);
  1618. sinon.stub(c, 'stopRegistration', Em.K);
  1619. });
  1620. afterEach(function() {
  1621. c.parseWarnings.restore();
  1622. c.stopRegistration.restore();
  1623. });
  1624. it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', function() {
  1625. sinon.spy(c, '_setHostDataWithSkipBootstrap');
  1626. sinon.stub(App, 'get', function(k) {
  1627. if ('skipBootstrap' === k) return true;
  1628. if ('testMode' === k) return false;
  1629. return Em.get(App, k);
  1630. });
  1631. c.reopen({
  1632. bootHosts: [Em.Object.create({name: 'h1'})]
  1633. });
  1634. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1635. c.getHostInfoSuccessCallback(jsonData);
  1636. expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
  1637. App.get.restore();
  1638. c._setHostDataWithSkipBootstrap.restore();
  1639. });
  1640. it('should add repo warnings', function() {
  1641. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1642. sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
  1643. sinon.stub(c, 'checkHostDiskSpace', Em.K);
  1644. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1645. sinon.stub(App, 'get', function(k) {
  1646. if ('skipBootstrap' === k) return false;
  1647. if ('testMode' === k) return false;
  1648. return Em.get(App, k);
  1649. });
  1650. c.reopen({
  1651. bootHosts: [Em.Object.create({name: 'h1'})]
  1652. });
  1653. c.getHostInfoSuccessCallback(jsonData);
  1654. expect(c.get('repoCategoryWarnings.length')).to.equal(1);
  1655. expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1656. c.checkHostOSType.restore();
  1657. c.checkHostDiskSpace.restore();
  1658. c._setHostDataFromLoadedHostInfo.restore();
  1659. App.get.restore();
  1660. });
  1661. it('should add disk warnings', function() {
  1662. var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
  1663. sinon.stub(c, 'checkHostDiskSpace', function() {return 'not_null_value';});
  1664. sinon.stub(c, 'checkHostOSType', Em.K);
  1665. sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
  1666. sinon.stub(App, 'get', function(k) {
  1667. if ('skipBootstrap' === k) return false;
  1668. if ('testMode' === k) return false;
  1669. return Em.get(App, k);
  1670. });
  1671. c.reopen({
  1672. bootHosts: [Em.Object.create({name: 'h1'})]
  1673. });
  1674. c.getHostInfoSuccessCallback(jsonData);
  1675. expect(c.get('diskCategoryWarnings.length')).to.equal(1);
  1676. expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
  1677. c.checkHostOSType.restore();
  1678. c.checkHostDiskSpace.restore();
  1679. c._setHostDataFromLoadedHostInfo.restore();
  1680. App.get.restore();
  1681. });
  1682. });
  1683. describe('#_setHostDataWithSkipBootstrap', function() {
  1684. it('should set mock-data', function() {
  1685. var host = Em.Object.create({});
  1686. c._setHostDataWithSkipBootstrap(host);
  1687. expect(host.get('cpu')).to.equal(2);
  1688. expect(host.get('memory')).to.equal('2000000.00');
  1689. expect(host.get('disk_info.length')).to.equal(4);
  1690. });
  1691. });
  1692. describe('#_setHostDataFromLoadedHostInfo', function() {
  1693. it('should set data from hostInfo', function() {
  1694. var host = Em.Object.create(),
  1695. hostInfo = {
  1696. Hosts: {
  1697. cpu_count: 2,
  1698. total_mem: 12345,
  1699. os_type: 't1',
  1700. os_arch: 'os1',
  1701. ip: '0.0.0.0',
  1702. disk_info: [
  1703. {mountpoint: '/boot'},
  1704. {mountpoint: '/usr'},
  1705. {mountpoint: '/no-boot'},
  1706. {mountpoint: '/boot'}
  1707. ]
  1708. }
  1709. };
  1710. c._setHostDataFromLoadedHostInfo(host, hostInfo);
  1711. expect(host.get('cpu')).to.equal(2);
  1712. expect(host.get('os_type')).to.equal('t1');
  1713. expect(host.get('os_arch')).to.equal('os1');
  1714. expect(host.get('ip')).to.equal('0.0.0.0');
  1715. expect(host.get('memory')).to.equal('12345.00');
  1716. expect(host.get('disk_info.length')).to.equal(2);
  1717. });
  1718. });
  1719. describe('#getJDKName', function() {
  1720. beforeEach(function() {
  1721. sinon.stub($, 'ajax', Em.K);
  1722. sinon.stub(App, 'get', function(k) {
  1723. if ('testMode' === k) return false;
  1724. return Em.get(App, k);
  1725. });
  1726. });
  1727. afterEach(function() {
  1728. $.ajax.restore();
  1729. App.get.restore();
  1730. });
  1731. it('should do proper request to ambari-server', function() {
  1732. c.getJDKName();
  1733. expect($.ajax.args[0][0].type).to.contain('GET');
  1734. 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');
  1735. });
  1736. });
  1737. describe('#getJDKNameSuccessCallback', function() {
  1738. it('should set proper data to controller properties', function() {
  1739. var expected = {
  1740. name: 'name',
  1741. home: 'home',
  1742. location: 'location'
  1743. },
  1744. data = {
  1745. RootServiceComponents: {
  1746. properties: {
  1747. 'jdk.name': expected.name,
  1748. 'java.home': expected.home,
  1749. 'jdk_location': expected.location
  1750. }
  1751. }
  1752. };
  1753. c.getJDKNameSuccessCallback(data);
  1754. expect(c.get('needJDKCheckOnHosts')).to.equal(false);
  1755. expect(c.get('jdkLocation')).to.equal(expected.location);
  1756. expect(c.get('javaHome')).to.equal(expected.home);
  1757. });
  1758. });
  1759. describe('#doCheckJDK', function() {
  1760. beforeEach(function() {
  1761. sinon.stub($, 'ajax', Em.K);
  1762. sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
  1763. sinon.stub(App, 'get', function(k) {
  1764. if ('testMode' === k) return false;
  1765. return Em.get(App, k);
  1766. });
  1767. });
  1768. afterEach(function() {
  1769. $.ajax.restore();
  1770. c.setRegistrationInProgressOnce.restore();
  1771. App.get.restore();
  1772. });
  1773. it('should do proper request to the ambari-server', function() {
  1774. var bootHosts = [{name: 'n1'}, {name: 'n2'}],
  1775. javaHome = '/java',
  1776. jdkLocation = '/jdk';
  1777. c.reopen({
  1778. bootHosts: bootHosts,
  1779. javaHome: javaHome,
  1780. jdkLocation: jdkLocation
  1781. });
  1782. c.doCheckJDK();
  1783. var request = $.ajax.args[0][0], data = JSON.parse(request.data);
  1784. expect(request.type).to.equal('POST');
  1785. expect(request.url).to.contain('/requests');
  1786. expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
  1787. expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
  1788. expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
  1789. });
  1790. });
  1791. describe('#doCheckJDKsuccessCallback', function() {
  1792. beforeEach(function() {
  1793. sinon.stub($, 'ajax', Em.K);
  1794. sinon.stub(App, 'get', function(k) {
  1795. if ('testMode' === k) return false;
  1796. return Em.get(App, k);
  1797. });
  1798. });
  1799. afterEach(function() {
  1800. $.ajax.restore();
  1801. App.get.restore();
  1802. });
  1803. it('should set jdkRequestIndex if data provided', function() {
  1804. var data = {
  1805. href: '/a/b/c'
  1806. },
  1807. expected = 'c';
  1808. c.set('jdkRequestIndex', null);
  1809. c.doCheckJDKsuccessCallback(data);
  1810. expect(c.get('jdkRequestIndex')).to.equal(expected);
  1811. });
  1812. it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function() {
  1813. var data = null,
  1814. expected = true;
  1815. c.set('isJDKWarningsLoaded', false);
  1816. c.set('jdkCategoryWarnings', {});
  1817. c.doCheckJDKsuccessCallback(data);
  1818. expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
  1819. });
  1820. it('should do propert request to ambari-server', function() {
  1821. var data = null,
  1822. jdkRequestIndex = 'jdkRequestIndex',
  1823. url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
  1824. c.set('jdkRequestIndex', jdkRequestIndex);
  1825. c.set('jdkCategoryWarnings', null);
  1826. c.doCheckJDKsuccessCallback(data);
  1827. expect($.ajax.args[0][0].type).to.equal('GET');
  1828. expect($.ajax.args[0][0].url).to.contain(url);
  1829. });
  1830. });
  1831. describe('#doCheckJDKerrorCallback', function() {
  1832. it('should set isJDKWarningsLoaded to true', function() {
  1833. c.set('isJDKWarningsLoaded', false);
  1834. c.doCheckJDKerrorCallback();
  1835. c.set('isJDKWarningsLoaded', true);
  1836. });
  1837. });
  1838. describe('#parseJDKCheckResults', function() {
  1839. beforeEach(function() {
  1840. sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
  1841. });
  1842. afterEach(function() {
  1843. c.doCheckJDKsuccessCallback.restore();
  1844. });
  1845. it('should set jdkCategoryWarnings to null if no data', function() {
  1846. var data = {Requests: {}};
  1847. c.set('jdkCategoryWarnings', {});
  1848. c.parseJDKCheckResults(data);
  1849. expect(c.get('jdkCategoryWarnings')).to.be.null;
  1850. });
  1851. it('should parse warnings (1)', function() {
  1852. var data = {
  1853. Requests: {
  1854. end_time: 1
  1855. },
  1856. tasks: []
  1857. };
  1858. c.set('jdkCategoryWarnings', {});
  1859. c.parseJDKCheckResults(data);
  1860. expect(c.get('jdkCategoryWarnings')).to.eql([]);
  1861. });
  1862. it('should parse warnings (2)', function() {
  1863. var data = {
  1864. Requests: {
  1865. end_time: 1
  1866. },
  1867. tasks: [
  1868. {
  1869. Tasks: {
  1870. host_name: 'h1',
  1871. structured_out: {
  1872. java_home_check: {
  1873. exit_code: 1
  1874. }
  1875. }
  1876. }
  1877. },
  1878. {
  1879. Tasks: {
  1880. host_name: 'h2',
  1881. structured_out: {
  1882. java_home_check: {
  1883. exit_code: 0
  1884. }
  1885. }
  1886. }
  1887. }
  1888. ]
  1889. };
  1890. c.set('jdkCategoryWarnings', {});
  1891. c.parseJDKCheckResults(data);
  1892. var result = c.get('jdkCategoryWarnings');
  1893. expect(result.length).to.equal(1);
  1894. expect(result[0].hostsNames).to.eql(['h1']);
  1895. });
  1896. });
  1897. });