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 | +import unittest |
6 | +from mock import patch |
7 | +from nose.tools import raises |
8 | +import charmhelpers.contrib.openstack.neutron as neutron |
9 | + |
10 | +TO_PATCH = [ |
11 | + 'log', |
12 | + 'config', |
13 | + 'os_release', |
14 | + 'check_output', |
15 | +] |
16 | + |
17 | + |
18 | +class NeutronTests(unittest.TestCase): |
19 | + def setUp(self): |
20 | + for m in TO_PATCH: |
21 | + setattr(self, m, self._patch(m)) |
22 | + |
23 | + def _patch(self, method): |
24 | + _m = patch('charmhelpers.contrib.openstack.neutron.' + method) |
25 | + mock = _m.start() |
26 | + self.addCleanup(_m.stop) |
27 | + return mock |
28 | + |
29 | + def test_headers_package(self): |
30 | + self.check_output.return_value = '3.13.0-19-generic' |
31 | + kname = neutron.headers_package() |
32 | + self.assertEquals(kname, 'linux-headers-3.13.0-19-generic') |
33 | + |
34 | + def test_kernel_version(self): |
35 | + self.check_output.return_value = '3.13.0-19-generic' |
36 | + kver_maj, kver_min = neutron.kernel_version() |
37 | + self.assertEquals((kver_maj, kver_min), (3, 13)) |
38 | + |
39 | + @patch.object(neutron, 'kernel_version') |
40 | + def test_determine_dkms_package_old_kernel(self, _kernel_version): |
41 | + _kernel_version.return_value = (3, 10) |
42 | + dkms_package = neutron.determine_dkms_package() |
43 | + self.assertEquals(dkms_package, ['openvswitch-datapath-dkms']) |
44 | + |
45 | + @patch.object(neutron, 'kernel_version') |
46 | + def test_determine_dkms_package_new_kernel(self, _kernel_version): |
47 | + _kernel_version.return_value = (3, 13) |
48 | + dkms_package = neutron.determine_dkms_package() |
49 | + self.assertEquals(dkms_package, []) |
50 | + |
51 | + def test_quantum_plugins(self): |
52 | + self.config.return_value = 'foo' |
53 | + plugins = neutron.quantum_plugins() |
54 | + self.assertEquals(plugins['ovs']['services'], ['quantum-plugin-openvswitch-agent']) |
55 | + self.assertEquals(plugins['nvp']['services'], []) |
56 | + |
57 | + def test_neutron_plugins_preicehouse(self): |
58 | + self.config.return_value = 'foo' |
59 | + self.os_release .return_value = 'havana' |
60 | + plugins = neutron.neutron_plugins() |
61 | + self.assertEquals(plugins['ovs']['config'], '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini') |
62 | + self.assertEquals(plugins['nvp']['services'], []) |
63 | + |
64 | + def test_neutron_plugins(self): |
65 | + self.config.return_value = 'foo' |
66 | + self.os_release .return_value = 'icehouse' |
67 | + plugins = neutron.neutron_plugins() |
68 | + self.assertEquals(plugins['ovs']['config'], '/etc/neutron/plugins/ml2/ml2_conf.ini') |
69 | + self.assertEquals(plugins['nvp']['services'], []) |
70 | + |
71 | + @patch.object(neutron, 'network_manager') |
72 | + def test_neutron_plugin_attribute_quantum(self, _network_manager): |
73 | + self.config.return_value = 'foo' |
74 | + _network_manager.return_value = 'quantum' |
75 | + plugins = neutron.neutron_plugin_attribute('ovs', 'services') |
76 | + self.assertEquals(plugins, ['quantum-plugin-openvswitch-agent']) |
77 | + |
78 | + @patch.object(neutron, 'network_manager') |
79 | + def test_neutron_plugin_attribute_neutron(self, _network_manager): |
80 | + self.config.return_value = 'foo' |
81 | + self.os_release .return_value = 'icehouse' |
82 | + _network_manager.return_value = 'neutron' |
83 | + plugins = neutron.neutron_plugin_attribute('ovs', 'services') |
84 | + self.assertEquals(plugins, ['neutron-plugin-openvswitch-agent']) |
85 | + |
86 | + @raises(Exception) |
87 | + @patch.object(neutron, 'network_manager') |
88 | + def test_neutron_plugin_attribute_foo(self, _network_manager): |
89 | + _network_manager.return_value = 'foo' |
90 | + self.assertRaises(Exception, neutron.neutron_plugin_attribute('ovs', 'services')) |
91 | + |
92 | + @raises(Exception) |
93 | + @patch.object(neutron, 'network_manager') |
94 | + def test_neutron_plugin_attribute_plugin_keyerror(self, _network_manager): |
95 | + self.config.return_value = 'foo' |
96 | + _network_manager.return_value = 'quantum' |
97 | + self.assertRaises(Exception, neutron.neutron_plugin_attribute('foo', 'foo')) |
98 | + |
99 | + @patch.object(neutron, 'network_manager') |
100 | + def test_neutron_plugin_attribute_attr_keyerror(self, _network_manager): |
101 | + self.config.return_value = 'foo' |
102 | + _network_manager.return_value = 'quantum' |
103 | + plugins = neutron.neutron_plugin_attribute('ovs', 'foo') |
104 | + self.assertEquals(plugins, None) |
105 | + |
106 | + @raises(Exception) |
107 | + def test_network_manager_essex(self): |
108 | + essex_cases = { |
109 | + 'quantum': 'quantum', |
110 | + 'neutron': 'quantum', |
111 | + 'newhotness': 'newhotness', |
112 | + } |
113 | + self.os_release.return_value = 'essex' |
114 | + for nwmanager in essex_cases: |
115 | + self.config.return_value = nwmanager |
116 | + self.assertRaises(Exception, neutron.network_manager()) |
117 | + |
118 | + def test_network_manager_folsom(self): |
119 | + folsom_cases = { |
120 | + 'quantum': 'quantum', |
121 | + 'neutron': 'quantum', |
122 | + 'newhotness': 'newhotness', |
123 | + } |
124 | + self.os_release.return_value = 'folsom' |
125 | + for nwmanager in folsom_cases: |
126 | + self.config.return_value = nwmanager |
127 | + renamed_manager = neutron.network_manager() |
128 | + self.assertEquals(renamed_manager, folsom_cases[nwmanager]) |
129 | + |
130 | + def test_network_manager_grizzly(self): |
131 | + grizzly_cases = { |
132 | + 'quantum': 'quantum', |
133 | + 'neutron': 'quantum', |
134 | + 'newhotness': 'newhotness', |
135 | + } |
136 | + self.os_release.return_value = 'grizzly' |
137 | + for nwmanager in grizzly_cases: |
138 | + self.config.return_value = nwmanager |
139 | + renamed_manager = neutron.network_manager() |
140 | + self.assertEquals(renamed_manager, grizzly_cases[nwmanager]) |
141 | + |
142 | + def test_network_manager_havana(self): |
143 | + havana_cases = { |
144 | + 'quantum': 'neutron', |
145 | + 'neutron': 'neutron', |
146 | + 'newhotness': 'newhotness', |
147 | + } |
148 | + self.os_release.return_value = 'havana' |
149 | + for nwmanager in havana_cases: |
150 | + self.config.return_value = nwmanager |
151 | + renamed_manager = neutron.network_manager() |
152 | + self.assertEquals(renamed_manager, havana_cases[nwmanager]) |
153 | + |
154 | + def test_network_manager_icehouse(self): |
155 | + icehouse_cases = { |
156 | + 'quantum': 'neutron', |
157 | + 'neutron': 'neutron', |
158 | + 'newhotness': 'newhotness', |
159 | + } |
160 | + self.os_release.return_value = 'icehouse' |
161 | + for nwmanager in icehouse_cases: |
162 | + self.config.return_value = nwmanager |
163 | + renamed_manager = neutron.network_manager() |
164 | + self.assertEquals(renamed_manager, icehouse_cases[nwmanager]) |
165 | |
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 | 'password': 'foo', |
171 | } |
172 | |
173 | +SHARED_DB_RELATION_SSL = { |
174 | + 'db_host': 'dbserver.local', |
175 | + 'password': 'foo', |
176 | + 'ssl_ca': 'Zm9vCg==', |
177 | + 'ssl_cert': 'YmFyCg==', |
178 | + 'ssl_key': 'Zm9vYmFyCg==', |
179 | +} |
180 | + |
181 | SHARED_DB_CONFIG = { |
182 | 'database-user': 'adam', |
183 | 'database': 'foodb', |
184 | @@ -140,6 +148,15 @@ |
185 | 'vip': '10.0.0.1', |
186 | } |
187 | |
188 | +AMQP_RELATION_WITH_SSL = { |
189 | + 'private-address': 'rabbithost', |
190 | + 'password': 'foobar', |
191 | + 'vip': '10.0.0.1', |
192 | + 'ssl_port': 5671, |
193 | + 'ssl_ca': 'cert', |
194 | + 'ha_queues': 'queues', |
195 | +} |
196 | + |
197 | AMQP_AA_RELATION = { |
198 | 'amqp:0': { |
199 | 'rabbitmq/0': { |
200 | @@ -227,6 +244,7 @@ |
201 | 'determine_apache_port', |
202 | 'config', |
203 | 'is_clustered', |
204 | + 'time', |
205 | ] |
206 | |
207 | |
208 | @@ -274,6 +292,36 @@ |
209 | } |
210 | self.assertEquals(result, expected) |
211 | |
212 | + @patch('os.path.exists') |
213 | + @patch('__builtin__.open') |
214 | + def test_db_ssl(self, _open, osexists): |
215 | + osexists.return_value = False |
216 | + ssl_dir = '/etc/dbssl' |
217 | + db_ssl_ctxt = context.db_ssl(SHARED_DB_RELATION_SSL, {}, ssl_dir) |
218 | + expected = { |
219 | + 'database_ssl_ca': ssl_dir + '/db-client.ca', |
220 | + 'database_ssl_cert': ssl_dir + '/db-client.cert', |
221 | + 'database_ssl_key': ssl_dir + '/db-client.key', |
222 | + } |
223 | + files = [ |
224 | + call(expected['database_ssl_ca'], 'w'), |
225 | + call(expected['database_ssl_cert'], 'w'), |
226 | + call(expected['database_ssl_key'], 'w') |
227 | + ] |
228 | + for f in files: |
229 | + self.assertIn(f, _open.call_args_list) |
230 | + self.assertEquals(db_ssl_ctxt, expected) |
231 | + decode = [ |
232 | + call(SHARED_DB_RELATION_SSL['ssl_ca']), |
233 | + call(SHARED_DB_RELATION_SSL['ssl_cert']), |
234 | + call(SHARED_DB_RELATION_SSL['ssl_key']) |
235 | + ] |
236 | + self.assertEquals(decode, self.b64decode.call_args_list) |
237 | + |
238 | + def test_db_ssl_nossldir(self): |
239 | + db_ssl_ctxt = context.db_ssl(SHARED_DB_RELATION_SSL, {}, None) |
240 | + self.assertEquals(db_ssl_ctxt, {}) |
241 | + |
242 | def test_shared_db_context_with_missing_relation(self): |
243 | '''Test shared-db context missing relation data''' |
244 | incomplete_relation = copy(SHARED_DB_RELATION) |
245 | @@ -442,6 +490,46 @@ |
246 | } |
247 | self.assertEquals(result, expected) |
248 | |
249 | + @patch('__builtin__.open') |
250 | + def test_amqp_context_with_data_ssl(self, _open): |
251 | + '''Test amqp context with all required data and ssl''' |
252 | + relation = FakeRelation(relation_data=AMQP_RELATION_WITH_SSL) |
253 | + self.relation_get.side_effect = relation.get |
254 | + self.config.return_value = AMQP_CONFIG |
255 | + ssl_dir = '/etc/sslamqp' |
256 | + amqp = context.AMQPContext(ssl_dir=ssl_dir) |
257 | + result = amqp() |
258 | + expected = { |
259 | + 'rabbitmq_host': 'rabbithost', |
260 | + 'rabbitmq_password': 'foobar', |
261 | + 'rabbitmq_user': 'adam', |
262 | + 'rabbit_ssl_port': 5671, |
263 | + 'rabbitmq_virtual_host': 'foo', |
264 | + 'rabbit_ssl_ca': ssl_dir + '/rabbit-client-ca.pem', |
265 | + 'rabbitmq_ha_queues': True, |
266 | + } |
267 | + _open.assert_called_once_with(ssl_dir + '/rabbit-client-ca.pem', 'w') |
268 | + self.assertEquals(result, expected) |
269 | + self.assertEquals([call(AMQP_RELATION_WITH_SSL['ssl_ca'])], self.b64decode.call_args_list) |
270 | + |
271 | + def test_amqp_context_with_data_ssl_noca(self): |
272 | + '''Test amqp context with all required data with ssl but missing ca''' |
273 | + relation = FakeRelation(relation_data=AMQP_RELATION_WITH_SSL) |
274 | + self.relation_get.side_effect = relation.get |
275 | + self.config.return_value = AMQP_CONFIG |
276 | + amqp = context.AMQPContext() |
277 | + result = amqp() |
278 | + expected = { |
279 | + 'rabbitmq_host': 'rabbithost', |
280 | + 'rabbitmq_password': 'foobar', |
281 | + 'rabbitmq_user': 'adam', |
282 | + 'rabbit_ssl_port': 5671, |
283 | + 'rabbitmq_virtual_host': 'foo', |
284 | + 'rabbit_ssl_ca': 'cert', |
285 | + 'rabbitmq_ha_queues': True, |
286 | + } |
287 | + self.assertEquals(result, expected) |
288 | + |
289 | def test_amqp_context_with_data_clustered(self): |
290 | '''Test amqp context with all required data with clustered rabbit''' |
291 | relation_data = copy(AMQP_RELATION) |
292 | @@ -500,6 +588,14 @@ |
293 | amqp = context.AMQPContext() |
294 | self.assertRaises(context.OSContextError, amqp) |
295 | |
296 | + def test_ceph_no_relids(self): |
297 | + '''Test empty ceph realtion''' |
298 | + relation = FakeRelation(relation_data={}) |
299 | + self.relation_ids.side_effect = relation.get |
300 | + ceph = context.CephContext() |
301 | + result = ceph() |
302 | + self.assertEquals(result, {}) |
303 | + |
304 | @patch.object(context, 'config') |
305 | @patch('os.path.isdir') |
306 | @patch('os.mkdir') |
307 | @@ -753,6 +849,21 @@ |
308 | 'neutron_security_groups': True, |
309 | 'local_ip': '10.0.0.1'}, neutron.ovs_ctxt()) |
310 | |
311 | + @patch.object(context.NeutronContext, 'neutron_security_groups') |
312 | + @patch.object(context, 'unit_private_ip') |
313 | + @patch.object(context, 'neutron_plugin_attribute') |
314 | + def test_neutron_nvp_plugin_context(self, attr, ip, sec_groups): |
315 | + ip.return_value = '10.0.0.1' |
316 | + sec_groups.__get__ = MagicMock(return_value=True) |
317 | + attr.return_value = 'some.quantum.driver.class' |
318 | + neutron = context.NeutronContext() |
319 | + self.assertEquals({ |
320 | + 'config': 'some.quantum.driver.class', |
321 | + 'core_plugin': 'some.quantum.driver.class', |
322 | + 'neutron_plugin': 'nvp', |
323 | + 'neutron_security_groups': True, |
324 | + 'local_ip': '10.0.0.1'}, neutron.nvp_ctxt()) |
325 | + |
326 | @patch('charmhelpers.contrib.openstack.context.unit_get') |
327 | @patch.object(context.NeutronContext, 'network_manager') |
328 | def test_neutron_neutron_ctxt(self, mock_network_manager, |