step3_test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('utils/http_client');
  21. require('models/host');
  22. require('controllers/wizard/step3_controller');
  23. describe('App.WizardStep3Controller', function () {
  24. describe('#getAllRegisteredHostsCallback', function () {
  25. it('One host is already in the cluster, one host is registered', function() {
  26. var controller = App.WizardStep3Controller.create({
  27. hostsInCluster: [{
  28. hostName: 'wst3_host1'
  29. }],
  30. bootHosts: [
  31. {name:'wst3_host1'},
  32. {name:'wst3_host2'}
  33. ]
  34. });
  35. var test_data = {
  36. items: [
  37. {
  38. Hosts: {
  39. host_name: 'wst3_host1'
  40. }
  41. },
  42. {
  43. Hosts: {
  44. host_name: 'wst3_host2'
  45. }
  46. },
  47. {
  48. Hosts: {
  49. host_name: 'wst3_host3'
  50. }
  51. }
  52. ]
  53. };
  54. controller.getAllRegisteredHostsCallback(test_data);
  55. expect(controller.get('hasMoreRegisteredHosts')).to.equal(true);
  56. expect(controller.get('registeredHosts').length).to.equal(1);
  57. });
  58. it('All hosts are new', function() {
  59. var controller = App.WizardStep3Controller.create({
  60. hostsInCluster: [{
  61. hostName: 'wst3_host1'
  62. }],
  63. bootHosts: [
  64. {name:'wst3_host3'},
  65. {name:'wst3_host4'}
  66. ]
  67. });
  68. var test_data = {
  69. items: [
  70. {
  71. Hosts: {
  72. host_name: 'wst3_host3'
  73. }
  74. },
  75. {
  76. Hosts: {
  77. host_name: 'wst3_host4'
  78. }
  79. }
  80. ]
  81. };
  82. controller.getAllRegisteredHostsCallback(test_data);
  83. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  84. expect(controller.get('registeredHosts')).to.equal('');
  85. });
  86. it('No new hosts', function() {
  87. var controller = App.WizardStep3Controller.create({
  88. hostsInCluster: [{
  89. hostName: 'wst3_host1'
  90. }],
  91. bootHosts: [
  92. {name:'wst3_host1'}
  93. ]
  94. });
  95. var test_data = {
  96. items: [
  97. {
  98. Hosts: {
  99. host_name: 'wst3_host1'
  100. }
  101. }
  102. ]
  103. };
  104. controller.getAllRegisteredHostsCallback(test_data);
  105. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  106. expect(controller.get('registeredHosts')).to.equal('');
  107. });
  108. });
  109. var tests = [
  110. {
  111. bootHosts: [
  112. Em.Object.create({name:'wst3_host1', bootStatus: 'REGISTERED', isChecked: false}),
  113. Em.Object.create({name:'wst3_host2', bootStatus: 'REGISTERING', isChecked: false})
  114. ],
  115. m: 'One registered, one registering',
  116. visibleHosts: {
  117. RUNNING: {
  118. e: 0
  119. },
  120. REGISTERING: {
  121. e: 1
  122. },
  123. REGISTERED: {
  124. e: 1
  125. },
  126. FAILED: {
  127. e: 0
  128. }
  129. },
  130. onAllChecked: {
  131. e: [true, true]
  132. }
  133. },
  134. {
  135. bootHosts: [
  136. Em.Object.create({name:'wst3_host1', bootStatus: 'REGISTERED', isChecked: false}),
  137. Em.Object.create({name:'wst3_host2', bootStatus: 'REGISTERED', isChecked: false})
  138. ],
  139. m: 'Two registered',
  140. visibleHosts: {
  141. RUNNING: {
  142. e: 0
  143. },
  144. REGISTERING: {
  145. e: 0
  146. },
  147. REGISTERED: {
  148. e: 2
  149. },
  150. FAILED: {
  151. e: 0
  152. }
  153. },
  154. onAllChecked: {
  155. e: [true, true]
  156. }
  157. },
  158. {
  159. bootHosts: [
  160. Em.Object.create({name:'wst3_host1', bootStatus: 'FAILED', isChecked: false}),
  161. Em.Object.create({name:'wst3_host2', bootStatus: 'REGISTERED', isChecked: false})
  162. ],
  163. m: 'One registered, one failed',
  164. visibleHosts: {
  165. RUNNING: {
  166. e: 0
  167. },
  168. REGISTERING: {
  169. e: 0
  170. },
  171. REGISTERED: {
  172. e: 1
  173. },
  174. FAILED: {
  175. e: 1
  176. }
  177. },
  178. onAllChecked: {
  179. e: [true, true]
  180. }
  181. },
  182. {
  183. bootHosts: [
  184. Em.Object.create({name:'wst3_host1', bootStatus: 'FAILED', isChecked: false}),
  185. Em.Object.create({name:'wst3_host2', bootStatus: 'FAILED', isChecked: false})
  186. ],
  187. m: 'Two failed',
  188. visibleHosts: {
  189. RUNNING: {
  190. e: 0
  191. },
  192. REGISTERING: {
  193. e: 0
  194. },
  195. REGISTERED: {
  196. e: 0
  197. },
  198. FAILED: {
  199. e: 2
  200. }
  201. },
  202. onAllChecked: {
  203. e: [true, true]
  204. }
  205. },
  206. {
  207. bootHosts: [
  208. Em.Object.create({name:'wst3_host1', bootStatus: 'REGISTERING', isChecked: false}),
  209. Em.Object.create({name:'wst3_host2', bootStatus: 'REGISTERING', isChecked: false})
  210. ],
  211. m: 'Two registering',
  212. visibleHosts: {
  213. RUNNING: {
  214. e: 0
  215. },
  216. REGISTERING: {
  217. e: 2
  218. },
  219. REGISTERED: {
  220. e: 0
  221. },
  222. FAILED: {
  223. e: 0
  224. }
  225. },
  226. onAllChecked: {
  227. e: [true, true]
  228. }
  229. }
  230. ];
  231. describe('#registrationTimeoutSecs', function() {
  232. it('Manual install', function() {
  233. var controller = App.WizardStep3Controller.create({
  234. content: {
  235. installOptions: {
  236. manualInstall: true
  237. }
  238. }
  239. });
  240. expect(controller.get('registrationTimeoutSecs')).to.equal(15);
  241. });
  242. it('Not manual install', function() {
  243. var controller = App.WizardStep3Controller.create({
  244. content: {
  245. installOptions: {
  246. manualInstall: false
  247. }
  248. }
  249. });
  250. expect(controller.get('registrationTimeoutSecs')).to.equal(120);
  251. });
  252. });
  253. describe('#isHostHaveWarnings', function() {
  254. var tests = [
  255. {
  256. warnings: [{},{}],
  257. m: 'Warnings exist',
  258. e: true
  259. },
  260. {
  261. warnings: [],
  262. m: 'Warnings don\'t exist',
  263. e: false
  264. }
  265. ];
  266. tests.forEach(function(test) {
  267. var controller = App.WizardStep3Controller.create();
  268. controller.set('warnings', test.warnings);
  269. it(test.m, function() {
  270. expect(controller.get('isHostHaveWarnings')).to.equal(test.e);
  271. });
  272. });
  273. });
  274. describe('#noHostsSelected', function() {
  275. tests.forEach(function(test) {
  276. it(test.m + ' - nothing checked', function() {
  277. var controller = App.WizardStep3Controller.create({
  278. hosts: test.bootHosts
  279. });
  280. controller.get('hosts').setEach('isChecked', false);
  281. console.log(controller.hosts);
  282. expect(controller.get('noHostsSelected')).to.equal(true);
  283. });
  284. it(test.m + ' - one checked', function() {
  285. var controller = App.WizardStep3Controller.create({
  286. hosts: test.bootHosts
  287. });
  288. controller.get('hosts').setEach('isChecked', true);
  289. expect(controller.get('noHostsSelected')).to.equal(false);
  290. });
  291. });
  292. });
  293. });