highAvailability_controller_test.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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/main/admin/highAvailability_controller');
  20. require('models/host_component');
  21. require('models/host');
  22. require('utils/ajax/ajax');
  23. describe('App.MainAdminHighAvailabilityController', function () {
  24. var controller = App.MainAdminHighAvailabilityController.create();
  25. describe('#enableHighAvailability()', function () {
  26. beforeEach(function () {
  27. sinon.spy(controller, "showErrorPopup");
  28. });
  29. afterEach(function () {
  30. controller.showErrorPopup.restore();
  31. });
  32. it('Security enabled', function () {
  33. controller.set('securityEnabled', true);
  34. expect(controller.enableHighAvailability()).to.be.false;
  35. expect(controller.showErrorPopup.calledOnce).to.be.true;
  36. });
  37. it('less than 3 ZooKeeper Servers', function () {
  38. controller.set('securityEnabled', false);
  39. App.store.load(App.HostComponent, {
  40. id: "NAMENODE_host1",
  41. component_name: 'NAMENODE',
  42. work_status: 'STARTED'
  43. });
  44. expect(controller.enableHighAvailability()).to.be.false;
  45. expect(controller.showErrorPopup.calledOnce).to.be.true;
  46. App.store.loadMany(App.HostComponent, [
  47. {
  48. id: "ZOOKEEPER_SERVER_host1",
  49. component_name: 'ZOOKEEPER_SERVER'
  50. },
  51. {
  52. id: "ZOOKEEPER_SERVER_host2",
  53. component_name: 'ZOOKEEPER_SERVER'
  54. },
  55. {
  56. id: "ZOOKEEPER_SERVER_host3",
  57. component_name: 'ZOOKEEPER_SERVER'
  58. }
  59. ]);
  60. });
  61. it('Security disabled and all checks passed', function () {
  62. App.router.set('transitionTo', function () {
  63. });
  64. expect(controller.enableHighAvailability()).to.be.true;
  65. expect(controller.showErrorPopup.called).to.be.false;
  66. });
  67. it('NameNode is started', function () {
  68. App.HostComponent.find('NAMENODE_host1').set('workStatus', 'INSTALLED');
  69. expect(controller.enableHighAvailability()).to.be.false;
  70. expect(controller.showErrorPopup.calledOnce).to.be.true;
  71. App.HostComponent.find('NAMENODE_host1').set('workStatus', 'STARTED');
  72. });
  73. });
  74. describe('#setSecurityStatus()', function () {
  75. beforeEach(function () {
  76. sinon.stub(App.ajax, "send", Em.K);
  77. });
  78. afterEach(function () {
  79. App.ajax.send.restore();
  80. });
  81. it('testMode = true', function () {
  82. App.testEnableSecurity = false;
  83. App.testMode = true;
  84. controller.set('securityEnabled', false);
  85. controller.set('dataIsLoaded', false);
  86. controller.setSecurityStatus();
  87. expect(controller.get('securityEnabled')).to.be.true;
  88. expect(controller.get('dataIsLoaded')).to.be.true;
  89. expect(App.ajax.send.called).to.be.false;
  90. });
  91. it('testMode = false', function () {
  92. App.testMode = false;
  93. controller.set('securityEnabled', false);
  94. controller.set('dataIsLoaded', false);
  95. controller.setSecurityStatus();
  96. expect(controller.get('securityEnabled')).to.be.false;
  97. expect(controller.get('dataIsLoaded')).to.be.false;
  98. expect(App.ajax.send.calledOnce).to.be.true;
  99. });
  100. });
  101. describe('#getSecurityStatusFromServerSuccessCallback()', function () {
  102. beforeEach(function () {
  103. sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
  104. sinon.stub(controller, "showErrorPopup", Em.K);
  105. });
  106. afterEach(function () {
  107. controller.getServiceConfigsFromServer.restore();
  108. controller.showErrorPopup.restore();
  109. });
  110. it('desired_configs is empty', function () {
  111. var data = {
  112. Clusters: {
  113. desired_configs: {}
  114. }
  115. };
  116. controller.getSecurityStatusFromServerSuccessCallback(data);
  117. expect(controller.showErrorPopup.calledOnce).to.be.true;
  118. });
  119. it('desired_configs does not have "global"', function () {
  120. var data = {
  121. Clusters: {
  122. desired_configs: {
  123. 'hdfs-site': {}
  124. }
  125. }
  126. };
  127. controller.getSecurityStatusFromServerSuccessCallback(data);
  128. expect(controller.showErrorPopup.calledOnce).to.be.true;
  129. });
  130. it('desired_configs does not have "global"', function () {
  131. var data = {
  132. Clusters: {
  133. desired_configs: {
  134. 'global': {
  135. tag: 1
  136. }
  137. }
  138. }
  139. };
  140. controller.getSecurityStatusFromServerSuccessCallback(data);
  141. expect(controller.get('tag')).to.equal(1);
  142. expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
  143. expect(controller.showErrorPopup.called).to.be.false;
  144. });
  145. });
  146. describe('#getSecurityStatusFromServerSuccessCallback()', function () {
  147. beforeEach(function () {
  148. sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
  149. sinon.stub(controller, "showErrorPopup", Em.K);
  150. });
  151. afterEach(function () {
  152. controller.getServiceConfigsFromServer.restore();
  153. controller.showErrorPopup.restore();
  154. });
  155. it('desired_configs is empty', function () {
  156. var data = {
  157. Clusters: {
  158. desired_configs: {}
  159. }
  160. };
  161. controller.getSecurityStatusFromServerSuccessCallback(data);
  162. expect(controller.showErrorPopup.calledOnce).to.be.true;
  163. });
  164. it('desired_configs does not have "global"', function () {
  165. var data = {
  166. Clusters: {
  167. desired_configs: {
  168. 'hdfs-site': {}
  169. }
  170. }
  171. };
  172. controller.getSecurityStatusFromServerSuccessCallback(data);
  173. expect(controller.showErrorPopup.calledOnce).to.be.true;
  174. });
  175. it('desired_configs does not have "global"', function () {
  176. var data = {
  177. Clusters: {
  178. desired_configs: {
  179. 'global': {
  180. tag: 1
  181. }
  182. }
  183. }
  184. };
  185. controller.getSecurityStatusFromServerSuccessCallback(data);
  186. expect(controller.get('tag')).to.equal(1);
  187. expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
  188. expect(controller.showErrorPopup.called).to.be.false;
  189. });
  190. });
  191. describe('#joinMessage()', function () {
  192. it('message is empty', function () {
  193. var message = [];
  194. expect(controller.joinMessage(message)).to.be.empty;
  195. });
  196. it('message is array from two strings', function () {
  197. var message = ['yes', 'no'];
  198. expect(controller.joinMessage(message)).to.equal('yes<br/>no');
  199. });
  200. it('message is string', function () {
  201. var message = 'hello';
  202. expect(controller.joinMessage(message)).to.equal('<p>hello</p>');
  203. });
  204. });
  205. describe('#getServiceConfigsFromServer()', function () {
  206. it('properties is null', function () {
  207. App.router.set('configurationController', Em.Object.create({
  208. getConfigsByTags: function () {
  209. return this.get('data');
  210. },
  211. data: [
  212. {
  213. tag: 1,
  214. properties: null
  215. }
  216. ]
  217. }));
  218. controller.getServiceConfigsFromServer();
  219. expect(controller.get('dataIsLoaded')).to.be.true;
  220. expect(controller.get('securityEnabled')).to.be.false;
  221. });
  222. it('"security_enabled" config is absent', function () {
  223. App.router.set('configurationController.data', [
  224. {
  225. tag: 1,
  226. properties: {}
  227. }
  228. ]);
  229. controller.getServiceConfigsFromServer();
  230. expect(controller.get('dataIsLoaded')).to.be.true;
  231. expect(controller.get('securityEnabled')).to.be.false;
  232. });
  233. it('"security_enabled" is false', function () {
  234. App.router.set('configurationController.data', [
  235. {
  236. tag: 1,
  237. properties: {
  238. 'security_enabled': false
  239. }
  240. }
  241. ]);
  242. controller.getServiceConfigsFromServer();
  243. expect(controller.get('dataIsLoaded')).to.be.true;
  244. expect(controller.get('securityEnabled')).to.be.false;
  245. });
  246. it('"security_enabled" is "false"', function () {
  247. App.router.set('configurationController.data', [
  248. {
  249. tag: 1,
  250. properties: {
  251. 'security_enabled': "false"
  252. }
  253. }
  254. ]);
  255. controller.getServiceConfigsFromServer();
  256. expect(controller.get('dataIsLoaded')).to.be.true;
  257. expect(controller.get('securityEnabled')).to.be.false;
  258. });
  259. it('"security_enabled" is "true"', function () {
  260. App.router.set('configurationController.data', [
  261. {
  262. tag: 1,
  263. properties: {
  264. 'security_enabled': "true"
  265. }
  266. }
  267. ]);
  268. controller.getServiceConfigsFromServer();
  269. expect(controller.get('dataIsLoaded')).to.be.true;
  270. expect(controller.get('securityEnabled')).to.be.true;
  271. });
  272. it('"security_enabled" is true', function () {
  273. App.router.set('configurationController.data', [
  274. {
  275. tag: 1,
  276. properties: {
  277. 'security_enabled': true
  278. }
  279. }
  280. ]);
  281. controller.getServiceConfigsFromServer();
  282. expect(controller.get('dataIsLoaded')).to.be.true;
  283. expect(controller.get('securityEnabled')).to.be.true;
  284. });
  285. });
  286. });