step3_test.js 89 KB

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