step2_test.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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('controllers/wizard/step2_controller');
  20. require('models/host');
  21. require('models/host_component');
  22. require('messages');
  23. var testHelpers = require('test/helpers');
  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', 'App.router.btnClickInProgress']);
  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 parse hosts from multiple pattern expression to hostNameArr', function () {
  362. var controller = App.WizardStep2Controller.create({
  363. hostNameArr: ['test[1-2]host[01-05]']
  364. });
  365. controller.parseHostNamesAsPatternExpression();
  366. var hosts = controller.get('hostNameArr');
  367. expect(hosts).eql([
  368. 'test1host01',
  369. 'test1host02',
  370. 'test1host03',
  371. 'test1host04',
  372. 'test1host05',
  373. 'test2host01',
  374. 'test2host02',
  375. 'test2host03',
  376. 'test2host04',
  377. 'test2host05'
  378. ]);
  379. });
  380. it('should skip duplicates', function () {
  381. var controller = App.WizardStep2Controller.create({
  382. hostNameArr: ['host[1-3]', 'host2']
  383. });
  384. controller.parseHostNamesAsPatternExpression();
  385. expect(controller.get('hostNameArr')).to.eql(['host1', 'host2', 'host3']);
  386. });
  387. });
  388. describe('#proceedNext()', function () {
  389. beforeEach(function () {
  390. sinon.stub(c, 'warningPopup', Em.K);
  391. sinon.stub(c, 'manualInstallPopup', Em.K);
  392. sinon.stub(App.router, 'send', Em.K);
  393. });
  394. afterEach(function () {
  395. c.warningPopup.restore();
  396. c.manualInstallPopup.restore();
  397. App.router.send.restore();
  398. });
  399. it('should call warningPopup if not isAllHostNamesValid and no warningConfirmed', function() {
  400. c.reopen({
  401. isAllHostNamesValid: function() {
  402. return false;
  403. }
  404. });
  405. var r = c.proceedNext(false);
  406. expect(r).to.equal(false);
  407. expect(c.warningPopup.calledOnce).to.equal(true);
  408. });
  409. it('should call manualInstallPopup if manualInstall is true', function () {
  410. c.reopen({
  411. hostNames: '',
  412. manualInstall: true
  413. });
  414. var r = c.proceedNext(true);
  415. expect(r).to.equal(false);
  416. expect(c.manualInstallPopup.calledOnce).to.equal(true);
  417. });
  418. it ('should save hosts and proceed next if manualInstall is false', function() {
  419. c.reopen({
  420. hostNameArr: ['h1'],
  421. manualInstall: false,
  422. isAllHostNamesValid: function() {return true;},
  423. content: {
  424. installOptions: {},
  425. hosts: null
  426. }
  427. });
  428. var r = c.proceedNext();
  429. expect(r).to.equal(true);
  430. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  431. expect(App.router.send.calledWith('next')).to.equal(true);
  432. });
  433. });
  434. describe('#installedHostsPopup', function() {
  435. beforeEach(function() {
  436. sinon.spy(App.ModalPopup, 'show');
  437. sinon.stub(c, 'proceedNext', Em.K);
  438. });
  439. afterEach(function() {
  440. App.ModalPopup.show.restore();
  441. c.proceedNext.restore();
  442. });
  443. it('should call App.ModalPopup.show', function() {
  444. c.installedHostsPopup();
  445. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  446. });
  447. it('should proceed next on primary', function() {
  448. c.installedHostsPopup().onPrimary();
  449. expect(c.proceedNext.calledOnce).to.equal(true);
  450. });
  451. });
  452. describe('#warningPopup', function() {
  453. beforeEach(function() {
  454. sinon.spy(App.ModalPopup, 'show');
  455. sinon.stub(c, 'proceedNext', Em.K);
  456. });
  457. afterEach(function() {
  458. App.ModalPopup.show.restore();
  459. c.proceedNext.restore();
  460. });
  461. it('should call App.ModalPopup.show', function() {
  462. c.warningPopup();
  463. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  464. });
  465. it('should proceed next on primary', function() {
  466. c.warningPopup().onPrimary();
  467. expect(c.proceedNext.calledWith(true)).to.equal(true);
  468. });
  469. });
  470. describe('#hostNamePatternPopup', function() {
  471. beforeEach(function() {
  472. sinon.spy(App.ModalPopup, 'show');
  473. sinon.stub(c, 'proceedNext', Em.K);
  474. });
  475. afterEach(function() {
  476. App.ModalPopup.show.restore();
  477. c.proceedNext.restore();
  478. });
  479. it('should call App.ModalPopup.show', function() {
  480. c.hostNamePatternPopup();
  481. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  482. });
  483. it('should proceed next on primary', function() {
  484. c.hostNamePatternPopup().onPrimary();
  485. expect(c.proceedNext.calledOnce).to.equal(true);
  486. });
  487. });
  488. describe('#manualInstallPopup', function() {
  489. beforeEach(function() {
  490. sinon.spy(App.ModalPopup, 'show');
  491. sinon.stub(App.router, 'send', Em.K);
  492. sinon.stub(c, 'saveHosts', Em.K);
  493. });
  494. afterEach(function() {
  495. App.ModalPopup.show.restore();
  496. App.router.send.restore();
  497. c.saveHosts.restore();
  498. });
  499. it('should call App.ModalPopup.show', function() {
  500. c.manualInstallPopup();
  501. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  502. });
  503. it('should save hosts and go next on primary', function() {
  504. c.manualInstallPopup().onPrimary();
  505. expect(c.saveHosts.calledOnce).to.equal(true);
  506. expect(App.router.send.calledWith('next')).to.equal(true);
  507. });
  508. });
  509. describe('#manualInstallWarningPopup', function() {
  510. beforeEach(function() {
  511. sinon.spy(App.ModalPopup, 'show');
  512. });
  513. afterEach(function() {
  514. App.ModalPopup.show.restore();
  515. });
  516. it('should call App.ModalPopup.show if content.installOptions.useSsh is false', function() {
  517. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: false}}});
  518. controller.manualInstallWarningPopup();
  519. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  520. });
  521. it('shouldn\'t call App.ModalPopup.show if content.installOptions.useSsh is true', function() {
  522. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: true}}});
  523. controller.manualInstallWarningPopup();
  524. expect(App.ModalPopup.show.called).to.equal(false);
  525. });
  526. });
  527. describe('#setAmbariJavaHome', function() {
  528. it('should do ajax-request', function() {
  529. var controller = App.WizardStep2Controller.create({onGetAmbariJavaHomeSuccess: Em.K, onGetAmbariJavaHomeError: Em.K});
  530. controller.setAmbariJavaHome();
  531. var args = testHelpers.findAjaxRequest('name', 'ambari.service');
  532. expect(args).exists;
  533. });
  534. });
  535. describe('#onGetAmbariJavaHomeSuccess', function() {
  536. it('should set java.home value receiced from server', function() {
  537. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  538. var test = {RootServiceComponents: {properties: {'java.home': '/root'}}};
  539. controller.onGetAmbariJavaHomeSuccess(test);
  540. expect(controller.content.installOptions.javaHome).to.equal('/root');
  541. });
  542. });
  543. describe('#onGetAmbariJavaHomeError', function() {
  544. it('should set default java.home value', function() {
  545. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  546. controller.onGetAmbariJavaHomeError();
  547. expect(controller.content.installOptions.javaHome).to.equal(App.get('defaultJavaHome'));
  548. });
  549. });
  550. describe('#saveHosts', function() {
  551. beforeEach(function() {
  552. sinon.stub(c, 'setAmbariJavaHome', Em.K);
  553. c.reopen({
  554. hostNameArr: ['h1'],
  555. content: {
  556. hosts: null
  557. }
  558. });
  559. });
  560. afterEach(function() {
  561. c.setAmbariJavaHome.restore();
  562. });
  563. it('should call setAmbariJavaHome', function() {
  564. c.saveHosts();
  565. expect(c.setAmbariJavaHome.calledOnce).to.equal(true);
  566. });
  567. it('should set content.hosts', function() {
  568. c.saveHosts();
  569. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  570. });
  571. });
  572. });