step3_test.js 65 KB

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