step6_test.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  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 validationUtils = require('utils/validator');
  20. require('utils/helper');
  21. require('controllers/wizard/step6_controller');
  22. var controller,
  23. services = [
  24. Em.Object.create({
  25. serviceName: 'YARN',
  26. isSelected: true
  27. }),
  28. Em.Object.create({
  29. serviceName: 'HBASE',
  30. isSelected: true
  31. }),
  32. Em.Object.create({
  33. serviceName: 'HDFS',
  34. isSelected: true
  35. }),
  36. Em.Object.create({
  37. serviceName: 'STORM',
  38. isSelected: true
  39. }),
  40. Em.Object.create({
  41. serviceName: 'FLUME',
  42. isSelected: true
  43. })
  44. ];
  45. function getController() {
  46. var c = App.WizardStep6Controller.create({
  47. content: Em.Object.create({
  48. hosts: {},
  49. masterComponentHosts: {},
  50. services: services,
  51. controllerName: ''
  52. })
  53. });
  54. var h = {}, m = [];
  55. Em.A(['host0', 'host1', 'host2', 'host3']).forEach(function (hostName) {
  56. var obj = Em.Object.create({
  57. name: hostName,
  58. hostName: hostName,
  59. bootStatus: 'REGISTERED'
  60. });
  61. h[hostName] = obj;
  62. m.push(obj);
  63. });
  64. c.set('content.hosts', h);
  65. c.set('content.masterComponentHosts', m);
  66. c.set('isMasters', false);
  67. return c;
  68. }
  69. describe('App.WizardStep6Controller', function () {
  70. beforeEach(function () {
  71. controller = getController();
  72. });
  73. App.TestAliases.testAsComputedEqual(getController(), 'isAddHostWizard', 'content.controllerName', 'addHostController');
  74. describe('#installedServiceNames', function () {
  75. it(' should filter content.services by isInstalled property', function () {
  76. var _services = Em.A([]);
  77. _services.pushObjects(Em.A([{isInstalled: true, serviceName: "service1"},
  78. {isInstalled: false, serviceName: "service2"},
  79. {isInstalled: true, serviceName: "service3"},
  80. {isInstalled: false, serviceName: "service4"},
  81. {isInstalled: true, serviceName: "service5"}]));
  82. controller.set('content.services', _services);
  83. expect(controller.get('installedServiceNames')).to.eql(["service1", "service3", "service5"]);
  84. });
  85. });
  86. describe('#showValidationIssuesAcceptBox', function () {
  87. it('should return true if success callback', function () {
  88. var deffer = jQuery.Deferred();
  89. function callback() {
  90. deffer.resolve(true);
  91. }
  92. controller.showValidationIssuesAcceptBox(callback);
  93. jQuery.when(deffer.promise()).then(function(data) {
  94. expect(data).to.equal(true);
  95. });
  96. });
  97. });
  98. describe('#selectAllNodes', function () {
  99. var hostsObj = Em.A([Em.Object.create({
  100. hasMaster: false,
  101. isInstalled: false,
  102. checkboxes: Em.A([
  103. Em.Object.create({
  104. title: 'l1',
  105. component: 'name',
  106. isInstalled: false,
  107. checked: false
  108. })
  109. ])
  110. })]);
  111. var obj = Em.Object.create({
  112. context: {
  113. name: "name"
  114. }
  115. });
  116. var clientComponents = Em.A([{component_name: "name1"}]);
  117. it('should make checkbox checked', function () {
  118. controller.set('hosts', hostsObj);
  119. controller.set('content.clients', clientComponents);
  120. controller.selectAllNodes(obj);
  121. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  122. hasMaster: false,
  123. isInstalled: false,
  124. checkboxes: Em.A([
  125. Em.Object.create({
  126. title: 'l1',
  127. component: 'name',
  128. isInstalled: false,
  129. checked: true
  130. })
  131. ])
  132. })]));
  133. });
  134. });
  135. describe('#deselectAllNodes', function () {
  136. var hostsObj = Em.A([Em.Object.create({
  137. hasMaster: false,
  138. isInstalled: false,
  139. checkboxes: Em.A([
  140. Em.Object.create({
  141. title: 'l1',
  142. component: 'name',
  143. isInstalled: false,
  144. checked: true
  145. })
  146. ])
  147. })]);
  148. var obj = Em.Object.create({
  149. context: {
  150. name: "name"
  151. }
  152. });
  153. var clientComponents = Em.A([{component_name: "name1"}]);
  154. it('should uncheck checkbox', function () {
  155. controller.set('hosts', hostsObj);
  156. controller.set('content.clients', clientComponents);
  157. controller.deselectAllNodes(obj);
  158. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  159. hasMaster: false,
  160. isInstalled: false,
  161. checkboxes: Em.A([
  162. Em.Object.create({
  163. title: 'l1',
  164. component: 'name',
  165. isInstalled: false,
  166. checked: false
  167. })
  168. ])
  169. })]));
  170. });
  171. });
  172. describe('#renderSlaves()', function () {
  173. var hostsObj = [{}];
  174. beforeEach(function() {
  175. sinon.stub(controller, 'selectRecommendedComponents');
  176. sinon.stub(controller, 'setInstalledComponents');
  177. sinon.stub(controller, 'restoreComponentsSelection');
  178. sinon.stub(controller, 'selectClientHost');
  179. });
  180. afterEach(function() {
  181. controller.selectRecommendedComponents.restore();
  182. controller.setInstalledComponents.restore();
  183. controller.restoreComponentsSelection.restore();
  184. controller.selectClientHost.restore();
  185. });
  186. describe("slaveComponents is null", function() {
  187. beforeEach(function() {
  188. controller.set('content.slaveComponentHosts', null);
  189. });
  190. it("selectRecommendedComponents should be called", function() {
  191. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  192. expect(controller.selectRecommendedComponents.calledWith(hostsObj)).to.be.true;
  193. });
  194. it("setInstalledComponents should be called", function() {
  195. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  196. expect(controller.setInstalledComponents.calledWith(hostsObj)).to.be.true;
  197. });
  198. it("restoreComponentsSelection should not be called", function() {
  199. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  200. expect(controller.restoreComponentsSelection.called).to.be.false;
  201. });
  202. it("selectClientHost should be called", function() {
  203. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  204. expect(controller.selectClientHost.calledWith(hostsObj)).to.be.true;
  205. });
  206. });
  207. describe("slaveComponents is defined", function() {
  208. var slaveComponentHosts = [{}];
  209. beforeEach(function() {
  210. controller.set('content.slaveComponentHosts', slaveComponentHosts);
  211. });
  212. it("selectRecommendedComponents should not be called", function() {
  213. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  214. expect(controller.selectRecommendedComponents.called).to.be.false;
  215. });
  216. it("setInstalledComponents should not be called", function() {
  217. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  218. expect(controller.setInstalledComponents.called).to.be.false;
  219. });
  220. it("restoreComponentsSelection should be called", function() {
  221. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  222. expect(controller.restoreComponentsSelection.calledWith(hostsObj, slaveComponentHosts)).to.be.true;
  223. });
  224. it("selectClientHost should be called", function() {
  225. expect(controller.renderSlaves(hostsObj)).to.eql(hostsObj);
  226. expect(controller.selectClientHost.calledWith(hostsObj)).to.be.true;
  227. });
  228. });
  229. });
  230. describe("#setInstalledComponents()", function() {
  231. var hostsObj = [{
  232. hostName: 'host1',
  233. checkboxes: [
  234. {
  235. component: 'C1',
  236. isInstalled: false
  237. },
  238. {
  239. component: 'C2',
  240. isInstalled: false
  241. }
  242. ]
  243. }];
  244. it("installedHosts is null", function() {
  245. controller.set('content.installedHosts', null);
  246. expect(controller.setInstalledComponents(hostsObj)).to.be.false;
  247. });
  248. it("installedHosts is defined", function() {
  249. controller.set('content.installedHosts', {
  250. 'host1': {
  251. hostComponents: [
  252. {
  253. HostRoles: {
  254. component_name: 'C1'
  255. }
  256. }
  257. ]
  258. }
  259. });
  260. controller.setInstalledComponents(hostsObj);
  261. expect(hostsObj[0].checkboxes[0].isInstalled).to.be.true;
  262. expect(hostsObj[0].checkboxes[1].isInstalled).to.be.false;
  263. });
  264. });
  265. describe("#restoreComponentsSelection()", function() {
  266. var getHostsObj = function() {
  267. return [{
  268. hostName: 'host1',
  269. checkboxes: [
  270. {
  271. component: 'C1',
  272. title: 'c1',
  273. isInstalled: false,
  274. checked: false
  275. },
  276. {
  277. component: 'C2',
  278. title: 'c1',
  279. isInstalled: true,
  280. checked: false
  281. },
  282. {
  283. component: 'C3',
  284. title: 'c3',
  285. isInstalled: false,
  286. checked: false
  287. }
  288. ]
  289. }];
  290. };
  291. var slaveComponents = [
  292. {
  293. componentName: 'C1',
  294. hosts: [{hostName: 'host1', isInstalled: true}]
  295. }
  296. ];
  297. beforeEach(function() {
  298. controller.set('headers', [
  299. Em.Object.create({
  300. name: 'C1',
  301. label: 'c1'
  302. }),
  303. Em.Object.create({
  304. name: 'C2',
  305. label: 'c2'
  306. }),
  307. Em.Object.create({
  308. name: 'C3',
  309. label: 'c3'
  310. })
  311. ]);
  312. });
  313. it("C1 components should be checked and installed", function() {
  314. var hostsObj = getHostsObj();
  315. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  316. expect(hostsObj[0].checkboxes[0].isInstalled).to.be.true;
  317. expect(hostsObj[0].checkboxes[0].checked).to.be.true;
  318. });
  319. it("C2 components should not be checked and should be installed", function() {
  320. var hostsObj = getHostsObj();
  321. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  322. expect(hostsObj[0].checkboxes[1].isInstalled).to.be.true;
  323. expect(hostsObj[0].checkboxes[1].checked).to.be.false;
  324. });
  325. it("C3 components should not be checked and should not be installed", function() {
  326. var hostsObj = getHostsObj();
  327. controller.restoreComponentsSelection(hostsObj, slaveComponents);
  328. expect(hostsObj[0].checkboxes[2].isInstalled).to.be.false;
  329. expect(hostsObj[0].checkboxes[2].checked).to.be.false;
  330. });
  331. });
  332. describe("#selectRecommendedComponents()", function() {
  333. var hostsObj = [{
  334. hostName: 'host1',
  335. checkboxes: [
  336. {
  337. component: 'C1',
  338. checked: false
  339. },
  340. {
  341. component: 'C2',
  342. checked: false
  343. },
  344. {
  345. component: 'CLIENT',
  346. checked: false
  347. }
  348. ]
  349. }];
  350. var recommendations = {
  351. blueprint: {
  352. host_groups: [
  353. {
  354. name: 'g1',
  355. components: [
  356. {name: 'C1'},
  357. {name: 'C_CLIENT'}
  358. ]
  359. }
  360. ]
  361. },
  362. blueprint_cluster_binding: {
  363. host_groups: [
  364. {
  365. name: 'g1',
  366. hosts: [{fqdn: 'host1'}]
  367. }
  368. ]
  369. }
  370. };
  371. beforeEach(function() {
  372. sinon.stub(App, 'get').returns(['C_CLIENT']);
  373. });
  374. afterEach(function() {
  375. App.get.restore();
  376. });
  377. it("C1 should be checked", function() {
  378. controller.set('content.recommendations', recommendations);
  379. controller.selectRecommendedComponents(hostsObj);
  380. expect(hostsObj[0].checkboxes[0].checked).to.be.true;
  381. });
  382. it("C2 should not be checked", function() {
  383. controller.set('content.recommendations', recommendations);
  384. controller.selectRecommendedComponents(hostsObj);
  385. expect(hostsObj[0].checkboxes[1].checked).to.be.false;
  386. });
  387. it("CLIENT should be checked", function() {
  388. controller.set('content.recommendations', recommendations);
  389. controller.selectRecommendedComponents(hostsObj);
  390. expect(hostsObj[0].checkboxes[2].checked).to.be.true;
  391. });
  392. });
  393. App.TestAliases.testAsComputedOr(getController(), 'anyGeneralErrors', ['errorMessage', 'generalErrorMessages.length']);
  394. describe('#render', function () {
  395. it('true if loaded', function () {
  396. var hosts = {
  397. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  398. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  399. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  400. };
  401. var headers = Em.A([
  402. Em.Object.create({name: "c1", label: 'l1', isDisabled: true}),
  403. Em.Object.create({name: "c2", label: 'l2', isDisabled: false})
  404. ]);
  405. var masterComponentHosts = Em.A([
  406. {hostName: 'h1', component: 'c1'}
  407. ]);
  408. var recommendations = {
  409. blueprint: {
  410. host_groups: [
  411. {
  412. components: [
  413. {
  414. name: 'c6'
  415. }
  416. ],
  417. name: 'host-group-1'
  418. },
  419. {
  420. components: [
  421. {
  422. name: 'c8'
  423. }
  424. ],
  425. name: 'host-group-2'
  426. }
  427. ]
  428. },
  429. blueprint_cluster_binding: {
  430. host_groups: [
  431. {
  432. hosts: [
  433. {
  434. fqdn: 'h0'
  435. }
  436. ],
  437. name: 'host-group-1'
  438. },
  439. {
  440. hosts: [
  441. {
  442. fqdn: 'h1'
  443. }
  444. ],
  445. name: 'host-group-2'
  446. }]
  447. }
  448. };
  449. controller.set('content.hosts', hosts);
  450. controller.set('content.masterComponentHosts', masterComponentHosts);
  451. controller.set('content.recommendations', recommendations);
  452. controller.set('headers', headers);
  453. controller.render();
  454. expect(controller.get('isLoaded')).to.equal(true);
  455. });
  456. });
  457. describe('#anyGeneralWarnings', function () {
  458. it('true if generalWarningMessages is non empty array and warningMessage is undefined', function () {
  459. controller.set('generalWarningMessages', ["warning1", "warning2"]);
  460. expect(controller.get('anyGeneralWarnings')).to.equal(true);
  461. });
  462. it('false if generalWarningMessages is empty array', function () {
  463. controller.set('generalWarningMessages', []);
  464. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  465. });
  466. it('undefined if generalWarningMessages is undefined', function () {
  467. controller.set('generalWarningMessages', false);
  468. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  469. });
  470. });
  471. App.TestAliases.testAsComputedOr(getController(), 'anyGeneralIssues', ['anyGeneralErrors', 'anyGeneralWarnings']);
  472. App.TestAliases.testAsComputedOr(getController(), 'anyErrors', ['anyGeneralErrors', 'anyHostErrors']);
  473. App.TestAliases.testAsComputedOr(getController(), 'anyWarnings', ['anyGeneralWarnings', 'anyHostWarnings']);
  474. describe('#anyWarnings', function () {
  475. it('true if generalWarningMessages is non empty', function () {
  476. controller.set('generalWarningMessages', ["error 404", "error"]);
  477. expect(controller.get('anyWarnings')).to.equal(true);
  478. });
  479. it('false if generalWarningMessages is empty', function () {
  480. controller.set('generalWarningMessages', []);
  481. expect(controller.get('anyWarnings')).to.equal(false);
  482. });
  483. });
  484. App.TestAliases.testAsComputedEqual(getController(), 'isInstallerWizard', 'content.controllerName', 'installerController');
  485. App.TestAliases.testAsComputedEqual(getController(), 'isAddServiceWizard', 'content.controllerName', 'addServiceController');
  486. describe('#selectClientHost', function () {
  487. it('true if isClientsSet false', function () {
  488. var hostsObj = Em.A([Em.Object.create({
  489. hasMaster: false,
  490. checkboxes: Em.A([
  491. Em.Object.create({
  492. component: 'c1',
  493. isInstalled: false,
  494. checked: true
  495. })
  496. ])
  497. })]);
  498. controller.set('isClientsSet', false);
  499. controller.selectClientHost(hostsObj);
  500. expect(controller.get('isClientsSet')).to.equal(true);
  501. });
  502. });
  503. describe('#updateValidationsSuccessCallback', function () {
  504. var hosts = Em.A([Em.Object.create({
  505. warnMessages: "warn",
  506. errorMessages: "error",
  507. anyMessage: true,
  508. checkboxes: Em.A([Em.Object.create({
  509. hasWarnMessage: true,
  510. hasErrorMessage: true
  511. })])
  512. })]);
  513. var validationData = Em.Object.create({
  514. resources: Em.A([
  515. Em.Object.create({
  516. items: Em.A([
  517. Em.Object.create({
  518. "component-name": 'HDFS_CLIENT',
  519. host: "1",
  520. isMaster: true
  521. })
  522. ])
  523. })
  524. ])
  525. });
  526. beforeEach(function () {
  527. sinon.stub(validationUtils, 'filterNotInstalledComponents', function () {
  528. return Em.A([Em.Object.create({
  529. componentName: 'c0',
  530. isSlave: true,
  531. type: 'host-component',
  532. level: 'ERROR'
  533. }),
  534. Em.Object.create({
  535. componentName: 'c1',
  536. isSlave: true,
  537. type: 'host-component',
  538. level: 'WARN',
  539. isShownOnInstallerSlaveClientPage: true
  540. })]);
  541. });
  542. sinon.stub(App.StackServiceComponent, 'find', function () {
  543. return [
  544. Em.Object.create({
  545. componentName: 'c0',
  546. isSlave: true
  547. }),
  548. Em.Object.create({
  549. componentName: 'c1',
  550. isSlave: true,
  551. isShownOnInstallerSlaveClientPage: true
  552. }),
  553. Em.Object.create({
  554. componentName: 'c2',
  555. isSlave: true,
  556. isShownOnInstallerSlaveClientPage: false
  557. }),
  558. Em.Object.create({
  559. componentName: 'c3',
  560. isClient: true
  561. }),
  562. Em.Object.create({
  563. componentName: 'c4',
  564. isClient: true,
  565. isRequiredOnAllHosts: false
  566. }),
  567. Em.Object.create({
  568. componentName: 'c5',
  569. isClient: true,
  570. isRequiredOnAllHosts: true
  571. }),
  572. Em.Object.create({
  573. componentName: 'c6',
  574. isMaster: true,
  575. isShownOnInstallerAssignMasterPage: true
  576. }),
  577. Em.Object.create({
  578. componentName: 'c7',
  579. isMaster: true,
  580. isShownOnInstallerAssignMasterPage: false
  581. }),
  582. Em.Object.create({
  583. componentName: 'HDFS_CLIENT',
  584. isMaster: true,
  585. isShownOnAddServiceAssignMasterPage: true
  586. }),
  587. Em.Object.create({
  588. componentName: 'c9',
  589. isMaster: true,
  590. isShownOnAddServiceAssignMasterPage: false
  591. })
  592. ];
  593. });
  594. controller.set('hosts', hosts);
  595. controller.updateValidationsSuccessCallback(validationData);
  596. });
  597. afterEach(function () {
  598. App.StackServiceComponent.find.restore();
  599. validationUtils.filterNotInstalledComponents.restore();
  600. });
  601. it('no generalErrorMessages', function () {
  602. expect(controller.get('generalErrorMessages').length).to.equal(0);
  603. });
  604. it('no generalWarningMessages', function () {
  605. expect(controller.get('generalWarningMessages').length).to.equal(0);
  606. });
  607. it('hosts info is valid', function () {
  608. var cHosts = JSON.parse(JSON.stringify(controller.get('hosts')));
  609. var expected = [{
  610. warnMessages: [null],
  611. errorMessages: [null],
  612. anyMessage: true,
  613. checkboxes: [{
  614. hasWarnMessage: true,
  615. hasErrorMessage: true
  616. }]
  617. }];
  618. expect(cHosts).to.eql(expected);
  619. });
  620. });
  621. describe('#clearError', function () {
  622. var headers = Em.A([
  623. Em.Object.create({name: "c1", label: 't1'}),
  624. Em.Object.create({name: "c2", label: 't2'})]);
  625. beforeEach(function () {
  626. controller.set('errorMessage', 'error');
  627. controller.set('headers', headers);
  628. });
  629. it('both checkboxes are checked', function () {
  630. var hosts = Em.A([
  631. Em.Object.create({
  632. checkboxes: Em.A([
  633. Em.Object.create({
  634. component: 'c1',
  635. isInstalled: false,
  636. checked: true
  637. }),
  638. Em.Object.create({
  639. component: 'c2',
  640. isInstalled: false,
  641. checked: true
  642. })])
  643. })
  644. ]);
  645. controller.set('hosts', hosts);
  646. controller.clearError();
  647. expect(controller.get('errorMessage')).to.equal('');
  648. });
  649. it('true if is one of checkboxes checked false', function () {
  650. var hosts = Em.A([
  651. Em.Object.create({
  652. checkboxes: Em.A([
  653. Em.Object.create({
  654. title: "t1",
  655. component: 'c1',
  656. isInstalled: false,
  657. checked: false
  658. }),
  659. Em.Object.create({
  660. title: "t2",
  661. component: 'c2',
  662. isInstalled: false,
  663. checked: true
  664. })])
  665. })
  666. ]);
  667. controller.set('hosts', hosts);
  668. controller.set('isAddHostWizard', true);
  669. controller.clearError();
  670. expect(controller.get('errorMessage')).to.equal('error');
  671. });
  672. });
  673. describe('#clearStep', function () {
  674. beforeEach(function () {
  675. sinon.stub(controller, 'clearError', Em.K);
  676. });
  677. afterEach(function () {
  678. controller.clearError.restore();
  679. });
  680. it('should call clearError', function () {
  681. controller.clearStep();
  682. expect(controller.clearError.calledOnce).to.equal(true);
  683. });
  684. it('should clear hosts', function () {
  685. controller.set('hosts', [
  686. {},
  687. {}
  688. ]);
  689. controller.clearStep();
  690. expect(controller.get('hosts')).to.eql([]);
  691. });
  692. it('should clear headers', function () {
  693. controller.set('headers', [
  694. {},
  695. {}
  696. ]);
  697. controller.clearStep();
  698. expect(controller.get('headers')).to.eql([]);
  699. });
  700. it('should set isLoaded to false', function () {
  701. controller.set('isLoaded', true);
  702. controller.clearStep();
  703. expect(controller.get('isLoaded')).to.equal(false);
  704. });
  705. });
  706. describe('#checkCallback', function () {
  707. beforeEach(function () {
  708. sinon.stub(controller, 'clearError', Em.K);
  709. });
  710. afterEach(function () {
  711. controller.clearError.restore();
  712. });
  713. it('should call clearError', function () {
  714. controller.checkCallback('');
  715. expect(controller.clearError.calledOnce).to.equal(true);
  716. });
  717. Em.A([
  718. {
  719. m: 'all checked, isInstalled false',
  720. headers: Em.A([
  721. Em.Object.create({name: 'c1'})
  722. ]),
  723. hosts: Em.A([
  724. Em.Object.create({
  725. checkboxes: Em.A([
  726. Em.Object.create({
  727. component: 'c1',
  728. isInstalled: false,
  729. checked: true
  730. })
  731. ])
  732. })
  733. ]),
  734. component: 'c1',
  735. e: {
  736. allChecked: true,
  737. noChecked: false
  738. }
  739. },
  740. {
  741. m: 'all checked, isInstalled true',
  742. headers: Em.A([
  743. Em.Object.create({name: 'c1'})
  744. ]),
  745. hosts: Em.A([
  746. Em.Object.create({
  747. checkboxes: Em.A([
  748. Em.Object.create({
  749. component: 'c1',
  750. isInstalled: true,
  751. checked: true
  752. })
  753. ])
  754. })
  755. ]),
  756. component: 'c1',
  757. e: {
  758. allChecked: true,
  759. noChecked: true
  760. }
  761. },
  762. {
  763. m: 'no one checked',
  764. headers: Em.A([
  765. Em.Object.create({name: 'c1'})
  766. ]),
  767. hosts: Em.A([
  768. Em.Object.create({
  769. checkboxes: Em.A([
  770. Em.Object.create({
  771. component: 'c1',
  772. isInstalled: false,
  773. checked: false
  774. })
  775. ])
  776. })
  777. ]),
  778. component: 'c1',
  779. e: {
  780. allChecked: false,
  781. noChecked: true
  782. }
  783. },
  784. {
  785. m: 'some checked',
  786. headers: Em.A([
  787. Em.Object.create({name: 'c1'})
  788. ]),
  789. hosts: Em.A([
  790. Em.Object.create({
  791. checkboxes: Em.A([
  792. Em.Object.create({
  793. component: 'c1',
  794. isInstalled: false,
  795. checked: true
  796. }),
  797. Em.Object.create({
  798. component: 'c1',
  799. isInstalled: false,
  800. checked: false
  801. })
  802. ])
  803. })
  804. ]),
  805. component: 'c1',
  806. e: {
  807. allChecked: false,
  808. noChecked: false
  809. }
  810. },
  811. {
  812. m: 'some checked, some isInstalled true',
  813. headers: Em.A([
  814. Em.Object.create({name: 'c1'})
  815. ]),
  816. hosts: Em.A([
  817. Em.Object.create({
  818. checkboxes: Em.A([
  819. Em.Object.create({
  820. component: 'c1',
  821. isInstalled: true,
  822. checked: true
  823. }),
  824. Em.Object.create({
  825. component: 'c1',
  826. isInstalled: true,
  827. checked: true
  828. })
  829. ])
  830. })
  831. ]),
  832. component: 'c1',
  833. e: {
  834. allChecked: true,
  835. noChecked: true
  836. }
  837. },
  838. {
  839. m: 'some checked, some isInstalled true (2)',
  840. headers: Em.A([
  841. Em.Object.create({name: 'c1'})
  842. ]),
  843. hosts: Em.A([
  844. Em.Object.create({
  845. checkboxes: Em.A([
  846. Em.Object.create({
  847. component: 'c1',
  848. isInstalled: false,
  849. checked: false
  850. }),
  851. Em.Object.create({
  852. component: 'c1',
  853. isInstalled: true,
  854. checked: true
  855. })
  856. ])
  857. })
  858. ]),
  859. component: 'c1',
  860. e: {
  861. allChecked: false,
  862. noChecked: true
  863. }
  864. }
  865. ]).forEach(function (test) {
  866. describe(test.m, function () {
  867. beforeEach(function () {
  868. controller.clearStep();
  869. controller.set('headers', test.headers);
  870. controller.set('hosts', test.hosts);
  871. controller.checkCallback(test.component);
  872. this.header = controller.get('headers').findProperty('name', test.component);
  873. });
  874. it('allChecked is ' + test.e.allChecked, function () {
  875. expect(this.header.get('allChecked')).to.equal(test.e.allChecked);
  876. });
  877. it('noChecked is ' + test.e.noChecked, function () {
  878. expect(this.header.get('noChecked')).to.equal(test.e.noChecked);
  879. });
  880. });
  881. });
  882. });
  883. describe('#getHostNames', function () {
  884. var tests = Em.A([
  885. {
  886. hosts: {
  887. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  888. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  889. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  890. },
  891. m: 'All REGISTERED',
  892. e: ['h1', 'h2', 'h3']
  893. },
  894. {
  895. hosts: {
  896. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  897. h2: {bootStatus: 'FAILED', name: 'h2'},
  898. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  899. },
  900. m: 'Some REGISTERED',
  901. e: ['h1', 'h3']
  902. },
  903. {
  904. hosts: {
  905. h1: {bootStatus: 'FAILED', name: 'h1'},
  906. h2: {bootStatus: 'FAILED', name: 'h2'},
  907. h3: {bootStatus: 'FAILED', name: 'h3'}
  908. },
  909. m: 'No one REGISTERED',
  910. e: []
  911. },
  912. {
  913. hosts: {},
  914. m: 'Empty hosts',
  915. e: []
  916. }
  917. ]);
  918. tests.forEach(function (test) {
  919. it(test.m, function () {
  920. controller.set('content.hosts', test.hosts);
  921. var r = controller.getHostNames();
  922. expect(r).to.eql(test.e);
  923. });
  924. });
  925. });
  926. describe('#getMasterComponentsForHost', function () {
  927. var tests = Em.A([
  928. {
  929. masterComponentHosts: Em.A([
  930. {hostName: 'h1', component: 'c1'}
  931. ]),
  932. hostName: 'h1',
  933. m: 'host exists',
  934. e: ['c1']
  935. },
  936. {
  937. masterComponentHosts: Em.A([
  938. {hostName: 'h1', component: 'c1'}
  939. ]),
  940. hostName: 'h2',
  941. m: 'host donesn\'t exists',
  942. e: []
  943. }
  944. ]);
  945. tests.forEach(function (test) {
  946. it(test.m, function () {
  947. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  948. var r = controller.getMasterComponentsForHost(test.hostName);
  949. expect(r).to.eql(test.e);
  950. });
  951. });
  952. });
  953. describe('#selectMasterComponents', function () {
  954. var tests = Em.A([
  955. {
  956. masterComponentHosts: Em.A([
  957. {
  958. hostName: 'h1',
  959. component: 'c1'
  960. }
  961. ]),
  962. hostsObj: [
  963. Em.Object.create({
  964. hostName: 'h1',
  965. checkboxes: [
  966. Em.Object.create({
  967. component: 'c1',
  968. checked: false
  969. })
  970. ]
  971. })
  972. ],
  973. e: true,
  974. m: 'host and component exist'
  975. },
  976. {
  977. masterComponentHosts: Em.A([
  978. {
  979. hostName: 'h1',
  980. component: 'c2'
  981. }
  982. ]),
  983. hostsObj: [
  984. Em.Object.create({
  985. hostName: 'h1',
  986. checkboxes: [
  987. Em.Object.create({
  988. component: 'c1',
  989. checked: false
  990. })
  991. ]
  992. })
  993. ],
  994. e: false,
  995. m: 'host exists'
  996. },
  997. {
  998. masterComponentHosts: Em.A([
  999. {
  1000. hostName: 'h2',
  1001. component: 'c2'
  1002. }
  1003. ]),
  1004. hostsObj: [
  1005. Em.Object.create({
  1006. hostName: 'h1',
  1007. checkboxes: [
  1008. Em.Object.create({
  1009. component: 'c1',
  1010. checked: false
  1011. })
  1012. ]
  1013. })
  1014. ],
  1015. e: false,
  1016. m: 'host and component don\'t exist'
  1017. }
  1018. ]);
  1019. tests.forEach(function (test) {
  1020. it(test.m, function () {
  1021. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  1022. var r = controller.selectMasterComponents(test.hostsObj);
  1023. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  1024. });
  1025. });
  1026. });
  1027. describe('#getCurrentMastersBlueprint', function () {
  1028. var tests = Em.A([
  1029. {
  1030. masterComponentHosts: Em.A([
  1031. {hostName: 'h1', component: 'c1'}
  1032. ]),
  1033. hosts: {'h1': {}},
  1034. m: 'one host and one component',
  1035. e:{
  1036. blueprint: {
  1037. host_groups: [
  1038. {
  1039. name: 'host-group-1',
  1040. components: [
  1041. { name: 'c1' }
  1042. ]
  1043. }
  1044. ]
  1045. },
  1046. blueprint_cluster_binding: {
  1047. host_groups: [
  1048. {
  1049. name: 'host-group-1',
  1050. hosts: [
  1051. { fqdn: 'h1' }
  1052. ]
  1053. }
  1054. ]
  1055. }
  1056. }
  1057. },
  1058. {
  1059. masterComponentHosts: Em.A([
  1060. {hostName: 'h1', component: 'c1'},
  1061. {hostName: 'h2', component: 'c2'},
  1062. {hostName: 'h2', component: 'c3'}
  1063. ]),
  1064. hosts: {'h1': {}, 'h2': {}, 'h3': {}},
  1065. m: 'multiple hosts and multiple components',
  1066. e: {
  1067. blueprint: {
  1068. host_groups: [
  1069. {
  1070. name: 'host-group-1',
  1071. components: [
  1072. { name: 'c1' }
  1073. ]
  1074. },
  1075. {
  1076. name: 'host-group-2',
  1077. components: [
  1078. { name: 'c2' },
  1079. { name: 'c3' }
  1080. ]
  1081. },
  1082. {
  1083. name: 'host-group-3',
  1084. components: []
  1085. }
  1086. ]
  1087. },
  1088. blueprint_cluster_binding: {
  1089. host_groups: [
  1090. {
  1091. name: 'host-group-1',
  1092. hosts: [
  1093. { fqdn: 'h1' }
  1094. ]
  1095. },
  1096. {
  1097. name: 'host-group-2',
  1098. hosts: [
  1099. { fqdn: 'h2' }
  1100. ]
  1101. },
  1102. {
  1103. name: 'host-group-3',
  1104. hosts: [
  1105. { fqdn: 'h3' }
  1106. ]
  1107. }
  1108. ]
  1109. }
  1110. }
  1111. }
  1112. ]);
  1113. tests.forEach(function (test) {
  1114. it(test.m, function () {
  1115. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  1116. controller.set('content.hosts', test.hosts);
  1117. var r = controller.getCurrentMastersBlueprint();
  1118. expect(r).to.eql(test.e);
  1119. });
  1120. });
  1121. });
  1122. describe('#getCurrentBlueprint', function () {
  1123. var tests = Em.A([
  1124. {
  1125. clientComponents: Em.A([{component_name: "name1"}]),
  1126. hosts: Em.A([
  1127. Em.Object.create({
  1128. checkboxes: Em.A([
  1129. Em.Object.create({
  1130. component: 'c1',
  1131. checked: true
  1132. }),
  1133. Em.Object.create({
  1134. component: 'CLIENT',
  1135. checked: true
  1136. })
  1137. ])
  1138. })
  1139. ]),
  1140. m: 'one host and one component',
  1141. e:{
  1142. blueprint: {
  1143. host_groups: [
  1144. {
  1145. name: 'host-group-1',
  1146. components: [
  1147. { name: 'c1' },
  1148. { name: 'name1' }
  1149. ]
  1150. }
  1151. ]
  1152. },
  1153. blueprint_cluster_binding: {
  1154. host_groups: [
  1155. {
  1156. name: 'host-group-1',
  1157. hosts: [
  1158. {}
  1159. ]
  1160. }
  1161. ]
  1162. }
  1163. }
  1164. }
  1165. ]);
  1166. tests.forEach(function (test) {
  1167. it(test.m, function () {
  1168. controller.set('content.clients', test.clientComponents);
  1169. controller.set('hosts', test.hosts);
  1170. var r = controller.getCurrentBlueprint();
  1171. expect(JSON.parse(JSON.stringify(r))).to.eql(JSON.parse(JSON.stringify(test.e)));
  1172. });
  1173. });
  1174. });
  1175. describe('#callServerSideValidation', function () {
  1176. var cases = [
  1177. {
  1178. controllerName: 'installerController',
  1179. hosts: [
  1180. {
  1181. hostName: 'h0'
  1182. },
  1183. {
  1184. hostName: 'h1'
  1185. }
  1186. ],
  1187. expected: [
  1188. ['c0', 'c6'],
  1189. ['c1', 'c3', 'c8']
  1190. ]
  1191. },
  1192. {
  1193. controllerName: 'addServiceController',
  1194. hosts: [
  1195. {
  1196. hostName: 'h0'
  1197. },
  1198. {
  1199. hostName: 'h1'
  1200. }
  1201. ],
  1202. expected: [
  1203. ['c0', 'c6'],
  1204. ['c1', 'c3', 'c8']
  1205. ]
  1206. },
  1207. {
  1208. controllerName: 'addHostController',
  1209. hosts: [
  1210. {
  1211. hostName: 'h0'
  1212. }
  1213. ],
  1214. expected: [
  1215. ['c0', 'c2', 'c5', 'c6'],
  1216. ['c1', 'c2', 'c3', 'c5', 'c8']
  1217. ]
  1218. }
  1219. ],
  1220. expectedHostGroups = [
  1221. {
  1222. name: 'host-group-1',
  1223. fqdn: 'h0'
  1224. },
  1225. {
  1226. name: 'host-group-2',
  1227. fqdn: 'h1'
  1228. }
  1229. ];
  1230. beforeEach(function () {
  1231. controller.get('content').setProperties({
  1232. recommendations: {
  1233. blueprint: {
  1234. host_groups: [
  1235. {
  1236. components: [
  1237. {
  1238. name: 'c6'
  1239. }
  1240. ],
  1241. name: 'host-group-1'
  1242. },
  1243. {
  1244. components: [
  1245. {
  1246. name: 'c8'
  1247. }
  1248. ],
  1249. name: 'host-group-2'
  1250. }
  1251. ]
  1252. },
  1253. blueprint_cluster_binding: {
  1254. host_groups: [
  1255. {
  1256. hosts: [
  1257. {
  1258. fqdn: 'h0'
  1259. }
  1260. ],
  1261. name: 'host-group-1'
  1262. },
  1263. {
  1264. hosts: [
  1265. {
  1266. fqdn: 'h1'
  1267. }
  1268. ],
  1269. name: 'host-group-2'
  1270. }]
  1271. }
  1272. },
  1273. clients: [
  1274. {
  1275. component_name: 'c3'
  1276. }
  1277. ]
  1278. });
  1279. sinon.stub(App.StackService, 'find', function () {
  1280. return [
  1281. Em.Object.create({
  1282. serviceName: 's0',
  1283. isSelected: true
  1284. }),
  1285. Em.Object.create({
  1286. serviceName: 's1',
  1287. isInstalled: true,
  1288. isSelected: true
  1289. })
  1290. ];
  1291. });
  1292. sinon.stub(App.StackServiceComponent, 'find', function () {
  1293. return [
  1294. Em.Object.create({
  1295. componentName: 'c0',
  1296. isSlave: true
  1297. }),
  1298. Em.Object.create({
  1299. componentName: 'c1',
  1300. isSlave: true,
  1301. isShownOnInstallerSlaveClientPage: true
  1302. }),
  1303. Em.Object.create({
  1304. componentName: 'c2',
  1305. isSlave: true,
  1306. isShownOnInstallerSlaveClientPage: false
  1307. }),
  1308. Em.Object.create({
  1309. componentName: 'c3',
  1310. isClient: true
  1311. }),
  1312. Em.Object.create({
  1313. componentName: 'c4',
  1314. isClient: true,
  1315. isRequiredOnAllHosts: false
  1316. }),
  1317. Em.Object.create({
  1318. componentName: 'c5',
  1319. isClient: true,
  1320. isRequiredOnAllHosts: true
  1321. }),
  1322. Em.Object.create({
  1323. componentName: 'c6',
  1324. isMaster: true,
  1325. isShownOnInstallerAssignMasterPage: true
  1326. }),
  1327. Em.Object.create({
  1328. componentName: 'c7',
  1329. isMaster: true,
  1330. isShownOnInstallerAssignMasterPage: false
  1331. }),
  1332. Em.Object.create({
  1333. componentName: 'c8',
  1334. isMaster: true,
  1335. isShownOnAddServiceAssignMasterPage: true
  1336. }),
  1337. Em.Object.create({
  1338. componentName: 'c9',
  1339. isMaster: true,
  1340. isShownOnAddServiceAssignMasterPage: false
  1341. })
  1342. ];
  1343. });
  1344. sinon.stub(controller, 'getCurrentBlueprint', function () {
  1345. return {
  1346. blueprint: {
  1347. host_groups: [
  1348. {
  1349. components: [
  1350. {
  1351. name: 'c0'
  1352. }
  1353. ],
  1354. name: 'host-group-1'
  1355. },
  1356. {
  1357. components: [
  1358. {
  1359. name: 'c1'
  1360. },
  1361. {
  1362. name: 'c3'
  1363. }
  1364. ],
  1365. name: 'host-group-2'
  1366. }
  1367. ]
  1368. },
  1369. blueprint_cluster_binding: {
  1370. host_groups: [
  1371. {
  1372. hosts: [
  1373. {
  1374. fqdn: 'h0'
  1375. }
  1376. ],
  1377. name: 'host-group-1'
  1378. },
  1379. {
  1380. hosts: [
  1381. {
  1382. fqdn: 'h1'
  1383. }
  1384. ],
  1385. name: 'host-group-2'
  1386. }]
  1387. }
  1388. };
  1389. });
  1390. sinon.stub(controller, 'getCurrentMastersBlueprint', function () {
  1391. return {
  1392. blueprint: {
  1393. host_groups: [
  1394. {
  1395. components: [
  1396. {
  1397. name: 'c6'
  1398. }
  1399. ],
  1400. name: 'host-group-1'
  1401. },
  1402. {
  1403. components: [
  1404. {
  1405. name: 'c8'
  1406. }
  1407. ],
  1408. name: 'host-group-2'
  1409. }
  1410. ]
  1411. },
  1412. blueprint_cluster_binding: {
  1413. host_groups: [
  1414. {
  1415. hosts: [
  1416. {
  1417. fqdn: 'h0'
  1418. }
  1419. ],
  1420. name: 'host-group-1'
  1421. },
  1422. {
  1423. hosts: [
  1424. {
  1425. fqdn: 'h1'
  1426. }
  1427. ],
  1428. name: 'host-group-2'
  1429. }]
  1430. }
  1431. };
  1432. });
  1433. sinon.stub(App, 'get').withArgs('components.clients').returns(['c3', 'c4']);
  1434. sinon.stub(controller, 'getCurrentMasterSlaveBlueprint', function () {
  1435. return {
  1436. blueprint: {
  1437. host_groups: [
  1438. {
  1439. components: [
  1440. {
  1441. name: 'c6'
  1442. }
  1443. ],
  1444. name: 'host-group-1'
  1445. },
  1446. {
  1447. components: [
  1448. {
  1449. name: 'c8'
  1450. }
  1451. ],
  1452. name: 'host-group-2'
  1453. }
  1454. ]
  1455. },
  1456. blueprint_cluster_binding: {
  1457. host_groups: [
  1458. {
  1459. hosts: [
  1460. {
  1461. fqdn: 'h0'
  1462. }
  1463. ],
  1464. name: 'host-group-1'
  1465. },
  1466. {
  1467. hosts: [
  1468. {
  1469. fqdn: 'h1'
  1470. }
  1471. ],
  1472. name: 'host-group-2'
  1473. }]
  1474. }
  1475. };
  1476. });
  1477. sinon.stub(App.Host, 'find', function () {
  1478. return [
  1479. {
  1480. hostName: 'h1'
  1481. }
  1482. ];
  1483. });
  1484. });
  1485. afterEach(function () {
  1486. App.StackService.find.restore();
  1487. App.StackServiceComponent.find.restore();
  1488. controller.getCurrentBlueprint.restore();
  1489. controller.getCurrentMastersBlueprint.restore();
  1490. App.get.restore();
  1491. controller.getCurrentMasterSlaveBlueprint.restore();
  1492. App.Host.find.restore();
  1493. });
  1494. cases.forEach(function (item) {
  1495. describe(item.controllerName, function () {
  1496. beforeEach(function () {
  1497. controller.set('hosts', item.hosts);
  1498. controller.set('content.controllerName', item.controllerName);
  1499. controller.callServerSideValidation();
  1500. });
  1501. it('blueprint.host_groups count is correct', function () {
  1502. expect(controller.get('content.recommendationsHostGroups.blueprint.host_groups.length')).to.equal(expectedHostGroups.length);
  1503. });
  1504. it('blueprint_cluster_binding.host_groups count is correct', function () {
  1505. expect(controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups.length')).to.equal(expectedHostGroups.length);
  1506. });
  1507. item.expected.forEach(function (e, index) {
  1508. it('components are valid for group# ' + (index + 1), function () {
  1509. expect(controller.get('content.recommendationsHostGroups.blueprint.host_groups')[index].components.mapProperty('name').sort()).to.be.eql(e);
  1510. });
  1511. });
  1512. expectedHostGroups.forEach(function (group) {
  1513. it(group.name, function () {
  1514. var bpGroup = controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups').findProperty('name', group.name);
  1515. expect(bpGroup.hosts).to.have.length(1);
  1516. expect(bpGroup.hosts[0].fqdn).to.equal(group.fqdn);
  1517. });
  1518. });
  1519. });
  1520. });
  1521. });
  1522. describe('#isAllCheckboxesEmpty', function () {
  1523. Em.A([
  1524. {
  1525. m: 'all checkboxes are not empty',
  1526. hosts: [
  1527. {checkboxes: [{checked: true}, {checked: true}]},
  1528. {checkboxes: [{checked: true}, {checked: true}]}
  1529. ],
  1530. e: false
  1531. },
  1532. {
  1533. m: 'some checkboxes are empty',
  1534. hosts: [
  1535. {checkboxes: [{checked: true}, {checked: false}]},
  1536. {checkboxes: [{checked: true}, {checked: false}]}
  1537. ],
  1538. e: false
  1539. },
  1540. {
  1541. m: 'all checkboxes are empty',
  1542. hosts: [
  1543. {checkboxes: [{checked: false}, {checked: false}]},
  1544. {checkboxes: [{checked: false}, {checked: false}]}
  1545. ],
  1546. e: true
  1547. }
  1548. ]).forEach(function (test) {
  1549. it(test.m, function () {
  1550. controller.set('hosts', test.hosts);
  1551. expect(controller.isAllCheckboxesEmpty()).to.be.equal(test.e);
  1552. });
  1553. });
  1554. });
  1555. describe('#loadStep', function () {
  1556. beforeEach(function () {
  1557. sinon.stub(controller, 'render', Em.K);
  1558. sinon.stub(controller, 'callValidation', Em.K);
  1559. sinon.stub(App.StackService, 'find').returns([
  1560. Em.Object.create({
  1561. isSelected: true,
  1562. serviceName: 's1',
  1563. serviceComponents: [
  1564. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's1c1', isRequired: true}),
  1565. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's1c2', isRequired: true})
  1566. ]
  1567. }),
  1568. Em.Object.create({
  1569. isSelected: true,
  1570. serviceName: 's2',
  1571. serviceComponents: [
  1572. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's2c3', isRequired: false}),
  1573. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's2c4', isRequired: false})
  1574. ]
  1575. }),
  1576. Em.Object.create({
  1577. isInstalled: true,
  1578. serviceName: 's3',
  1579. serviceComponents: [
  1580. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's3c1', isRequired: true}),
  1581. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's3c2', isRequired: true})
  1582. ]
  1583. }),
  1584. Em.Object.create({
  1585. isInstalled: true,
  1586. serviceName: 's4',
  1587. serviceComponents: [
  1588. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's4c3', isRequired: false}),
  1589. Em.Object.create({isShownOnInstallerSlaveClientPage: true, componentName: 's4c4', isRequired: false})
  1590. ]
  1591. })
  1592. ]);
  1593. });
  1594. afterEach(function () {
  1595. controller.render.restore();
  1596. controller.callValidation.restore();
  1597. App.StackService.find.restore();
  1598. });
  1599. describe('isInstallerWizard', function () {
  1600. beforeEach(function () {
  1601. controller.set('content', {
  1602. clients: [{}],
  1603. controllerName: 'installerController'
  1604. });
  1605. controller.loadStep();
  1606. });
  1607. it('component names are valid', function () {
  1608. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s1c1', 's1c2', 's2c3', 's2c4', 'CLIENT']);
  1609. });
  1610. it('component labels are valid', function () {
  1611. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S1c1', 'S1c2', 'S2c3', 'S2c4', 'Client']);
  1612. });
  1613. it('everyone allChecked is false', function () {
  1614. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1615. });
  1616. it('component required-flags are valid', function () {
  1617. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, undefined]);
  1618. });
  1619. it('everyone noChecked is false', function () {
  1620. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1621. });
  1622. it('everyone isDisabled is false', function () {
  1623. expect(controller.get('headers').everyProperty('isDisabled', false)).to.be.true;
  1624. });
  1625. it('component allId-fields are valid', function () {
  1626. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s1c1', 'all-s1c2', 'all-s2c3', 'all-s2c4', 'all-CLIENT']);
  1627. });
  1628. it('component noneId-fields are valid', function () {
  1629. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s1c1', 'none-s1c2', 'none-s2c3', 'none-s2c4', 'none-CLIENT']);
  1630. });
  1631. });
  1632. describe('isAddHostWizard', function () {
  1633. beforeEach(function () {
  1634. controller.set('content', {
  1635. clients: [{}],
  1636. controllerName: 'addHostController'
  1637. });
  1638. controller.loadStep();
  1639. });
  1640. it('component names are valid', function () {
  1641. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s3c1', 's3c2', 's4c3', 's4c4', 'CLIENT']);
  1642. });
  1643. it('component labels are valid', function () {
  1644. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S3c1', 'S3c2', 'S4c3', 'S4c4', 'Client']);
  1645. });
  1646. it('everyone allChecked is false', function () {
  1647. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1648. });
  1649. it('component required-flags are valid', function () {
  1650. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, undefined]);
  1651. });
  1652. it('everyone noChecked is false', function () {
  1653. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1654. });
  1655. it('everyone isDisabled is false', function () {
  1656. expect(controller.get('headers').everyProperty('isDisabled', false)).to.be.true;
  1657. });
  1658. it('component allId-fields are valid', function () {
  1659. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s3c1', 'all-s3c2', 'all-s4c3', 'all-s4c4', 'all-CLIENT']);
  1660. });
  1661. it('component noneId-fields are valid', function () {
  1662. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s3c1', 'none-s3c2', 'none-s4c3', 'none-s4c4', 'none-CLIENT']);
  1663. });
  1664. });
  1665. describe('isAddServiceWizard', function () {
  1666. beforeEach(function () {
  1667. controller.set('content', {
  1668. clients: [{}],
  1669. controllerName: 'addServiceController'
  1670. });
  1671. controller.loadStep();
  1672. });
  1673. it('component names are valid', function () {
  1674. expect(controller.get('headers').mapProperty('name')).to.be.eql(['s3c1', 's3c2', 's4c3', 's4c4', 's1c1', 's1c2', 's2c3', 's2c4', 'CLIENT']);
  1675. });
  1676. it('component labels are valid', function () {
  1677. expect(controller.get('headers').mapProperty('label')).to.be.eql(['S3c1', 'S3c2', 'S4c3', 'S4c4', 'S1c1', 'S1c2', 'S2c3', 'S2c4', 'Client']);
  1678. });
  1679. it('everyone allChecked is false', function () {
  1680. expect(controller.get('headers').everyProperty('allChecked', false)).to.be.true;
  1681. });
  1682. it('component required-flags are valid', function () {
  1683. expect(controller.get('headers').mapProperty('isRequired')).to.be.eql([true, true, false, false, true, true, false, false, undefined]);
  1684. });
  1685. it('everyone noChecked is false', function () {
  1686. expect(controller.get('headers').everyProperty('noChecked', true)).to.be.true;
  1687. });
  1688. it('installed services are disabled', function () {
  1689. expect(controller.get('headers').mapProperty('isDisabled', false)).to.be.eql([true, true, true, true, false, false, false, false, false]);
  1690. });
  1691. it('component allId-fields are valid', function () {
  1692. expect(controller.get('headers').mapProperty('allId')).to.be.eql(['all-s3c1', 'all-s3c2', 'all-s4c3', 'all-s4c4', 'all-s1c1', 'all-s1c2', 'all-s2c3', 'all-s2c4', 'all-CLIENT']);
  1693. });
  1694. it('component noneId-fields are valid', function () {
  1695. expect(controller.get('headers').mapProperty('noneId')).to.be.eql(['none-s3c1', 'none-s3c2', 'none-s4c3', 'none-s4c4', 'none-s1c1', 'none-s1c2', 'none-s2c3', 'none-s2c4', 'none-CLIENT']);
  1696. });
  1697. });
  1698. });
  1699. });