installer_test.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. require('models/cluster');
  20. require('controllers/wizard');
  21. require('controllers/installer');
  22. describe('App.InstallerController', function () {
  23. var installerController = App.InstallerController.create();
  24. after(function () {
  25. installerController.destroy();
  26. });
  27. describe('#init', function () {
  28. var c;
  29. beforeEach(function () {
  30. c = App.InstallerController.create({});
  31. });
  32. it('all steps are disabled by default', function () {
  33. expect(c.get('isStepDisabled.length')).to.be.above(0);
  34. expect(c.get('isStepDisabled').everyProperty('value', true)).to.be.ok;
  35. });
  36. });
  37. describe('#getCluster', function() {
  38. it ('Should return merged clusterStatusTemplate', function() {
  39. installerController.set('clusterStatusTemplate', {
  40. name: 'template'
  41. });
  42. expect(installerController.getCluster()).to.eql({
  43. name: 'template'
  44. });
  45. });
  46. });
  47. describe('#getHosts', function() {
  48. it ('Should return empty array', function() {
  49. expect(installerController.getHosts()).to.eql([]);
  50. });
  51. });
  52. describe('#loadServices', function() {
  53. it ('Should resolve nothing', function() {
  54. var res = installerController.loadServices();
  55. res.then(function(data){
  56. expect(data).to.be.undefined;
  57. });
  58. });
  59. });
  60. describe('#checkRepoURL', function() {
  61. var stacks = Em.A([
  62. Em.Object.create({
  63. isSelected: false
  64. }),
  65. Em.Object.create({
  66. isSelected: true,
  67. reload: false,
  68. id: 'nn-cc',
  69. stackNameVersion: 'nn-cc',
  70. repositories: Em.A([
  71. Em.Object.create({
  72. isSelected: true
  73. })
  74. ]),
  75. operatingSystems: Em.A([
  76. Em.Object.create({
  77. isSelected: true,
  78. repositories: Em.A([
  79. Em.Object.create({
  80. errorTitle: '1',
  81. errorContent: '1',
  82. validation: ''
  83. })
  84. ])
  85. })
  86. ])
  87. })
  88. ]);
  89. var wizard = Em.Object.create({
  90. skipValidationChecked: true
  91. });
  92. it ('Should reload installed stacks', function() {
  93. installerController.set('content.stacks', stacks);
  94. installerController.checkRepoURL(wizard);
  95. var expected = [
  96. {
  97. "isSelected": false
  98. },
  99. {
  100. "isSelected": true,
  101. "reload": true,
  102. "id": "nn-cc",
  103. "stackNameVersion": 'nn-cc',
  104. "repositories": [
  105. {
  106. "isSelected": true
  107. }
  108. ],
  109. "operatingSystems": [
  110. {
  111. "isSelected": true,
  112. "repositories": [
  113. {
  114. "errorTitle": "",
  115. "errorContent": "",
  116. "validation": "icon-repeat"
  117. }
  118. ]
  119. }
  120. ]
  121. }
  122. ];
  123. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  124. expect(res).to.be.eql(expected);
  125. });
  126. });
  127. describe('#checkRepoURLSuccessCallback', function() {
  128. var stacks = Em.A([
  129. Em.Object.create({
  130. isSelected: false
  131. }),
  132. Em.Object.create({
  133. isSelected: true,
  134. reload: false,
  135. id: 'nn-cc',
  136. repositories: Em.A([
  137. Em.Object.create({
  138. repoId: 11,
  139. isSelected: true
  140. })
  141. ]),
  142. operatingSystems: Em.A([
  143. Em.Object.create({
  144. isSelected: true,
  145. id: 1,
  146. repositories: Em.A([
  147. Em.Object.create({
  148. repoId: 11,
  149. errorTitle: '1',
  150. errorContent: '1',
  151. validation: ''
  152. })
  153. ])
  154. })
  155. ])
  156. })
  157. ]);
  158. var resolve = false;
  159. var data = {
  160. osId: 1,
  161. repoId: 11,
  162. dfd: {
  163. resolve: function() {
  164. resolve = true;
  165. }
  166. }
  167. };
  168. it ('Should check stacks for sucess', function() {
  169. installerController.set('content.stacks', stacks);
  170. installerController.checkRepoURLSuccessCallback(null,null,data);
  171. var expected = [
  172. {
  173. "isSelected": false
  174. },
  175. {
  176. "isSelected": true,
  177. "reload": false,
  178. "id": "nn-cc",
  179. "repositories": [
  180. {
  181. "repoId": 11,
  182. "isSelected": true
  183. }
  184. ],
  185. "operatingSystems": [
  186. {
  187. "isSelected": true,
  188. "id": 1,
  189. "repositories": [
  190. {
  191. "repoId": 11,
  192. "errorTitle": "1",
  193. "errorContent": "1",
  194. "validation": "icon-ok"
  195. }
  196. ]
  197. }
  198. ]
  199. }
  200. ];
  201. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  202. expect(resolve).to.be.true;
  203. expect(res).to.be.eql(expected);
  204. });
  205. });
  206. describe('#checkRepoURLErrorCallback', function() {
  207. var stacks = Em.A([
  208. Em.Object.create({
  209. isSelected: false
  210. }),
  211. Em.Object.create({
  212. isSelected: true,
  213. reload: false,
  214. id: 'nn-cc',
  215. repositories: Em.A([
  216. Em.Object.create({
  217. repoId: 11,
  218. isSelected: true
  219. })
  220. ]),
  221. operatingSystems: Em.A([
  222. Em.Object.create({
  223. isSelected: true,
  224. id: 1,
  225. repositories: Em.A([
  226. Em.Object.create({
  227. repoId: 11,
  228. errorTitle: '1',
  229. errorContent: '1',
  230. validation: ''
  231. })
  232. ])
  233. })
  234. ])
  235. })
  236. ]);
  237. var resolve = false;
  238. var data = {
  239. osId: 1,
  240. repoId: 11,
  241. dfd: {
  242. reject: function() {
  243. resolve = true;
  244. }
  245. }
  246. };
  247. it ('Should check stacks for error', function() {
  248. var req = {
  249. status: 500,
  250. statusText: 'error'
  251. };
  252. installerController.set('content.stacks', stacks);
  253. installerController.checkRepoURLErrorCallback(req,{},{},{},data);
  254. var expected = [
  255. {
  256. "isSelected": false
  257. },
  258. {
  259. "isSelected": true,
  260. "reload": false,
  261. "id": "nn-cc",
  262. "repositories": [
  263. {
  264. "repoId": 11,
  265. "isSelected": true
  266. }
  267. ],
  268. "operatingSystems": [
  269. {
  270. "isSelected": true,
  271. "id": 1,
  272. "repositories": [
  273. {
  274. "repoId": 11,
  275. "errorTitle": "500:error",
  276. "errorContent": "",
  277. "validation": "icon-exclamation-sign"
  278. }
  279. ]
  280. }
  281. ]
  282. }
  283. ];
  284. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  285. expect(resolve).to.be.true;
  286. expect(res).to.be.eql(expected);
  287. });
  288. });
  289. describe('#setLowerStepsDisable', function() {
  290. beforeEach(function () {
  291. var steps = Em.A([
  292. Em.Object.create({
  293. step: 0,
  294. value: false
  295. }),
  296. Em.Object.create({
  297. step: 1,
  298. value: false
  299. }),
  300. Em.Object.create({
  301. step: 2,
  302. value: false
  303. }),
  304. Em.Object.create({
  305. step: 3,
  306. value: false
  307. }),
  308. Em.Object.create({
  309. step: 4,
  310. value: false
  311. })
  312. ]);
  313. installerController.set('isStepDisabled', steps);
  314. installerController.setLowerStepsDisable(3);
  315. });
  316. it ('Should disable lower steps', function() {
  317. var expected = [
  318. {
  319. "step": 0,
  320. "value": true
  321. },
  322. {
  323. "step": 1,
  324. "value": true
  325. },
  326. {
  327. "step": 2,
  328. "value": true
  329. },
  330. {
  331. "step": 3,
  332. "value": false
  333. },
  334. {
  335. "step": 4,
  336. "value": false
  337. }
  338. ];
  339. var res = JSON.parse(JSON.stringify(installerController.get('isStepDisabled')));
  340. expect(res).to.eql(expected);
  341. });
  342. });
  343. describe('#setStepsEnable', function() {
  344. beforeEach(function () {
  345. var steps = Em.A([
  346. Em.Object.create({
  347. step: 0,
  348. value: false
  349. }),
  350. Em.Object.create({
  351. step: 1,
  352. value: false
  353. }),
  354. Em.Object.create({
  355. step: 2,
  356. value: false
  357. }),
  358. Em.Object.create({
  359. step: 3,
  360. value: false
  361. }),
  362. Em.Object.create({
  363. step: 4,
  364. value: false
  365. })
  366. ]);
  367. installerController.set('isStepDisabled', steps);
  368. installerController.totalSteps = steps.length - 1;
  369. installerController.set('currentStep',2);
  370. });
  371. it ('Should enable next steps', function() {
  372. var expected = [
  373. {
  374. "step": 0,
  375. "value": false
  376. },
  377. {
  378. "step": 1,
  379. "value": true
  380. },
  381. {
  382. "step": 2,
  383. "value": true
  384. },
  385. {
  386. "step": 3,
  387. "value": true
  388. },
  389. {
  390. "step": 4,
  391. "value": true
  392. }
  393. ];
  394. var res = JSON.parse(JSON.stringify(installerController.get('isStepDisabled')));
  395. expect(res).to.eql(expected);
  396. });
  397. });
  398. describe('#loadMap', function() {
  399. describe('Should load cluster', function() {
  400. var loadCluster = false;
  401. var checker = {
  402. load: function() {
  403. loadCluster = true;
  404. }
  405. };
  406. beforeEach(function () {
  407. installerController.loadMap['0'][0].callback.call(checker);
  408. });
  409. it('cluster info is loaded', function () {
  410. expect(loadCluster).to.be.true;
  411. });
  412. });
  413. describe('Should load stacks', function() {
  414. var loadStacks = false;
  415. var checker = {
  416. loadStacks: function() {
  417. return {
  418. always: function() {
  419. loadStacks = true;
  420. }
  421. };
  422. }
  423. };
  424. beforeEach(function () {
  425. installerController.loadMap['1'][0].callback.call(checker);
  426. });
  427. it('stack info is loaded', function () {
  428. expect(loadStacks).to.be.true;
  429. });
  430. });
  431. describe ('Should load stacks async', function() {
  432. var loadStacksVersions = false;
  433. var checker = {
  434. loadStacksVersions: function() {
  435. loadStacksVersions = true;
  436. }
  437. };
  438. it('stack versions are loaded', function () {
  439. installerController.loadMap['1'][1].callback.call(checker, true).then(function(data){
  440. expect(data).to.be.true;
  441. });
  442. expect(loadStacksVersions).to.be.false;
  443. });
  444. });
  445. describe('Should load installOptions', function() {
  446. var installOptions = false;
  447. var checker = {
  448. load: function() {
  449. installOptions = true;
  450. }
  451. };
  452. beforeEach(function () {
  453. installerController.loadMap['2'][0].callback.call(checker);
  454. });
  455. it('install option are loaded', function () {
  456. expect(installOptions).to.be.true;
  457. });
  458. });
  459. describe('Should load loadConfirmedHosts', function() {
  460. var loadConfirmedHosts = false;
  461. var checker = {
  462. loadConfirmedHosts: function() {
  463. loadConfirmedHosts = true;
  464. }
  465. };
  466. beforeEach(function () {
  467. installerController.loadMap['3'][0].callback.call(checker);
  468. });
  469. it('confirmed hosts are loaded', function () {
  470. expect(loadConfirmedHosts).to.be.true;
  471. });
  472. });
  473. describe('Should load loadServices', function() {
  474. var loadServices = false;
  475. var checker = {
  476. loadServices: function() {
  477. loadServices = true;
  478. }
  479. };
  480. beforeEach(function () {
  481. installerController.loadMap['4'][0].callback.call(checker);
  482. });
  483. it('services are loaded', function () {
  484. expect(loadServices).to.be.true;
  485. });
  486. });
  487. describe('Should load loadServices (2)', function() {
  488. var setSkipSlavesStep = false;
  489. var loadMasterComponentHosts = false;
  490. var loadConfirmedHosts = false;
  491. var loadRecommendations = false;
  492. var checker = {
  493. setSkipSlavesStep: function() {
  494. setSkipSlavesStep = true;
  495. },
  496. loadMasterComponentHosts: function() {
  497. loadMasterComponentHosts = true;
  498. },
  499. loadConfirmedHosts: function() {
  500. loadConfirmedHosts = true;
  501. },
  502. loadRecommendations: function() {
  503. loadRecommendations = true;
  504. }
  505. };
  506. beforeEach(function () {
  507. installerController.loadMap['5'][0].callback.call(checker);
  508. });
  509. it('confirmed hosts are loaded', function() {
  510. expect(loadConfirmedHosts).to.be.true;
  511. });
  512. it('`skipSlavesStep` is loaded', function() {
  513. expect(setSkipSlavesStep).to.be.true;
  514. });
  515. it('master components hosts are loaded', function() {
  516. expect(loadMasterComponentHosts).to.be.true;
  517. });
  518. it('recommendations are loaded', function() {
  519. expect(loadRecommendations).to.be.true;
  520. });
  521. });
  522. describe ('Should load serviceConfigGroups', function() {
  523. var loadServiceConfigGroups = false;
  524. var loadServiceConfigProperties = false;
  525. var loadCurrentHostGroups = false;
  526. var loadRecommendationsConfigs = false;
  527. var loadConfigThemes = false;
  528. var checker = {
  529. loadServiceConfigGroups: function() {
  530. loadServiceConfigGroups = true;
  531. },
  532. loadServiceConfigProperties: function() {
  533. loadServiceConfigProperties = true;
  534. },
  535. loadCurrentHostGroups: function() {
  536. loadCurrentHostGroups = true;
  537. },
  538. loadRecommendationsConfigs: function() {
  539. loadRecommendationsConfigs = true;
  540. },
  541. loadConfigThemes: function() {
  542. loadConfigThemes = true;
  543. }
  544. };
  545. beforeEach(function () {
  546. installerController.loadMap['7'][0].callback.call(checker);
  547. });
  548. it('config groups are loaded', function () {
  549. expect(loadServiceConfigGroups).to.be.true;
  550. });
  551. it('config properties are loaded', function () {
  552. expect(loadServiceConfigProperties).to.be.true;
  553. });
  554. it('current host groups are loaded', function () {
  555. expect(loadCurrentHostGroups).to.be.true;
  556. });
  557. it('recommendations are loaded', function () {
  558. expect(loadRecommendationsConfigs).to.be.true;
  559. });
  560. it('config themes are loaded', function () {
  561. expect(loadConfigThemes).to.be.true;
  562. });
  563. });
  564. describe('Should load clients', function() {
  565. var loadSlaveComponentHosts = false;
  566. var loadClients = false;
  567. var loadRecommendations = false;
  568. var checker = {
  569. loadSlaveComponentHosts: function() {
  570. loadSlaveComponentHosts = true;
  571. },
  572. loadClients: function() {
  573. loadClients = true;
  574. },
  575. loadRecommendations: function() {
  576. loadRecommendations = true;
  577. }
  578. };
  579. beforeEach(function () {
  580. installerController.loadMap['6'][0].callback.call(checker);
  581. });
  582. it('slave components hosts are loaded', function () {
  583. expect(loadSlaveComponentHosts).to.be.true;
  584. });
  585. it('clients are loaded', function () {
  586. expect(loadClients).to.be.true;
  587. });
  588. it('recommendations are loaded', function () {
  589. expect(loadRecommendations).to.be.true;
  590. });
  591. });
  592. });
  593. describe('#removeHosts', function() {
  594. var hostsDb = {
  595. 'h1': {},
  596. 'h2': {},
  597. 'h3': {},
  598. 'h4': {}
  599. };
  600. beforeEach(function () {
  601. sinon.stub(installerController, 'getDBProperty').returns(hostsDb);
  602. });
  603. afterEach(function () {
  604. installerController.getDBProperty.restore();
  605. });
  606. it ('Should remove hosts from the list', function() {
  607. var hosts = Em.A([
  608. {
  609. name: 'h1'
  610. },
  611. {
  612. name: 'h2'
  613. },
  614. {
  615. name: 'h3'
  616. }
  617. ]);
  618. installerController.removeHosts(hosts);
  619. expect(hostsDb).to.eql({
  620. 'h4': {}
  621. });
  622. });
  623. });
  624. describe('#allHosts', function() {
  625. it ('Should return hosts', function() {
  626. var hosts = {
  627. 'h1': {
  628. disk_info: Em.A([{
  629. available: 1,
  630. size: 10
  631. }]),
  632. hostComponents: Em.A([])
  633. }
  634. };
  635. var masterComponentHosts = Em.A([
  636. {
  637. hostName: 'h1',
  638. component: 'component',
  639. display_name: 'n1'
  640. }
  641. ]);
  642. var slaveComponentHosts = Em.A([
  643. {
  644. hosts: Em.A([
  645. {
  646. hostName: 'h1'
  647. }
  648. ])
  649. }
  650. ]);
  651. installerController.set('content.hosts', hosts);
  652. installerController.set('content.masterComponentHosts', masterComponentHosts);
  653. installerController.set('content.slaveComponentHosts', slaveComponentHosts);
  654. var res = JSON.parse(JSON.stringify(installerController.get('allHosts')));
  655. expect(res).to.eql([
  656. {
  657. "diskInfo": [
  658. {
  659. "available": 1,
  660. "size": 10
  661. }
  662. ],
  663. "diskTotal": 0.0000095367431640625,
  664. "diskFree": 9.5367431640625e-7,
  665. "hostComponents": [
  666. {
  667. "componentName": "component",
  668. "displayName": "n1"
  669. },
  670. {}
  671. ]
  672. }
  673. ]);
  674. });
  675. });
  676. describe('#loadServiceConfigProperties', function() {
  677. beforeEach(function () {
  678. sinon.stub(installerController, 'getDBProperty').returns({
  679. value: 2
  680. });
  681. });
  682. afterEach(function () {
  683. installerController.getDBProperty.restore();
  684. });
  685. it ('Should load service config property', function() {
  686. installerController.loadServiceConfigProperties();
  687. expect(installerController.get('content.serviceConfigProperties')).to.eql({
  688. "value": 2
  689. });
  690. });
  691. });
  692. describe('#saveServices', function() {
  693. it ('Should return correct names', function() {
  694. var stepController = Em.A([
  695. Em.Object.create({
  696. isInstalled: true,
  697. isSelected: true,
  698. serviceName: 'i1'
  699. }),
  700. Em.Object.create({
  701. isInstalled: false,
  702. isSelected: true,
  703. serviceName: 'i2'
  704. }),
  705. Em.Object.create({
  706. isInstalled: true,
  707. isSelected: false,
  708. serviceName: 'i3'
  709. })
  710. ]);
  711. installerController.saveServices(stepController);
  712. expect(installerController.get('content.selectedServiceNames')).to.eql(['i1','i2']);
  713. expect(installerController.get('content.installedServiceNames')).to.eql(['i1','i3']);
  714. });
  715. });
  716. describe('#saveClients', function() {
  717. var stepController;
  718. beforeEach(function () {
  719. stepController = Em.Object.create({
  720. content: Em.A([
  721. Em.Object.create({
  722. isInstalled: true,
  723. isSelected: true,
  724. serviceName: 'i1',
  725. serviceComponents: Em.A([
  726. Em.Object.create({
  727. isClient: true,
  728. componentName: 'name',
  729. displayName: 'dname'
  730. })
  731. ])
  732. }),
  733. Em.Object.create({
  734. isInstalled: false,
  735. isSelected: true,
  736. serviceName: 'i2',
  737. serviceComponents: Em.A([
  738. Em.Object.create({
  739. isClient: false
  740. })
  741. ])
  742. }),
  743. Em.Object.create({
  744. isInstalled: true,
  745. isSelected: false,
  746. serviceName: 'i3',
  747. serviceComponents: Em.A([
  748. Em.Object.create({
  749. isClient: false
  750. })
  751. ])
  752. })
  753. ])
  754. });
  755. });
  756. it ('Should return correct clients names', function() {
  757. installerController.saveClients(stepController);
  758. var res = JSON.parse(JSON.stringify(installerController.get('content.clients')));
  759. expect(res).to.eql([
  760. {
  761. "component_name": "name",
  762. "display_name": "dname",
  763. "isInstalled": false
  764. }
  765. ]);
  766. });
  767. });
  768. describe('#saveMasterComponentHosts', function() {
  769. beforeEach(function () {
  770. sinon.stub(installerController, 'getDBProperty').returns({
  771. 'h1': {
  772. id: 11
  773. },
  774. 'h3': {
  775. id: 13
  776. },
  777. 'h2': {
  778. id: 12
  779. }
  780. });
  781. });
  782. afterEach(function () {
  783. installerController.getDBProperty.restore();
  784. });
  785. it ('Should return hosts', function() {
  786. var stepController = Em.Object.create({
  787. selectedServicesMasters: Em.A([
  788. Em.Object.create({
  789. display_name: 'n1',
  790. component_name: 'c1',
  791. serviceId: 1,
  792. selectedHost: 'h1'
  793. })
  794. ])
  795. });
  796. installerController.saveMasterComponentHosts(stepController);
  797. expect(installerController.get('content.masterComponentHosts')).to.eql([
  798. {
  799. "display_name": "n1",
  800. "component": "c1",
  801. "serviceId": 1,
  802. "isInstalled": false,
  803. "host_id": 11
  804. }
  805. ]);
  806. });
  807. });
  808. describe('#loadConfirmedHosts', function() {
  809. beforeEach(function () {
  810. sinon.stub(installerController, 'getDBProperty').returns({
  811. 'h1': {
  812. id: 11
  813. },
  814. 'h3': {
  815. id: 13
  816. },
  817. 'h2': {
  818. id: 12
  819. }
  820. });
  821. });
  822. afterEach(function () {
  823. installerController.getDBProperty.restore();
  824. });
  825. it ('Should load hosts from db', function() {
  826. installerController.loadConfirmedHosts();
  827. expect(installerController.get('content.hosts')).to.eql({
  828. 'h1': {
  829. id: 11
  830. },
  831. 'h3': {
  832. id: 13
  833. },
  834. 'h2': {
  835. id: 12
  836. }
  837. });
  838. });
  839. });
  840. describe('#loadMasterComponentHosts', function() {
  841. beforeEach(function () {
  842. sinon.stub(installerController, 'getDBProperties', function() {
  843. return {
  844. masterComponentHosts: Em.A([
  845. {
  846. hostName: '',
  847. host_id: 11
  848. }
  849. ]),
  850. hosts: {
  851. 'h1': {
  852. id: 11
  853. },
  854. 'h3': {
  855. id: 13
  856. },
  857. 'h2': {
  858. id: 12
  859. }
  860. }
  861. }
  862. });
  863. });
  864. afterEach(function () {
  865. installerController.getDBProperties.restore();
  866. });
  867. it ('Should load hosts', function() {
  868. installerController.loadMasterComponentHosts();
  869. expect(installerController.get('content.masterComponentHosts')).to.eql([
  870. {
  871. "hostName": "h1",
  872. "host_id": 11
  873. }
  874. ]);
  875. });
  876. });
  877. describe('#loadSlaveComponentHosts', function() {
  878. beforeEach(function () {
  879. sinon.stub(installerController, 'getDBProperties', function() {
  880. return {
  881. hosts: {
  882. 'h1': {
  883. id: 11
  884. },
  885. 'h3': {
  886. id: 13
  887. },
  888. 'h2': {
  889. id: 12
  890. }
  891. },
  892. slaveComponentHosts: Em.A([
  893. {
  894. hosts: Em.A([
  895. {
  896. hostName: '',
  897. host_id: 11
  898. }
  899. ])
  900. }
  901. ])
  902. };
  903. });
  904. });
  905. afterEach(function () {
  906. installerController.getDBProperties.restore();
  907. });
  908. it ('Should load slave hosts', function() {
  909. installerController.loadSlaveComponentHosts();
  910. expect(installerController.get('content.slaveComponentHosts')).to.eql([
  911. {
  912. "hosts": [
  913. {
  914. "hostName": "h1",
  915. "host_id": 11
  916. }
  917. ]
  918. }
  919. ]);
  920. });
  921. });
  922. describe('#getServerVersionSuccessCallback', function () {
  923. var cases = [
  924. {
  925. osFamily: 'redhat5',
  926. expected: false
  927. },
  928. {
  929. osFamily: 'redhat6',
  930. expected: true
  931. },
  932. {
  933. osFamily: 'suse11',
  934. expected: false
  935. }
  936. ],
  937. title = 'App.isManagedMySQLForHiveEnabled should be {0} for {1}';
  938. cases.forEach(function (item) {
  939. it(title.format(item.expected, item.osFamily), function () {
  940. installerController.getServerVersionSuccessCallback({
  941. 'RootServiceComponents': {
  942. 'component_version': '',
  943. 'properties': {
  944. 'server.os_family': item.osFamily
  945. }
  946. }
  947. });
  948. expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
  949. });
  950. });
  951. });
  952. describe('#validateJDKVersion', function() {
  953. var tests = [
  954. {
  955. isCustomJDK: false,
  956. ambariProperties: {
  957. 'java.version': '1.8'
  958. },
  959. successCallbackCalled: false,
  960. popupCalled: true,
  961. stacks: [Em.Object.create({
  962. minJdkVersion: '1.6',
  963. maxJdkVersion: '1.7',
  964. isSelected: true
  965. })],
  966. m: 'JDK 1.8, stack supports 1.6-1.7 popup should be displayed'
  967. },
  968. {
  969. isCustomJDK: false,
  970. ambariProperties: {
  971. 'java.version': '1.8'
  972. },
  973. successCallbackCalled: true,
  974. popupCalled: false,
  975. stacks: [Em.Object.create({
  976. minJdkVersion: '1.6',
  977. maxJdkVersion: '1.8',
  978. isSelected: true
  979. })],
  980. m: 'JDK 1.8, stack supports 1.7-1.8 procceed installation without warning'
  981. },
  982. {
  983. isCustomJDK: false,
  984. ambariProperties: {
  985. 'java.version': '1.5'
  986. },
  987. successCallbackCalled: false,
  988. popupCalled: true,
  989. stacks: [Em.Object.create({
  990. minJdkVersion: '1.6',
  991. maxJdkVersion: '1.8',
  992. isSelected: true
  993. })],
  994. m: 'JDK 1.5, stack supports 1.6-1.8, popup should be displayed'
  995. },
  996. {
  997. isCustomJDK: false,
  998. ambariProperties: {
  999. 'java.version': '1.5'
  1000. },
  1001. successCallbackCalled: true,
  1002. popupCalled: false,
  1003. stacks: [Em.Object.create({
  1004. minJdkVersion: null,
  1005. maxJdkVersion: null,
  1006. isSelected: true
  1007. })],
  1008. m: 'JDK 1.5, stack supports max and min are null, procceed installation without warning'
  1009. },
  1010. {
  1011. isCustomJDK: false,
  1012. ambariProperties: {
  1013. 'java.version': '1.5'
  1014. },
  1015. successCallbackCalled: true,
  1016. popupCalled: false,
  1017. stacks: [Em.Object.create({
  1018. minJdkVersion: '1.5',
  1019. maxJdkVersion: null,
  1020. isSelected: true
  1021. })],
  1022. m: 'JDK 1.5, stack supports max is missed and min is 1.5, procceed installation without warning'
  1023. },
  1024. {
  1025. isCustomJDK: false,
  1026. ambariProperties: {
  1027. 'java.version': '1.6'
  1028. },
  1029. successCallbackCalled: false,
  1030. popupCalled: true,
  1031. stacks: [Em.Object.create({
  1032. minJdkVersion: '1.5',
  1033. maxJdkVersion: null,
  1034. isSelected: true
  1035. })],
  1036. m: 'JDK 1.6, stack supports max is missed and min is 1.5, popup should be displayed'
  1037. },
  1038. {
  1039. isCustomJDK: false,
  1040. ambariProperties: {
  1041. 'java.version': '1.5'
  1042. },
  1043. successCallbackCalled: true,
  1044. popupCalled: false,
  1045. stacks: [Em.Object.create({
  1046. minJdkVersion: null,
  1047. maxJdkVersion: '1.5',
  1048. isSelected: true
  1049. })],
  1050. m: 'JDK 1.5, stack supports max 1.5 and min is missed, procceed installation without warning'
  1051. },
  1052. {
  1053. isCustomJDK: false,
  1054. ambariProperties: {
  1055. 'java.version': '1.5'
  1056. },
  1057. successCallbackCalled: false,
  1058. popupCalled: true,
  1059. stacks: [Em.Object.create({
  1060. minJdkVersion: null,
  1061. maxJdkVersion: '1.8',
  1062. isSelected: true
  1063. })],
  1064. m: 'JDK 1.5, stack supports max 1.8 and min is missed, popup should be displayed'
  1065. },
  1066. {
  1067. isCustomJDK: false,
  1068. ambariProperties: {
  1069. 'java.version': '1.8'
  1070. },
  1071. successCallbackCalled: true,
  1072. popupCalled: false,
  1073. stacks: [Em.Object.create({
  1074. isSelected: true
  1075. })],
  1076. m: 'JDK 1.8, min, max jdk missed in stack definition, procceed installation without warning'
  1077. },
  1078. {
  1079. isCustomJDK: true,
  1080. ambariProperties: {
  1081. 'java.version': '1.8'
  1082. },
  1083. successCallbackCalled: true,
  1084. popupCalled: false,
  1085. stacks: [Em.Object.create({
  1086. minJdkVersion: '1.6',
  1087. maxJdkVersion: '1.8',
  1088. isSelected: true
  1089. })],
  1090. m: 'JDK 1.8, custom jdk location used, procceed installation without warning'
  1091. }
  1092. ];
  1093. tests.forEach(function(test) {
  1094. describe(test.m, function() {
  1095. var successCallback;
  1096. beforeEach(function () {
  1097. sinon.stub(App.Stack, 'find').returns(test.stacks);
  1098. sinon.stub(App.router, 'get').withArgs('clusterController.isCustomJDK').returns(test.isCustomJDK)
  1099. .withArgs('clusterController.ambariProperties').returns(test.ambariProperties);
  1100. sinon.stub(App, 'showConfirmationPopup', Em.K);
  1101. successCallback = sinon.spy();
  1102. installerController.validateJDKVersion(successCallback);
  1103. });
  1104. afterEach(function () {
  1105. App.router.get.restore();
  1106. App.Stack.find.restore();
  1107. App.showConfirmationPopup.restore();
  1108. });
  1109. it('successCallback is ' + (test.successCallbackCalled ? '' : 'not') + ' called', function () {
  1110. expect(successCallback.called).to.be.equal(test.successCallbackCalled);
  1111. });
  1112. it('App.showConfirmationPopup. is ' + (test.popupCalled ? '' : 'not') + ' called', function () {
  1113. expect(App.showConfirmationPopup.called).to.be.equal(test.popupCalled);
  1114. });
  1115. });
  1116. });
  1117. });
  1118. describe('#postVersionDefinitionFileErrorCallback', function () {
  1119. beforeEach(function () {
  1120. sinon.stub(App, 'showAlertPopup', Em.K);
  1121. });
  1122. afterEach(function () {
  1123. App.showAlertPopup.restore();
  1124. });
  1125. it('should delete VDF-data', function () {
  1126. App.db.setLocalRepoVDFData({});
  1127. expect(App.db.getLocalRepoVDFData()).to.not.be.an.object;
  1128. installerController.postVersionDefinitionFileErrorCallback({}, {}, {}, {}, {dfd: $.Deferred()});
  1129. expect(App.db.getLocalRepoVDFData()).to.be.undefined;
  1130. });
  1131. });
  1132. });