step3_test.js 88 KB

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