step2_test.js 20 KB

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