step2_test.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 Ember = require('ember');
  20. require('controllers/wizard/step2_controller');
  21. require('models/host');
  22. require('models/host_component');
  23. require('messages');
  24. var c;
  25. describe('App.WizardStep2Controller', function () {
  26. beforeEach(function() {
  27. c = App.WizardStep2Controller.create();
  28. });
  29. describe('#isInstaller', function() {
  30. it('true if controllerName is installerController', function() {
  31. var controller = App.WizardStep2Controller.create({content: {controllerName: 'installerController'}});
  32. expect(controller.get('isInstaller')).to.equal(true);
  33. });
  34. it('false if controllerName isn\'t installerController', function() {
  35. var controller = App.WizardStep2Controller.create({content: {controllerName: 'addServiceController'}});
  36. expect(controller.get('isInstaller')).to.equal(false);
  37. });
  38. });
  39. describe('#manualInstall', function() {
  40. it('should be equal to content.installOptions.manualInstall', function() {
  41. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
  42. expect(controller.get('manualInstall')).to.equal(true);
  43. controller.toggleProperty('content.installOptions.manualInstall');
  44. expect(controller.get('manualInstall')).to.equal(false);
  45. });
  46. });
  47. describe('#hostNames', function() {
  48. it('should be equal to content.installOptions.hostNames', function() {
  49. var controller = App.WizardStep2Controller.create({content: {installOptions: {hostNames: 'A,b,C'}}});
  50. expect(controller.get('hostNames')).to.equal('a,b,c');
  51. controller.set('content.installOptions.hostNames', 'a,B');
  52. expect(controller.get('hostNames')).to.equal('a,b');
  53. });
  54. });
  55. describe('#sshKey', function() {
  56. it('should be equal to content.installOptions.sshKey', function() {
  57. var controller = App.WizardStep2Controller.create({content: {installOptions: {sshKey: '123'}}});
  58. expect(controller.get('sshKey')).to.equal('123');
  59. controller.set('content.installOptions.sshKey', '321');
  60. expect(controller.get('sshKey')).to.equal('321');
  61. });
  62. });
  63. describe('#sshUser', function() {
  64. it('should be equal to content.installOptions.sshUser', function() {
  65. var controller = App.WizardStep2Controller.create({content: {installOptions: {sshUser: '123'}}});
  66. expect(controller.get('sshUser')).to.equal('123');
  67. controller.set('content.installOptions.sshUser', '321');
  68. expect(controller.get('sshUser')).to.equal('321');
  69. });
  70. });
  71. describe('#installType', function() {
  72. it('should be manualDriven if manualInstall is selected', function() {
  73. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
  74. expect(controller.get('installType')).to.equal('manualDriven');
  75. });
  76. it('should be ambariDriven if manualInstall isn\'t selected', function() {
  77. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: false}}});
  78. expect(controller.get('installType')).to.equal('ambariDriven');
  79. });
  80. });
  81. describe('#updateHostNameArr()', function () {
  82. var controller = App.WizardStep2Controller.create({
  83. hostNames: 'apache.ambari'
  84. });
  85. controller.updateHostNameArr();
  86. it('should push to hostNameArr only new host names', function(){
  87. expect(controller.get('hostNameArr').length).to.equal(1);
  88. });
  89. it('should push to inputtedAgainHostNames already installed host names', function(){
  90. expect(controller.get('inputtedAgainHostNames').length).to.equal(0);
  91. })
  92. });
  93. describe('#isAllHostNamesValid()', function () {
  94. var controller = App.WizardStep2Controller.create({
  95. hostNames: ''
  96. });
  97. it('should return true if all host names are valid', function(){
  98. controller.set('hostNames', 'amache.org ambari.com');
  99. expect(controller.isAllHostNamesValid()).to.equal(true);
  100. });
  101. var tests = Em.A([
  102. 'hostname',
  103. '-hostname.com',
  104. 'hostname-.com',
  105. 'host_name.com',
  106. '123.123.123.123',
  107. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname',
  108. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostname'
  109. ]);
  110. tests.forEach(function (test) {
  111. it('should return false for invalid host names ' + test + ' ', function () {
  112. controller.set('hostNames', test);
  113. expect(controller.isAllHostNamesValid()).to.equal(false);
  114. });
  115. });
  116. });
  117. describe('#checkHostError()', function () {
  118. var controller = App.WizardStep2Controller.create();
  119. it('should set hostsError if hostNames is ""', function () {
  120. controller.set('content', {'installOptions': {'hostNames': ''}});
  121. controller.checkHostError();
  122. expect(controller.get('hostsError').length).to.be.above(2);
  123. });
  124. it('should set hostsError to null if hostNames is valid', function () {
  125. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  126. controller.checkHostError();
  127. expect(controller.get('hostsError')).to.equal(null);
  128. })
  129. });
  130. describe('#checkHostAfterSubmitHandler()', function () {
  131. it('should be called after changing hasSubmitted', function (done) {
  132. var controller = App.WizardStep2Controller.create({
  133. checkHostError: function () {
  134. done();
  135. }
  136. });
  137. controller.set('hasSubmitted', true);
  138. });
  139. it('should be called after changing hostNames', function (done) {
  140. var controller = App.WizardStep2Controller.create({
  141. hasSubmitted: true,
  142. checkHostError: function () {
  143. done();
  144. }
  145. });
  146. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  147. })
  148. });
  149. describe('#sshKeyError', function () {
  150. var tests = Em.A([
  151. {
  152. manualInstall: false,
  153. sshKey: '',
  154. hasSubmitted: false,
  155. e: null
  156. },
  157. {
  158. manualInstall: true,
  159. sshKey: '',
  160. hasSubmitted: false,
  161. e: null
  162. },
  163. {
  164. manualInstall: true,
  165. sshKey: 'nobody',
  166. hasSubmitted: false,
  167. e: null
  168. },
  169. {
  170. manualInstall: false,
  171. sshKey: 'nobody',
  172. hasSubmitted: false,
  173. e: null
  174. },
  175. {
  176. manualInstall: false,
  177. sshKey: '',
  178. hasSubmitted: true,
  179. e: null
  180. },
  181. {
  182. manualInstall: true,
  183. sshKey: '',
  184. hasSubmitted: true,
  185. e: null
  186. },
  187. {
  188. manualInstall: true,
  189. sshKey: 'nobody',
  190. hasSubmitted: true,
  191. e: null
  192. },
  193. {
  194. manualInstall: false,
  195. sshKey: 'nobody',
  196. hasSubmitted: true,
  197. e: null
  198. }
  199. ]);
  200. tests.forEach(function(test) {
  201. it(test.sshKey + ' ' + test.manualInstall.toString() + ' ' + test.hasSubmitted.toString(), function() {
  202. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshKey: test.sshKey}}});
  203. if(Em.isNone(test.e)) {
  204. expect(controller.get('sshKeyError')).to.equal(null);
  205. }
  206. else {
  207. expect(controller.get('sshKeyError').length).to.be.above(2);
  208. }
  209. });
  210. });
  211. });
  212. describe('#sshUserError', function () {
  213. var tests = Em.A([
  214. {
  215. manualInstall: false,
  216. sshUser: '',
  217. e: ''
  218. },
  219. {
  220. manualInstall: true,
  221. sshUser: '',
  222. e: null
  223. },
  224. {
  225. manualInstall: true,
  226. sshUser: 'nobody',
  227. e: null
  228. },
  229. {
  230. manualInstall: false,
  231. sshUser: 'nobody',
  232. e: null
  233. }
  234. ]);
  235. tests.forEach(function(test) {
  236. it('', function() {
  237. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshUser: test.sshUser}}});
  238. if(Em.isNone(test.e)) {
  239. expect(controller.get('sshUserError')).to.equal(null);
  240. }
  241. else {
  242. expect(controller.get('sshUserError').length).to.be.above(2);
  243. }
  244. });
  245. });
  246. });
  247. describe('#getHostInfo()', function () {
  248. it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
  249. var controller = App.WizardStep2Controller.create({
  250. hostNameArr: ['apache', 'ambari'],
  251. installType: 'manualDriven'
  252. });
  253. var test = controller.getHostInfo();
  254. expect(test).to.eql({
  255. 'apache':{'name':'apache', 'installType': 'manualDriven', 'bootStatus': 'PENDING', isInstalled: false},
  256. 'ambari':{'name':'ambari', 'installType': 'manualDriven', 'bootStatus': 'PENDING', isInstalled: false}
  257. });
  258. })
  259. });
  260. describe('#setSshKey()', function () {
  261. it('should set content.installOptions.sshKey', function () {
  262. var controller = App.WizardStep2Controller.create({
  263. content: {'installOptions': {'sshKey': '111'}}
  264. });
  265. controller.setSshKey('222');
  266. expect(controller.get('content.installOptions.sshKey')).to.equal('222');
  267. })
  268. });
  269. describe('#evaluateStep()', function () {
  270. it('should return false if isSubmitDisabled is true', function () {
  271. var controller = App.WizardStep2Controller.create({
  272. hostNames: 'apache.ambari',
  273. parseHostNamesAsPatternExpression: Em.K
  274. });
  275. controller.reopen({isSubmitDisabled: true});
  276. expect(controller.evaluateStep()).to.equal(false);
  277. });
  278. it('should return false if hostsError is not empty', function () {
  279. var controller = App.WizardStep2Controller.create({
  280. hostNames: 'apache.ambari',
  281. parseHostNamesAsPatternExpression: Em.K
  282. });
  283. controller.set('hostsError', 'error');
  284. expect(controller.evaluateStep()).to.equal(false);
  285. });
  286. it('should return false if sshKeyError is not empty', function () {
  287. var controller = App.WizardStep2Controller.create({
  288. hostNames: 'apache.ambari',
  289. parseHostNamesAsPatternExpression: Em.K
  290. });
  291. controller.reopen({sshKeyError: 'error'});
  292. expect(controller.evaluateStep()).to.equal(false);
  293. });
  294. it('should return false if hostNameArr is empty', function () {
  295. var controller = App.WizardStep2Controller.create({
  296. hostNames: '',
  297. parseHostNamesAsPatternExpression: Em.K
  298. });
  299. expect(controller.evaluateStep()).to.equal(false);
  300. });
  301. it('should return false if isPattern is true', function () {
  302. var controller = App.WizardStep2Controller.create({
  303. hostNames: 'apache.ambari',
  304. isPattern: true,
  305. parseHostNamesAsPatternExpression: Em.K
  306. });
  307. expect(controller.evaluateStep()).to.equal(false);
  308. })
  309. });
  310. describe('#parseHostNamesAsPatternExpression()', function () {
  311. it('should parse hosts from pattern expression to hostNameArr', function () {
  312. var controller = App.WizardStep2Controller.create({
  313. hostNameArr: ['host[001-011]']
  314. });
  315. controller.parseHostNamesAsPatternExpression();
  316. var result = true;
  317. var hosts = controller.get('hostNameArr');
  318. for (var i = 1; i<12; i++) {
  319. var extra = (i.toString().length == 1) ? 0 : '';
  320. if (hosts[i-1] !== 'host0' + extra + i) {
  321. result = false;
  322. }
  323. }
  324. expect(result).to.equal(true);
  325. })
  326. });
  327. describe('#proceedNext()', function () {
  328. it('should call warningPopup if not isAllHostNamesValid and no warningConfirmed', function() {
  329. c.reopen({
  330. isAllHostNamesValid: function() {
  331. return false;
  332. },
  333. warningPopup: Em.K
  334. });
  335. sinon.spy(c, 'warningPopup');
  336. var r = c.proceedNext(false);
  337. expect(r).to.equal(false);
  338. expect(c.warningPopup.calledOnce).to.equal(true);
  339. });
  340. it('should call manualInstallPopup if manualInstall is true', function () {
  341. c.reopen({
  342. hostNames: '',
  343. manualInstall: true,
  344. manualInstallPopup: Em.K
  345. });
  346. sinon.spy(c, 'manualInstallPopup');
  347. var r = c.proceedNext(true);
  348. expect(r).to.equal(false);
  349. expect(c.manualInstallPopup.calledOnce).to.equal(true);
  350. });
  351. it ('should save hosts and proceed next if skipBootstrap is true', function() {
  352. sinon.stub(App, 'get', function(k) {
  353. if ('skipBootstrap' === k) {
  354. return true;
  355. }
  356. return Em.get(App, k);
  357. });
  358. sinon.stub(App.router, 'send', Em.K);
  359. c.reopen({
  360. hostNameArr: ['h1'],
  361. isAllHostNamesValid: function() {return true;},
  362. content: {
  363. installOptions: {},
  364. hosts: null
  365. }
  366. });
  367. var r = c.proceedNext();
  368. expect(r).to.equal(true);
  369. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  370. expect(App.router.send.calledWith('next')).to.equal(true);
  371. App.get.restore();
  372. App.router.send.restore();
  373. });
  374. it('should call setupBootStrap', function() {
  375. sinon.stub(App, 'get', function(k) {
  376. if ('skipBootstrap' === k) {
  377. return false;
  378. }
  379. return Em.get(App, k);
  380. });
  381. c.reopen({
  382. hostNameArr: ['h1'],
  383. isAllHostNamesValid: function() {return true;},
  384. content: {
  385. installOptions: {},
  386. hosts: null
  387. }
  388. });
  389. sinon.stub(c, 'setupBootStrap', Em.K);
  390. var r = c.proceedNext();
  391. expect(r).to.equal(true);
  392. expect(c.setupBootStrap.calledOnce).to.eql(true);
  393. App.get.restore();
  394. c.setupBootStrap.restore();
  395. });
  396. });
  397. describe('#isSubmitDisabled', function () {
  398. var controller = App.WizardStep2Controller.create({
  399. hostsError: '',
  400. sshKeyError: ''
  401. });
  402. it('should return value if hostsError is not empty', function () {
  403. controller.set('hostsError', 'error');
  404. expect(controller.get('isSubmitDisabled').length).to.above(0);
  405. });
  406. it('should return value if sshKeyError is not empty', function () {
  407. controller.set('sshKeyError', 'error');
  408. controller.set('hostsError', '');
  409. expect(controller.get('isSubmitDisabled').length).to.above(0);
  410. })
  411. });
  412. describe('#installedHostsPopup', function() {
  413. beforeEach(function() {
  414. sinon.spy(App.ModalPopup, 'show');
  415. sinon.stub(c, 'proceedNext', Em.K);
  416. });
  417. afterEach(function() {
  418. App.ModalPopup.show.restore();
  419. c.proceedNext.restore();
  420. });
  421. it('should call App.ModalPopup.show', function() {
  422. c.installedHostsPopup();
  423. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  424. });
  425. it('should proceed next on primary', function() {
  426. c.installedHostsPopup().onPrimary();
  427. expect(c.proceedNext.calledOnce).to.equal(true);
  428. });
  429. });
  430. describe('#warningPopup', function() {
  431. beforeEach(function() {
  432. sinon.spy(App.ModalPopup, 'show');
  433. sinon.stub(c, 'proceedNext', Em.K);
  434. });
  435. afterEach(function() {
  436. App.ModalPopup.show.restore();
  437. c.proceedNext.restore();
  438. });
  439. it('should call App.ModalPopup.show', function() {
  440. c.warningPopup();
  441. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  442. });
  443. it('should proceed next on primary', function() {
  444. c.warningPopup().onPrimary();
  445. expect(c.proceedNext.calledWith(true)).to.equal(true);
  446. });
  447. });
  448. describe('#hostNamePatternPopup', function() {
  449. beforeEach(function() {
  450. sinon.spy(App.ModalPopup, 'show');
  451. sinon.stub(c, 'proceedNext', Em.K);
  452. });
  453. afterEach(function() {
  454. App.ModalPopup.show.restore();
  455. c.proceedNext.restore();
  456. });
  457. it('should call App.ModalPopup.show', function() {
  458. c.hostNamePatternPopup();
  459. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  460. });
  461. it('should proceed next on primary', function() {
  462. c.hostNamePatternPopup().onPrimary();
  463. expect(c.proceedNext.calledOnce).to.equal(true);
  464. });
  465. });
  466. describe('#manualInstallPopup', function() {
  467. beforeEach(function() {
  468. sinon.spy(App.ModalPopup, 'show');
  469. sinon.stub(App.router, 'send', Em.K);
  470. sinon.stub(c, 'saveHosts', Em.K);
  471. });
  472. afterEach(function() {
  473. App.ModalPopup.show.restore();
  474. App.router.send.restore();
  475. c.saveHosts.restore();
  476. });
  477. it('should call App.ModalPopup.show', function() {
  478. c.manualInstallPopup();
  479. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  480. });
  481. it('should save hosts and go next on primary', function() {
  482. c.manualInstallPopup().onPrimary();
  483. expect(c.saveHosts.calledOnce).to.equal(true);
  484. expect(App.router.send.calledWith('next')).to.equal(true);
  485. });
  486. });
  487. describe('#manualInstallWarningPopup', function() {
  488. beforeEach(function() {
  489. sinon.spy(App.ModalPopup, 'show');
  490. });
  491. afterEach(function() {
  492. App.ModalPopup.show.restore();
  493. });
  494. it('should call App.ModalPopup.show if content.installOptions.useSsh is false', function() {
  495. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: false}}});
  496. controller.manualInstallWarningPopup();
  497. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  498. });
  499. it('shouldn\'t call App.ModalPopup.show if content.installOptions.useSsh is true', function() {
  500. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: true}}});
  501. controller.manualInstallWarningPopup();
  502. expect(App.ModalPopup.show.called).to.equal(false);
  503. });
  504. });
  505. describe('#setAmbariJavaHome', function() {
  506. beforeEach(function() {
  507. sinon.spy($, 'ajax');
  508. });
  509. afterEach(function() {
  510. $.ajax.restore();
  511. });
  512. it('should do ajax-request', function() {
  513. var controller = App.WizardStep2Controller.create({onGetAmbariJavaHomeSuccess: Em.K, onGetAmbariJavaHomeError: Em.K});
  514. controller.setAmbariJavaHome();
  515. expect($.ajax.calledOnce).to.equal(true);
  516. });
  517. });
  518. describe('#onGetAmbariJavaHomeSuccess', function() {
  519. it('should set java.home value receiced from server', function() {
  520. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  521. var test = {RootServiceComponents: {properties: {'java.home': '/root'}}};
  522. controller.onGetAmbariJavaHomeSuccess(test);
  523. expect(controller.content.installOptions.javaHome).to.equal('/root');
  524. });
  525. });
  526. describe('#onGetAmbariJavaHomeError', function() {
  527. it('should set default java.home value', function() {
  528. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  529. controller.onGetAmbariJavaHomeError();
  530. expect(controller.content.installOptions.javaHome).to.equal(App.get('defaultJavaHome'));
  531. });
  532. });
  533. describe('#saveHosts', function() {
  534. beforeEach(function() {
  535. sinon.stub(c, 'setAmbariJavaHome', Em.K);
  536. c.reopen({
  537. hostNameArr: ['h1'],
  538. content: {
  539. hosts: null
  540. }
  541. });
  542. });
  543. afterEach(function() {
  544. c.setAmbariJavaHome.restore();
  545. });
  546. it('should call setAmbariJavaHome', function() {
  547. c.saveHosts();
  548. expect(c.setAmbariJavaHome.calledOnce).to.equal(true);
  549. });
  550. it('should set content.hosts', function() {
  551. c.saveHosts();
  552. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  553. });
  554. });
  555. });