step2_test.js 20 KB

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