step3_test.js 88 KB

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