step2_test.js 20 KB

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