Merge lp:~gnuoy/charm-helpers/more-openstack-tests into lp:charm-helpers
- more-openstack-tests
- Merge into devel
Proposed by
Liam Young
Status: | Merged |
---|---|
Merged at revision: | 137 |
Proposed branch: | lp:~gnuoy/charm-helpers/more-openstack-tests |
Merge into: | lp:charm-helpers |
Diff against target: |
328 lines (+271/-0) 2 files modified
tests/contrib/openstack/test_neutron_utils.py (+160/-0) tests/contrib/openstack/test_os_contexts.py (+111/-0) |
To merge this branch: | bzr merge lp:~gnuoy/charm-helpers/more-openstack-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
charmers | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
- 138. By Liam Young
-
Add network_manager test case for havana and minor tidy up
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'tests/contrib/openstack/test_neutron_utils.py' | |||
2 | --- tests/contrib/openstack/test_neutron_utils.py 1970-01-01 00:00:00 +0000 | |||
3 | +++ tests/contrib/openstack/test_neutron_utils.py 2014-04-07 08:52:22 +0000 | |||
4 | @@ -0,0 +1,160 @@ | |||
5 | 1 | import unittest | ||
6 | 2 | from mock import patch | ||
7 | 3 | from nose.tools import raises | ||
8 | 4 | import charmhelpers.contrib.openstack.neutron as neutron | ||
9 | 5 | |||
10 | 6 | TO_PATCH = [ | ||
11 | 7 | 'log', | ||
12 | 8 | 'config', | ||
13 | 9 | 'os_release', | ||
14 | 10 | 'check_output', | ||
15 | 11 | ] | ||
16 | 12 | |||
17 | 13 | |||
18 | 14 | class NeutronTests(unittest.TestCase): | ||
19 | 15 | def setUp(self): | ||
20 | 16 | for m in TO_PATCH: | ||
21 | 17 | setattr(self, m, self._patch(m)) | ||
22 | 18 | |||
23 | 19 | def _patch(self, method): | ||
24 | 20 | _m = patch('charmhelpers.contrib.openstack.neutron.' + method) | ||
25 | 21 | mock = _m.start() | ||
26 | 22 | self.addCleanup(_m.stop) | ||
27 | 23 | return mock | ||
28 | 24 | |||
29 | 25 | def test_headers_package(self): | ||
30 | 26 | self.check_output.return_value = '3.13.0-19-generic' | ||
31 | 27 | kname = neutron.headers_package() | ||
32 | 28 | self.assertEquals(kname, 'linux-headers-3.13.0-19-generic') | ||
33 | 29 | |||
34 | 30 | def test_kernel_version(self): | ||
35 | 31 | self.check_output.return_value = '3.13.0-19-generic' | ||
36 | 32 | kver_maj, kver_min = neutron.kernel_version() | ||
37 | 33 | self.assertEquals((kver_maj, kver_min), (3, 13)) | ||
38 | 34 | |||
39 | 35 | @patch.object(neutron, 'kernel_version') | ||
40 | 36 | def test_determine_dkms_package_old_kernel(self, _kernel_version): | ||
41 | 37 | _kernel_version.return_value = (3, 10) | ||
42 | 38 | dkms_package = neutron.determine_dkms_package() | ||
43 | 39 | self.assertEquals(dkms_package, ['openvswitch-datapath-dkms']) | ||
44 | 40 | |||
45 | 41 | @patch.object(neutron, 'kernel_version') | ||
46 | 42 | def test_determine_dkms_package_new_kernel(self, _kernel_version): | ||
47 | 43 | _kernel_version.return_value = (3, 13) | ||
48 | 44 | dkms_package = neutron.determine_dkms_package() | ||
49 | 45 | self.assertEquals(dkms_package, []) | ||
50 | 46 | |||
51 | 47 | def test_quantum_plugins(self): | ||
52 | 48 | self.config.return_value = 'foo' | ||
53 | 49 | plugins = neutron.quantum_plugins() | ||
54 | 50 | self.assertEquals(plugins['ovs']['services'], ['quantum-plugin-openvswitch-agent']) | ||
55 | 51 | self.assertEquals(plugins['nvp']['services'], []) | ||
56 | 52 | |||
57 | 53 | def test_neutron_plugins_preicehouse(self): | ||
58 | 54 | self.config.return_value = 'foo' | ||
59 | 55 | self.os_release .return_value = 'havana' | ||
60 | 56 | plugins = neutron.neutron_plugins() | ||
61 | 57 | self.assertEquals(plugins['ovs']['config'], '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini') | ||
62 | 58 | self.assertEquals(plugins['nvp']['services'], []) | ||
63 | 59 | |||
64 | 60 | def test_neutron_plugins(self): | ||
65 | 61 | self.config.return_value = 'foo' | ||
66 | 62 | self.os_release .return_value = 'icehouse' | ||
67 | 63 | plugins = neutron.neutron_plugins() | ||
68 | 64 | self.assertEquals(plugins['ovs']['config'], '/etc/neutron/plugins/ml2/ml2_conf.ini') | ||
69 | 65 | self.assertEquals(plugins['nvp']['services'], []) | ||
70 | 66 | |||
71 | 67 | @patch.object(neutron, 'network_manager') | ||
72 | 68 | def test_neutron_plugin_attribute_quantum(self, _network_manager): | ||
73 | 69 | self.config.return_value = 'foo' | ||
74 | 70 | _network_manager.return_value = 'quantum' | ||
75 | 71 | plugins = neutron.neutron_plugin_attribute('ovs', 'services') | ||
76 | 72 | self.assertEquals(plugins, ['quantum-plugin-openvswitch-agent']) | ||
77 | 73 | |||
78 | 74 | @patch.object(neutron, 'network_manager') | ||
79 | 75 | def test_neutron_plugin_attribute_neutron(self, _network_manager): | ||
80 | 76 | self.config.return_value = 'foo' | ||
81 | 77 | self.os_release .return_value = 'icehouse' | ||
82 | 78 | _network_manager.return_value = 'neutron' | ||
83 | 79 | plugins = neutron.neutron_plugin_attribute('ovs', 'services') | ||
84 | 80 | self.assertEquals(plugins, ['neutron-plugin-openvswitch-agent']) | ||
85 | 81 | |||
86 | 82 | @raises(Exception) | ||
87 | 83 | @patch.object(neutron, 'network_manager') | ||
88 | 84 | def test_neutron_plugin_attribute_foo(self, _network_manager): | ||
89 | 85 | _network_manager.return_value = 'foo' | ||
90 | 86 | self.assertRaises(Exception, neutron.neutron_plugin_attribute('ovs', 'services')) | ||
91 | 87 | |||
92 | 88 | @raises(Exception) | ||
93 | 89 | @patch.object(neutron, 'network_manager') | ||
94 | 90 | def test_neutron_plugin_attribute_plugin_keyerror(self, _network_manager): | ||
95 | 91 | self.config.return_value = 'foo' | ||
96 | 92 | _network_manager.return_value = 'quantum' | ||
97 | 93 | self.assertRaises(Exception, neutron.neutron_plugin_attribute('foo', 'foo')) | ||
98 | 94 | |||
99 | 95 | @patch.object(neutron, 'network_manager') | ||
100 | 96 | def test_neutron_plugin_attribute_attr_keyerror(self, _network_manager): | ||
101 | 97 | self.config.return_value = 'foo' | ||
102 | 98 | _network_manager.return_value = 'quantum' | ||
103 | 99 | plugins = neutron.neutron_plugin_attribute('ovs', 'foo') | ||
104 | 100 | self.assertEquals(plugins, None) | ||
105 | 101 | |||
106 | 102 | @raises(Exception) | ||
107 | 103 | def test_network_manager_essex(self): | ||
108 | 104 | essex_cases = { | ||
109 | 105 | 'quantum': 'quantum', | ||
110 | 106 | 'neutron': 'quantum', | ||
111 | 107 | 'newhotness': 'newhotness', | ||
112 | 108 | } | ||
113 | 109 | self.os_release.return_value = 'essex' | ||
114 | 110 | for nwmanager in essex_cases: | ||
115 | 111 | self.config.return_value = nwmanager | ||
116 | 112 | self.assertRaises(Exception, neutron.network_manager()) | ||
117 | 113 | |||
118 | 114 | def test_network_manager_folsom(self): | ||
119 | 115 | folsom_cases = { | ||
120 | 116 | 'quantum': 'quantum', | ||
121 | 117 | 'neutron': 'quantum', | ||
122 | 118 | 'newhotness': 'newhotness', | ||
123 | 119 | } | ||
124 | 120 | self.os_release.return_value = 'folsom' | ||
125 | 121 | for nwmanager in folsom_cases: | ||
126 | 122 | self.config.return_value = nwmanager | ||
127 | 123 | renamed_manager = neutron.network_manager() | ||
128 | 124 | self.assertEquals(renamed_manager, folsom_cases[nwmanager]) | ||
129 | 125 | |||
130 | 126 | def test_network_manager_grizzly(self): | ||
131 | 127 | grizzly_cases = { | ||
132 | 128 | 'quantum': 'quantum', | ||
133 | 129 | 'neutron': 'quantum', | ||
134 | 130 | 'newhotness': 'newhotness', | ||
135 | 131 | } | ||
136 | 132 | self.os_release.return_value = 'grizzly' | ||
137 | 133 | for nwmanager in grizzly_cases: | ||
138 | 134 | self.config.return_value = nwmanager | ||
139 | 135 | renamed_manager = neutron.network_manager() | ||
140 | 136 | self.assertEquals(renamed_manager, grizzly_cases[nwmanager]) | ||
141 | 137 | |||
142 | 138 | def test_network_manager_havana(self): | ||
143 | 139 | havana_cases = { | ||
144 | 140 | 'quantum': 'neutron', | ||
145 | 141 | 'neutron': 'neutron', | ||
146 | 142 | 'newhotness': 'newhotness', | ||
147 | 143 | } | ||
148 | 144 | self.os_release.return_value = 'havana' | ||
149 | 145 | for nwmanager in havana_cases: | ||
150 | 146 | self.config.return_value = nwmanager | ||
151 | 147 | renamed_manager = neutron.network_manager() | ||
152 | 148 | self.assertEquals(renamed_manager, havana_cases[nwmanager]) | ||
153 | 149 | |||
154 | 150 | def test_network_manager_icehouse(self): | ||
155 | 151 | icehouse_cases = { | ||
156 | 152 | 'quantum': 'neutron', | ||
157 | 153 | 'neutron': 'neutron', | ||
158 | 154 | 'newhotness': 'newhotness', | ||
159 | 155 | } | ||
160 | 156 | self.os_release.return_value = 'icehouse' | ||
161 | 157 | for nwmanager in icehouse_cases: | ||
162 | 158 | self.config.return_value = nwmanager | ||
163 | 159 | renamed_manager = neutron.network_manager() | ||
164 | 160 | self.assertEquals(renamed_manager, icehouse_cases[nwmanager]) | ||
165 | 0 | 161 | ||
166 | === modified file 'tests/contrib/openstack/test_os_contexts.py' | |||
167 | --- tests/contrib/openstack/test_os_contexts.py 2014-04-02 11:35:51 +0000 | |||
168 | +++ tests/contrib/openstack/test_os_contexts.py 2014-04-07 08:52:22 +0000 | |||
169 | @@ -74,6 +74,14 @@ | |||
170 | 74 | 'password': 'foo', | 74 | 'password': 'foo', |
171 | 75 | } | 75 | } |
172 | 76 | 76 | ||
173 | 77 | SHARED_DB_RELATION_SSL = { | ||
174 | 78 | 'db_host': 'dbserver.local', | ||
175 | 79 | 'password': 'foo', | ||
176 | 80 | 'ssl_ca': 'Zm9vCg==', | ||
177 | 81 | 'ssl_cert': 'YmFyCg==', | ||
178 | 82 | 'ssl_key': 'Zm9vYmFyCg==', | ||
179 | 83 | } | ||
180 | 84 | |||
181 | 77 | SHARED_DB_CONFIG = { | 85 | SHARED_DB_CONFIG = { |
182 | 78 | 'database-user': 'adam', | 86 | 'database-user': 'adam', |
183 | 79 | 'database': 'foodb', | 87 | 'database': 'foodb', |
184 | @@ -140,6 +148,15 @@ | |||
185 | 140 | 'vip': '10.0.0.1', | 148 | 'vip': '10.0.0.1', |
186 | 141 | } | 149 | } |
187 | 142 | 150 | ||
188 | 151 | AMQP_RELATION_WITH_SSL = { | ||
189 | 152 | 'private-address': 'rabbithost', | ||
190 | 153 | 'password': 'foobar', | ||
191 | 154 | 'vip': '10.0.0.1', | ||
192 | 155 | 'ssl_port': 5671, | ||
193 | 156 | 'ssl_ca': 'cert', | ||
194 | 157 | 'ha_queues': 'queues', | ||
195 | 158 | } | ||
196 | 159 | |||
197 | 143 | AMQP_AA_RELATION = { | 160 | AMQP_AA_RELATION = { |
198 | 144 | 'amqp:0': { | 161 | 'amqp:0': { |
199 | 145 | 'rabbitmq/0': { | 162 | 'rabbitmq/0': { |
200 | @@ -227,6 +244,7 @@ | |||
201 | 227 | 'determine_apache_port', | 244 | 'determine_apache_port', |
202 | 228 | 'config', | 245 | 'config', |
203 | 229 | 'is_clustered', | 246 | 'is_clustered', |
204 | 247 | 'time', | ||
205 | 230 | ] | 248 | ] |
206 | 231 | 249 | ||
207 | 232 | 250 | ||
208 | @@ -274,6 +292,36 @@ | |||
209 | 274 | } | 292 | } |
210 | 275 | self.assertEquals(result, expected) | 293 | self.assertEquals(result, expected) |
211 | 276 | 294 | ||
212 | 295 | @patch('os.path.exists') | ||
213 | 296 | @patch('__builtin__.open') | ||
214 | 297 | def test_db_ssl(self, _open, osexists): | ||
215 | 298 | osexists.return_value = False | ||
216 | 299 | ssl_dir = '/etc/dbssl' | ||
217 | 300 | db_ssl_ctxt = context.db_ssl(SHARED_DB_RELATION_SSL, {}, ssl_dir) | ||
218 | 301 | expected = { | ||
219 | 302 | 'database_ssl_ca': ssl_dir + '/db-client.ca', | ||
220 | 303 | 'database_ssl_cert': ssl_dir + '/db-client.cert', | ||
221 | 304 | 'database_ssl_key': ssl_dir + '/db-client.key', | ||
222 | 305 | } | ||
223 | 306 | files = [ | ||
224 | 307 | call(expected['database_ssl_ca'], 'w'), | ||
225 | 308 | call(expected['database_ssl_cert'], 'w'), | ||
226 | 309 | call(expected['database_ssl_key'], 'w') | ||
227 | 310 | ] | ||
228 | 311 | for f in files: | ||
229 | 312 | self.assertIn(f, _open.call_args_list) | ||
230 | 313 | self.assertEquals(db_ssl_ctxt, expected) | ||
231 | 314 | decode = [ | ||
232 | 315 | call(SHARED_DB_RELATION_SSL['ssl_ca']), | ||
233 | 316 | call(SHARED_DB_RELATION_SSL['ssl_cert']), | ||
234 | 317 | call(SHARED_DB_RELATION_SSL['ssl_key']) | ||
235 | 318 | ] | ||
236 | 319 | self.assertEquals(decode, self.b64decode.call_args_list) | ||
237 | 320 | |||
238 | 321 | def test_db_ssl_nossldir(self): | ||
239 | 322 | db_ssl_ctxt = context.db_ssl(SHARED_DB_RELATION_SSL, {}, None) | ||
240 | 323 | self.assertEquals(db_ssl_ctxt, {}) | ||
241 | 324 | |||
242 | 277 | def test_shared_db_context_with_missing_relation(self): | 325 | def test_shared_db_context_with_missing_relation(self): |
243 | 278 | '''Test shared-db context missing relation data''' | 326 | '''Test shared-db context missing relation data''' |
244 | 279 | incomplete_relation = copy(SHARED_DB_RELATION) | 327 | incomplete_relation = copy(SHARED_DB_RELATION) |
245 | @@ -442,6 +490,46 @@ | |||
246 | 442 | } | 490 | } |
247 | 443 | self.assertEquals(result, expected) | 491 | self.assertEquals(result, expected) |
248 | 444 | 492 | ||
249 | 493 | @patch('__builtin__.open') | ||
250 | 494 | def test_amqp_context_with_data_ssl(self, _open): | ||
251 | 495 | '''Test amqp context with all required data and ssl''' | ||
252 | 496 | relation = FakeRelation(relation_data=AMQP_RELATION_WITH_SSL) | ||
253 | 497 | self.relation_get.side_effect = relation.get | ||
254 | 498 | self.config.return_value = AMQP_CONFIG | ||
255 | 499 | ssl_dir = '/etc/sslamqp' | ||
256 | 500 | amqp = context.AMQPContext(ssl_dir=ssl_dir) | ||
257 | 501 | result = amqp() | ||
258 | 502 | expected = { | ||
259 | 503 | 'rabbitmq_host': 'rabbithost', | ||
260 | 504 | 'rabbitmq_password': 'foobar', | ||
261 | 505 | 'rabbitmq_user': 'adam', | ||
262 | 506 | 'rabbit_ssl_port': 5671, | ||
263 | 507 | 'rabbitmq_virtual_host': 'foo', | ||
264 | 508 | 'rabbit_ssl_ca': ssl_dir + '/rabbit-client-ca.pem', | ||
265 | 509 | 'rabbitmq_ha_queues': True, | ||
266 | 510 | } | ||
267 | 511 | _open.assert_called_once_with(ssl_dir + '/rabbit-client-ca.pem', 'w') | ||
268 | 512 | self.assertEquals(result, expected) | ||
269 | 513 | self.assertEquals([call(AMQP_RELATION_WITH_SSL['ssl_ca'])], self.b64decode.call_args_list) | ||
270 | 514 | |||
271 | 515 | def test_amqp_context_with_data_ssl_noca(self): | ||
272 | 516 | '''Test amqp context with all required data with ssl but missing ca''' | ||
273 | 517 | relation = FakeRelation(relation_data=AMQP_RELATION_WITH_SSL) | ||
274 | 518 | self.relation_get.side_effect = relation.get | ||
275 | 519 | self.config.return_value = AMQP_CONFIG | ||
276 | 520 | amqp = context.AMQPContext() | ||
277 | 521 | result = amqp() | ||
278 | 522 | expected = { | ||
279 | 523 | 'rabbitmq_host': 'rabbithost', | ||
280 | 524 | 'rabbitmq_password': 'foobar', | ||
281 | 525 | 'rabbitmq_user': 'adam', | ||
282 | 526 | 'rabbit_ssl_port': 5671, | ||
283 | 527 | 'rabbitmq_virtual_host': 'foo', | ||
284 | 528 | 'rabbit_ssl_ca': 'cert', | ||
285 | 529 | 'rabbitmq_ha_queues': True, | ||
286 | 530 | } | ||
287 | 531 | self.assertEquals(result, expected) | ||
288 | 532 | |||
289 | 445 | def test_amqp_context_with_data_clustered(self): | 533 | def test_amqp_context_with_data_clustered(self): |
290 | 446 | '''Test amqp context with all required data with clustered rabbit''' | 534 | '''Test amqp context with all required data with clustered rabbit''' |
291 | 447 | relation_data = copy(AMQP_RELATION) | 535 | relation_data = copy(AMQP_RELATION) |
292 | @@ -500,6 +588,14 @@ | |||
293 | 500 | amqp = context.AMQPContext() | 588 | amqp = context.AMQPContext() |
294 | 501 | self.assertRaises(context.OSContextError, amqp) | 589 | self.assertRaises(context.OSContextError, amqp) |
295 | 502 | 590 | ||
296 | 591 | def test_ceph_no_relids(self): | ||
297 | 592 | '''Test empty ceph realtion''' | ||
298 | 593 | relation = FakeRelation(relation_data={}) | ||
299 | 594 | self.relation_ids.side_effect = relation.get | ||
300 | 595 | ceph = context.CephContext() | ||
301 | 596 | result = ceph() | ||
302 | 597 | self.assertEquals(result, {}) | ||
303 | 598 | |||
304 | 503 | @patch.object(context, 'config') | 599 | @patch.object(context, 'config') |
305 | 504 | @patch('os.path.isdir') | 600 | @patch('os.path.isdir') |
306 | 505 | @patch('os.mkdir') | 601 | @patch('os.mkdir') |
307 | @@ -753,6 +849,21 @@ | |||
308 | 753 | 'neutron_security_groups': True, | 849 | 'neutron_security_groups': True, |
309 | 754 | 'local_ip': '10.0.0.1'}, neutron.ovs_ctxt()) | 850 | 'local_ip': '10.0.0.1'}, neutron.ovs_ctxt()) |
310 | 755 | 851 | ||
311 | 852 | @patch.object(context.NeutronContext, 'neutron_security_groups') | ||
312 | 853 | @patch.object(context, 'unit_private_ip') | ||
313 | 854 | @patch.object(context, 'neutron_plugin_attribute') | ||
314 | 855 | def test_neutron_nvp_plugin_context(self, attr, ip, sec_groups): | ||
315 | 856 | ip.return_value = '10.0.0.1' | ||
316 | 857 | sec_groups.__get__ = MagicMock(return_value=True) | ||
317 | 858 | attr.return_value = 'some.quantum.driver.class' | ||
318 | 859 | neutron = context.NeutronContext() | ||
319 | 860 | self.assertEquals({ | ||
320 | 861 | 'config': 'some.quantum.driver.class', | ||
321 | 862 | 'core_plugin': 'some.quantum.driver.class', | ||
322 | 863 | 'neutron_plugin': 'nvp', | ||
323 | 864 | 'neutron_security_groups': True, | ||
324 | 865 | 'local_ip': '10.0.0.1'}, neutron.nvp_ctxt()) | ||
325 | 866 | |||
326 | 756 | @patch('charmhelpers.contrib.openstack.context.unit_get') | 867 | @patch('charmhelpers.contrib.openstack.context.unit_get') |
327 | 757 | @patch.object(context.NeutronContext, 'network_manager') | 868 | @patch.object(context.NeutronContext, 'network_manager') |
328 | 758 | def test_neutron_neutron_ctxt(self, mock_network_manager, | 869 | def test_neutron_neutron_ctxt(self, mock_network_manager, |