step3_test.js 70 KB

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