Merge lp:~gnuoy/charms/trusty/quantum-gateway/neutron-contexts into lp:~openstack-charmers/charms/trusty/quantum-gateway/next
- Trusty Tahr (14.04)
- neutron-contexts
- Merge into next
Proposed by
Liam Young
Status: | Merged |
---|---|
Merged at revision: | 92 |
Proposed branch: | lp:~gnuoy/charms/trusty/quantum-gateway/neutron-contexts |
Merge into: | lp:~openstack-charmers/charms/trusty/quantum-gateway/next |
Diff against target: |
662 lines (+162/-340) 5 files modified
hooks/charmhelpers/contrib/openstack/context.py (+144/-1) hooks/quantum_contexts.py (+2/-118) hooks/quantum_utils.py (+5/-5) unit_tests/test_quantum_contexts.py (+8/-213) unit_tests/test_quantum_utils.py (+3/-3) |
To merge this branch: | bzr merge lp:~gnuoy/charms/trusty/quantum-gateway/neutron-contexts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Page | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #2693 quantum-
UNIT OK: passed
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #2700 quantum-
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 1
make: *** [test] Error 1
Full amulet test output: http://
Build: http://
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
James Page (james-page) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' |
2 | --- hooks/charmhelpers/contrib/openstack/context.py 2015-03-19 17:02:44 +0000 |
3 | +++ hooks/charmhelpers/contrib/openstack/context.py 2015-03-26 10:47:31 +0000 |
4 | @@ -47,6 +47,7 @@ |
5 | ) |
6 | |
7 | from charmhelpers.core.sysctl import create as sysctl_create |
8 | +from charmhelpers.core.strutils import bool_from_string |
9 | |
10 | from charmhelpers.core.host import ( |
11 | list_nics, |
12 | @@ -67,6 +68,7 @@ |
13 | ) |
14 | from charmhelpers.contrib.openstack.neutron import ( |
15 | neutron_plugin_attribute, |
16 | + parse_data_port_mappings, |
17 | ) |
18 | from charmhelpers.contrib.openstack.ip import ( |
19 | resolve_address, |
20 | @@ -82,7 +84,6 @@ |
21 | is_bridge_member, |
22 | ) |
23 | from charmhelpers.contrib.openstack.utils import get_host_ip |
24 | - |
25 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' |
26 | ADDRESS_TYPES = ['admin', 'internal', 'public'] |
27 | |
28 | @@ -1162,3 +1163,145 @@ |
29 | sysctl_create(sysctl_dict, |
30 | '/etc/sysctl.d/50-{0}.conf'.format(charm_name())) |
31 | return {'sysctl': sysctl_dict} |
32 | + |
33 | + |
34 | +class NeutronAPIContext(OSContextGenerator): |
35 | + ''' |
36 | + Inspects current neutron-plugin-api relation for neutron settings. Return |
37 | + defaults if it is not present. |
38 | + ''' |
39 | + interfaces = ['neutron-plugin-api'] |
40 | + |
41 | + def __call__(self): |
42 | + self.neutron_defaults = { |
43 | + 'l2_population': { |
44 | + 'rel_key': 'l2-population', |
45 | + 'default': False, |
46 | + }, |
47 | + 'overlay_network_type': { |
48 | + 'rel_key': 'overlay-network-type', |
49 | + 'default': 'gre', |
50 | + }, |
51 | + 'neutron_security_groups': { |
52 | + 'rel_key': 'neutron-security-groups', |
53 | + 'default': False, |
54 | + }, |
55 | + 'network_device_mtu': { |
56 | + 'rel_key': 'network-device-mtu', |
57 | + 'default': None, |
58 | + }, |
59 | + 'enable_dvr': { |
60 | + 'rel_key': 'enable-dvr', |
61 | + 'default': False, |
62 | + }, |
63 | + 'enable_l3ha': { |
64 | + 'rel_key': 'enable-l3ha', |
65 | + 'default': False, |
66 | + }, |
67 | + } |
68 | + ctxt = self.get_neutron_options({}) |
69 | + for rid in relation_ids('neutron-plugin-api'): |
70 | + for unit in related_units(rid): |
71 | + rdata = relation_get(rid=rid, unit=unit) |
72 | + if 'l2-population' in rdata: |
73 | + ctxt.update(self.get_neutron_options(rdata)) |
74 | + |
75 | + return ctxt |
76 | + |
77 | + def get_neutron_options(self, rdata): |
78 | + settings = {} |
79 | + for nkey in self.neutron_defaults.keys(): |
80 | + defv = self.neutron_defaults[nkey]['default'] |
81 | + rkey = self.neutron_defaults[nkey]['rel_key'] |
82 | + if rkey in rdata.keys(): |
83 | + if type(defv) is bool: |
84 | + settings[nkey] = bool_from_string(rdata[rkey]) |
85 | + else: |
86 | + settings[nkey] = rdata[rkey] |
87 | + else: |
88 | + settings[nkey] = defv |
89 | + return settings |
90 | + |
91 | + |
92 | +class ExternalPortContext(NeutronPortContext): |
93 | + |
94 | + def __call__(self): |
95 | + ctxt = {} |
96 | + ports = config('ext-port') |
97 | + if ports: |
98 | + ports = [p.strip() for p in ports.split()] |
99 | + ports = self.resolve_ports(ports) |
100 | + if ports: |
101 | + ctxt = {"ext_port": ports[0]} |
102 | + napi_settings = NeutronAPIContext()() |
103 | + mtu = napi_settings.get('network_device_mtu') |
104 | + if mtu: |
105 | + ctxt['ext_port_mtu'] = mtu |
106 | + |
107 | + return ctxt |
108 | + |
109 | + |
110 | +class DataPortContext(NeutronPortContext): |
111 | + |
112 | + def __call__(self): |
113 | + ports = config('data-port') |
114 | + if ports: |
115 | + portmap = parse_data_port_mappings(ports) |
116 | + ports = portmap.values() |
117 | + resolved = self.resolve_ports(ports) |
118 | + normalized = {get_nic_hwaddr(port): port for port in resolved |
119 | + if port not in ports} |
120 | + normalized.update({port: port for port in resolved |
121 | + if port in ports}) |
122 | + if resolved: |
123 | + return {bridge: normalized[port] for bridge, port in |
124 | + six.iteritems(portmap) if port in normalized.keys()} |
125 | + |
126 | + return None |
127 | + |
128 | + |
129 | +class PhyNICMTUContext(DataPortContext): |
130 | + |
131 | + def __call__(self): |
132 | + ctxt = {} |
133 | + mappings = super(PhyNICMTUContext, self).__call__() |
134 | + if mappings and mappings.values(): |
135 | + ports = mappings.values() |
136 | + napi_settings = NeutronAPIContext()() |
137 | + mtu = napi_settings.get('network_device_mtu') |
138 | + if mtu: |
139 | + ctxt["devs"] = '\\n'.join(ports) |
140 | + ctxt['mtu'] = mtu |
141 | + |
142 | + return ctxt |
143 | + |
144 | + |
145 | +class NetworkServiceContext(OSContextGenerator): |
146 | + |
147 | + def __init__(self, rel_name='quantum-network-service'): |
148 | + self.rel_name = rel_name |
149 | + self.interfaces = [rel_name] |
150 | + |
151 | + def __call__(self): |
152 | + for rid in relation_ids(self.rel_name): |
153 | + for unit in related_units(rid): |
154 | + rdata = relation_get(rid=rid, unit=unit) |
155 | + ctxt = { |
156 | + 'keystone_host': rdata.get('keystone_host'), |
157 | + 'service_port': rdata.get('service_port'), |
158 | + 'auth_port': rdata.get('auth_port'), |
159 | + 'service_tenant': rdata.get('service_tenant'), |
160 | + 'service_username': rdata.get('service_username'), |
161 | + 'service_password': rdata.get('service_password'), |
162 | + 'quantum_host': rdata.get('quantum_host'), |
163 | + 'quantum_port': rdata.get('quantum_port'), |
164 | + 'quantum_url': rdata.get('quantum_url'), |
165 | + 'region': rdata.get('region'), |
166 | + 'service_protocol': |
167 | + rdata.get('service_protocol') or 'http', |
168 | + 'auth_protocol': |
169 | + rdata.get('auth_protocol') or 'http', |
170 | + } |
171 | + if context_complete(ctxt): |
172 | + return ctxt |
173 | + return {} |
174 | |
175 | === modified file 'hooks/quantum_contexts.py' |
176 | --- hooks/quantum_contexts.py 2015-03-16 18:44:02 +0000 |
177 | +++ hooks/quantum_contexts.py 2015-03-26 10:47:31 +0000 |
178 | @@ -4,9 +4,6 @@ |
179 | import socket |
180 | from charmhelpers.core.hookenv import ( |
181 | config, |
182 | - relation_ids, |
183 | - related_units, |
184 | - relation_get, |
185 | unit_get, |
186 | cached |
187 | ) |
188 | @@ -15,8 +12,7 @@ |
189 | ) |
190 | from charmhelpers.contrib.openstack.context import ( |
191 | OSContextGenerator, |
192 | - context_complete, |
193 | - NeutronPortContext, |
194 | + NeutronAPIContext, |
195 | ) |
196 | from charmhelpers.contrib.openstack.utils import ( |
197 | get_os_codename_install_source |
198 | @@ -28,12 +24,8 @@ |
199 | get_address_in_network, |
200 | ) |
201 | from charmhelpers.contrib.openstack.neutron import ( |
202 | - parse_data_port_mappings, |
203 | parse_vlan_range_mappings, |
204 | ) |
205 | -from charmhelpers.core.host import ( |
206 | - get_nic_hwaddr, |
207 | -) |
208 | |
209 | DB_USER = "quantum" |
210 | QUANTUM_DB = "quantum" |
211 | @@ -104,61 +96,6 @@ |
212 | return CORE_PLUGIN[networking_name()][plugin] |
213 | |
214 | |
215 | -def _neutron_api_settings(): |
216 | - ''' |
217 | - Inspects current neutron-plugin-api relation for neutron settings. Return |
218 | - defaults if it is not present |
219 | - ''' |
220 | - neutron_settings = { |
221 | - 'l2_population': False, |
222 | - 'overlay_network_type': 'gre', |
223 | - |
224 | - } |
225 | - |
226 | - for rid in relation_ids('neutron-plugin-api'): |
227 | - for unit in related_units(rid): |
228 | - rdata = relation_get(rid=rid, unit=unit) |
229 | - if 'l2-population' in rdata: |
230 | - neutron_settings.update({ |
231 | - 'l2_population': rdata['l2-population'], |
232 | - 'overlay_network_type': rdata['overlay-network-type'], |
233 | - }) |
234 | - |
235 | - net_dev_mtu = rdata.get('network-device-mtu') |
236 | - if net_dev_mtu: |
237 | - neutron_settings['network_device_mtu'] = net_dev_mtu |
238 | - |
239 | - return neutron_settings |
240 | - |
241 | - |
242 | -class NetworkServiceContext(OSContextGenerator): |
243 | - interfaces = ['quantum-network-service'] |
244 | - |
245 | - def __call__(self): |
246 | - for rid in relation_ids('quantum-network-service'): |
247 | - for unit in related_units(rid): |
248 | - rdata = relation_get(rid=rid, unit=unit) |
249 | - ctxt = { |
250 | - 'keystone_host': rdata.get('keystone_host'), |
251 | - 'service_port': rdata.get('service_port'), |
252 | - 'auth_port': rdata.get('auth_port'), |
253 | - 'service_tenant': rdata.get('service_tenant'), |
254 | - 'service_username': rdata.get('service_username'), |
255 | - 'service_password': rdata.get('service_password'), |
256 | - 'quantum_host': rdata.get('quantum_host'), |
257 | - 'quantum_port': rdata.get('quantum_port'), |
258 | - 'quantum_url': rdata.get('quantum_url'), |
259 | - 'region': rdata.get('region'), |
260 | - 'service_protocol': |
261 | - rdata.get('service_protocol') or 'http', |
262 | - 'auth_protocol': |
263 | - rdata.get('auth_protocol') or 'http', |
264 | - } |
265 | - if context_complete(ctxt): |
266 | - return ctxt |
267 | - return {} |
268 | - |
269 | - |
270 | class L3AgentContext(OSContextGenerator): |
271 | |
272 | def __call__(self): |
273 | @@ -180,63 +117,10 @@ |
274 | return ctxt |
275 | |
276 | |
277 | -class ExternalPortContext(NeutronPortContext): |
278 | - |
279 | - def __call__(self): |
280 | - ctxt = {} |
281 | - ports = config('ext-port') |
282 | - if ports: |
283 | - ports = [p.strip() for p in ports.split()] |
284 | - ports = self.resolve_ports(ports) |
285 | - if ports: |
286 | - ctxt = {"ext_port": ports[0]} |
287 | - neutron_api_settings = _neutron_api_settings() |
288 | - mtu = neutron_api_settings.get('network_device_mtu') |
289 | - if mtu: |
290 | - ctxt['ext_port_mtu'] = mtu |
291 | - |
292 | - return ctxt |
293 | - |
294 | - |
295 | -class DataPortContext(NeutronPortContext): |
296 | - |
297 | - def __call__(self): |
298 | - ports = config('data-port') |
299 | - if ports: |
300 | - portmap = parse_data_port_mappings(ports) |
301 | - ports = portmap.values() |
302 | - resolved = self.resolve_ports(ports) |
303 | - normalized = {get_nic_hwaddr(port): port for port in resolved |
304 | - if port not in ports} |
305 | - normalized.update({port: port for port in resolved |
306 | - if port in ports}) |
307 | - if resolved: |
308 | - return {bridge: normalized[port] for bridge, port in |
309 | - portmap.iteritems() if port in normalized.keys()} |
310 | - |
311 | - return None |
312 | - |
313 | - |
314 | -class PhyNICMTUContext(DataPortContext): |
315 | - |
316 | - def __call__(self): |
317 | - ctxt = {} |
318 | - mappings = super(PhyNICMTUContext, self).__call__() |
319 | - if mappings and mappings.values(): |
320 | - ports = mappings.values() |
321 | - neutron_api_settings = _neutron_api_settings() |
322 | - mtu = neutron_api_settings.get('network_device_mtu') |
323 | - if mtu: |
324 | - ctxt["devs"] = '\\n'.join(ports) |
325 | - ctxt['mtu'] = mtu |
326 | - |
327 | - return ctxt |
328 | - |
329 | - |
330 | class QuantumGatewayContext(OSContextGenerator): |
331 | |
332 | def __call__(self): |
333 | - neutron_api_settings = _neutron_api_settings() |
334 | + neutron_api_settings = NeutronAPIContext()() |
335 | ctxt = { |
336 | 'shared_secret': get_shared_secret(), |
337 | 'local_ip': |
338 | |
339 | === modified file 'hooks/quantum_utils.py' |
340 | --- hooks/quantum_utils.py 2015-03-16 18:44:02 +0000 |
341 | +++ hooks/quantum_utils.py 2015-03-26 10:47:31 +0000 |
342 | @@ -41,7 +41,11 @@ |
343 | |
344 | import charmhelpers.contrib.openstack.context as context |
345 | from charmhelpers.contrib.openstack.context import ( |
346 | - SyslogContext |
347 | + SyslogContext, |
348 | + NetworkServiceContext, |
349 | + ExternalPortContext, |
350 | + PhyNICMTUContext, |
351 | + DataPortContext, |
352 | ) |
353 | import charmhelpers.contrib.openstack.templating as templating |
354 | from charmhelpers.contrib.openstack.neutron import headers_package |
355 | @@ -50,11 +54,7 @@ |
356 | NEUTRON, QUANTUM, |
357 | networking_name, |
358 | QuantumGatewayContext, |
359 | - NetworkServiceContext, |
360 | L3AgentContext, |
361 | - ExternalPortContext, |
362 | - PhyNICMTUContext, |
363 | - DataPortContext, |
364 | remap_plugin |
365 | ) |
366 | from charmhelpers.contrib.openstack.neutron import ( |
367 | |
368 | === modified file 'unit_tests/test_quantum_contexts.py' |
369 | --- unit_tests/test_quantum_contexts.py 2015-03-16 18:44:02 +0000 |
370 | +++ unit_tests/test_quantum_contexts.py 2015-03-26 10:47:31 +0000 |
371 | @@ -14,12 +14,8 @@ |
372 | TO_PATCH = [ |
373 | 'apt_install', |
374 | 'config', |
375 | - 'context_complete', |
376 | 'eligible_leader', |
377 | 'get_os_codename_install_source', |
378 | - 'relation_get', |
379 | - 'relation_ids', |
380 | - 'related_units', |
381 | 'unit_get', |
382 | ] |
383 | |
384 | @@ -42,182 +38,6 @@ |
385 | yield mock_open, mock_file |
386 | |
387 | |
388 | -class TestNetworkServiceContext(CharmTestCase): |
389 | - |
390 | - def setUp(self): |
391 | - super(TestNetworkServiceContext, self).setUp(quantum_contexts, |
392 | - TO_PATCH) |
393 | - self.config.side_effect = self.test_config.get |
394 | - self.context = quantum_contexts.NetworkServiceContext() |
395 | - self.test_relation.set( |
396 | - {'keystone_host': '10.5.0.1', |
397 | - 'service_port': '5000', |
398 | - 'auth_port': '20000', |
399 | - 'service_tenant': 'tenant', |
400 | - 'service_username': 'username', |
401 | - 'service_password': 'password', |
402 | - 'quantum_host': '10.5.0.2', |
403 | - 'quantum_port': '9696', |
404 | - 'quantum_url': 'http://10.5.0.2:9696/v2', |
405 | - 'region': 'aregion'} |
406 | - ) |
407 | - self.data_result = { |
408 | - 'keystone_host': '10.5.0.1', |
409 | - 'service_port': '5000', |
410 | - 'auth_port': '20000', |
411 | - 'service_tenant': 'tenant', |
412 | - 'service_username': 'username', |
413 | - 'service_password': 'password', |
414 | - 'quantum_host': '10.5.0.2', |
415 | - 'quantum_port': '9696', |
416 | - 'quantum_url': 'http://10.5.0.2:9696/v2', |
417 | - 'region': 'aregion', |
418 | - 'service_protocol': 'http', |
419 | - 'auth_protocol': 'http', |
420 | - } |
421 | - |
422 | - def test_not_related(self): |
423 | - self.relation_ids.return_value = [] |
424 | - self.assertEquals(self.context(), {}) |
425 | - |
426 | - def test_no_units(self): |
427 | - self.relation_ids.return_value = [] |
428 | - self.relation_ids.return_value = ['foo'] |
429 | - self.related_units.return_value = [] |
430 | - self.assertEquals(self.context(), {}) |
431 | - |
432 | - def test_no_data(self): |
433 | - self.relation_ids.return_value = ['foo'] |
434 | - self.related_units.return_value = ['bar'] |
435 | - self.relation_get.side_effect = self.test_relation.get |
436 | - self.context_complete.return_value = False |
437 | - self.assertEquals(self.context(), {}) |
438 | - |
439 | - def test_data_multi_unit(self): |
440 | - self.relation_ids.return_value = ['foo'] |
441 | - self.related_units.return_value = ['bar', 'baz'] |
442 | - self.context_complete.return_value = True |
443 | - self.relation_get.side_effect = self.test_relation.get |
444 | - self.assertEquals(self.context(), self.data_result) |
445 | - |
446 | - def test_data_single_unit(self): |
447 | - self.relation_ids.return_value = ['foo'] |
448 | - self.related_units.return_value = ['bar'] |
449 | - self.context_complete.return_value = True |
450 | - self.relation_get.side_effect = self.test_relation.get |
451 | - self.assertEquals(self.context(), self.data_result) |
452 | - |
453 | - |
454 | -class TestNeutronPortContext(CharmTestCase): |
455 | - |
456 | - def setUp(self): |
457 | - super(TestNeutronPortContext, self).setUp(quantum_contexts, |
458 | - TO_PATCH) |
459 | - self.machine_macs = { |
460 | - 'eth0': 'fe:c5:ce:8e:2b:00', |
461 | - 'eth1': 'fe:c5:ce:8e:2b:01', |
462 | - 'eth2': 'fe:c5:ce:8e:2b:02', |
463 | - 'eth3': 'fe:c5:ce:8e:2b:03', |
464 | - } |
465 | - self.machine_nics = { |
466 | - 'eth0': ['192.168.0.1'], |
467 | - 'eth1': ['192.168.0.2'], |
468 | - 'eth2': [], |
469 | - 'eth3': [], |
470 | - } |
471 | - self.absent_macs = "aa:a5:ae:ae:ab:a4 " |
472 | - |
473 | - def fake_config(self, cfgdict): |
474 | - |
475 | - def _fake_config(key): |
476 | - return cfgdict.get(key) |
477 | - |
478 | - return _fake_config |
479 | - |
480 | - def _fake_get_hwaddr(self, arg): |
481 | - return self.machine_macs[arg] |
482 | - |
483 | - def _fake_get_ipv4(self, arg, fatal=False): |
484 | - return self.machine_nics[arg] |
485 | - |
486 | - @patch('charmhelpers.contrib.openstack.context.config') |
487 | - def test_no_ext_port(self, mock_config): |
488 | - self.config.side_effect = config = self.fake_config({}) |
489 | - mock_config.side_effect = config |
490 | - self.assertEquals(quantum_contexts.ExternalPortContext()(), {}) |
491 | - |
492 | - @patch('charmhelpers.contrib.openstack.context.config') |
493 | - def test_ext_port_eth(self, mock_config): |
494 | - config = self.fake_config({'ext-port': 'eth1010'}) |
495 | - self.config.side_effect = config |
496 | - mock_config.side_effect = config |
497 | - self.assertEquals(quantum_contexts.ExternalPortContext()(), |
498 | - {'ext_port': 'eth1010'}) |
499 | - |
500 | - @patch('charmhelpers.contrib.openstack.context.get_nic_hwaddr') |
501 | - @patch('charmhelpers.contrib.openstack.context.list_nics') |
502 | - @patch('charmhelpers.contrib.openstack.context.get_ipv6_addr') |
503 | - @patch('charmhelpers.contrib.openstack.context.get_ipv4_addr') |
504 | - @patch('charmhelpers.contrib.openstack.context.config') |
505 | - def test_ext_port_mac(self, mock_config, mock_get_ipv4_addr, |
506 | - mock_get_ipv6_addr, mock_list_nics, |
507 | - mock_get_nic_hwaddr): |
508 | - config_macs = self.absent_macs + " " + self.machine_macs['eth2'] |
509 | - config = self.fake_config({'ext-port': config_macs}) |
510 | - self.config.side_effect = config |
511 | - mock_config.side_effect = config |
512 | - |
513 | - mock_get_ipv4_addr.side_effect = self._fake_get_ipv4 |
514 | - mock_get_ipv6_addr.return_value = [] |
515 | - mock_list_nics.return_value = self.machine_macs.keys() |
516 | - mock_get_nic_hwaddr.side_effect = self._fake_get_hwaddr |
517 | - |
518 | - self.assertEquals(quantum_contexts.ExternalPortContext()(), |
519 | - {'ext_port': 'eth2'}) |
520 | - |
521 | - config = self.fake_config({'ext-port': self.absent_macs}) |
522 | - self.config.side_effect = config |
523 | - mock_config.side_effect = config |
524 | - |
525 | - self.assertEquals(quantum_contexts.ExternalPortContext()(), {}) |
526 | - |
527 | - @patch.object(quantum_contexts, '_neutron_api_settings') |
528 | - @patch('charmhelpers.contrib.openstack.context.get_nic_hwaddr') |
529 | - @patch('charmhelpers.contrib.openstack.context.list_nics') |
530 | - @patch('charmhelpers.contrib.openstack.context.get_ipv6_addr') |
531 | - @patch('charmhelpers.contrib.openstack.context.get_ipv4_addr') |
532 | - @patch('charmhelpers.contrib.openstack.context.config') |
533 | - def test_ext_port_mac_one_used_nic(self, mock_config, |
534 | - mock_get_ipv4_addr, |
535 | - mock_get_ipv6_addr, mock_list_nics, |
536 | - mock_get_nic_hwaddr, |
537 | - mock_neutron_api_settings): |
538 | - |
539 | - mock_neutron_api_settings.return_value = {'network_device_mtu': 1234} |
540 | - config_macs = "%s %s" % (self.machine_macs['eth1'], |
541 | - self.machine_macs['eth2']) |
542 | - |
543 | - mock_get_ipv4_addr.side_effect = self._fake_get_ipv4 |
544 | - mock_get_ipv6_addr.return_value = [] |
545 | - mock_list_nics.return_value = self.machine_macs.keys() |
546 | - mock_get_nic_hwaddr.side_effect = self._fake_get_hwaddr |
547 | - |
548 | - config = self.fake_config({'ext-port': config_macs}) |
549 | - self.config.side_effect = config |
550 | - mock_config.side_effect = config |
551 | - self.assertEquals(quantum_contexts.ExternalPortContext()(), |
552 | - {'ext_port': 'eth2', 'ext_port_mtu': 1234}) |
553 | - |
554 | - @patch('charmhelpers.contrib.openstack.context.NeutronPortContext.' |
555 | - 'resolve_ports') |
556 | - def test_data_port_eth(self, mock_resolve): |
557 | - self.config.side_effect = self.fake_config({'data-port': |
558 | - 'phybr1:eth1010'}) |
559 | - mock_resolve.side_effect = lambda ports: ports |
560 | - self.assertEquals(quantum_contexts.DataPortContext()(), |
561 | - {'phybr1': 'eth1010'}) |
562 | - |
563 | - |
564 | class TestL3AgentContext(CharmTestCase): |
565 | |
566 | def setUp(self): |
567 | @@ -259,9 +79,12 @@ |
568 | TO_PATCH) |
569 | self.config.side_effect = self.test_config.get |
570 | |
571 | + @patch('charmhelpers.contrib.openstack.context.relation_get') |
572 | + @patch('charmhelpers.contrib.openstack.context.related_units') |
573 | + @patch('charmhelpers.contrib.openstack.context.relation_ids') |
574 | @patch.object(quantum_contexts, 'get_shared_secret') |
575 | @patch.object(quantum_contexts, 'get_host_ip') |
576 | - def test_all(self, _host_ip, _secret): |
577 | + def test_all(self, _host_ip, _secret, _rids, _runits, _rget): |
578 | self.test_config.set('plugin', 'ovs') |
579 | self.test_config.set('debug', False) |
580 | self.test_config.set('verbose', True) |
581 | @@ -269,15 +92,14 @@ |
582 | self.test_config.set('vlan-ranges', |
583 | 'physnet1:1000:2000 physnet2:2001:3000') |
584 | # Provided by neutron-api relation |
585 | - self.relation_ids.return_value = ['neutron-plugin-api:0'] |
586 | - self.related_units.return_value = ['neutron-api/0'] |
587 | - rdata = {'network-device-mtu': 9000} |
588 | - self.relation_get.side_effect = lambda *args, **kwargs: rdata |
589 | + _rids.return_value = ['neutron-plugin-api:0'] |
590 | + _runits.return_value = ['neutron-api/0'] |
591 | + rdata = {'network-device-mtu': 9000, 'l2-population': 'False'} |
592 | + _rget.side_effect = lambda *args, **kwargs: rdata |
593 | self.get_os_codename_install_source.return_value = 'folsom' |
594 | _host_ip.return_value = '10.5.0.1' |
595 | _secret.return_value = 'testsecret' |
596 | ctxt = quantum_contexts.QuantumGatewayContext()() |
597 | - self.relation_ids.assert_called_with('neutron-plugin-api') |
598 | self.assertEquals(ctxt, { |
599 | 'shared_secret': 'testsecret', |
600 | 'local_ip': '10.5.0.1', |
601 | @@ -414,30 +236,3 @@ |
602 | self.config.return_value = 'ovs' |
603 | self.assertEquals(quantum_contexts.core_plugin(), |
604 | quantum_contexts.NEUTRON_ML2_PLUGIN) |
605 | - |
606 | - def test_neutron_api_settings(self): |
607 | - self.relation_ids.return_value = ['foo'] |
608 | - self.related_units.return_value = ['bar'] |
609 | - self.test_relation.set({'l2-population': True, |
610 | - 'overlay-network-type': 'gre', }) |
611 | - self.relation_get.side_effect = self.test_relation.get |
612 | - self.assertEquals(quantum_contexts._neutron_api_settings(), |
613 | - {'l2_population': True, |
614 | - 'overlay_network_type': 'gre'}) |
615 | - |
616 | - def test_neutron_api_settings2(self): |
617 | - self.relation_ids.return_value = ['foo'] |
618 | - self.related_units.return_value = ['bar'] |
619 | - self.test_relation.set({'l2-population': True, |
620 | - 'overlay-network-type': 'gre', }) |
621 | - self.relation_get.side_effect = self.test_relation.get |
622 | - self.assertEquals(quantum_contexts._neutron_api_settings(), |
623 | - {'l2_population': True, |
624 | - 'overlay_network_type': 'gre'}) |
625 | - |
626 | - def test_neutron_api_settings_no_apiplugin(self): |
627 | - self.config.return_value = 1500 |
628 | - self.relation_ids.return_value = [] |
629 | - self.assertEquals(quantum_contexts._neutron_api_settings(), |
630 | - {'l2_population': False, |
631 | - 'overlay_network_type': 'gre', }) |
632 | |
633 | === modified file 'unit_tests/test_quantum_utils.py' |
634 | --- unit_tests/test_quantum_utils.py 2015-03-16 18:44:02 +0000 |
635 | +++ unit_tests/test_quantum_utils.py 2015-03-26 10:47:31 +0000 |
636 | @@ -138,7 +138,7 @@ |
637 | self.get_os_codename_install_source.return_value = 'kilo' |
638 | self.assertTrue('python-neutron-fwaas' in quantum_utils.get_packages()) |
639 | |
640 | - @patch('quantum_contexts.config') |
641 | + @patch('charmhelpers.contrib.openstack.context.config') |
642 | def test_configure_ovs_starts_service_if_required(self, mock_config): |
643 | mock_config.side_effect = self.test_config.get |
644 | self.config.return_value = 'ovs' |
645 | @@ -151,7 +151,7 @@ |
646 | quantum_utils.configure_ovs() |
647 | self.assertFalse(self.full_restart.called) |
648 | |
649 | - @patch('quantum_contexts.config') |
650 | + @patch('charmhelpers.contrib.openstack.context.config') |
651 | def test_configure_ovs_ovs_ext_port(self, mock_config): |
652 | mock_config.side_effect = self.test_config.get |
653 | self.config.side_effect = self.test_config.get |
654 | @@ -167,7 +167,7 @@ |
655 | ]) |
656 | self.add_bridge_port.assert_called_with('br-ex', 'eth0') |
657 | |
658 | - @patch('quantum_contexts.config') |
659 | + @patch('charmhelpers.contrib.openstack.context.config') |
660 | def test_configure_ovs_ovs_data_port(self, mock_config): |
661 | mock_config.side_effect = self.test_config.get |
662 | self.config.side_effect = self.test_config.get |
charm_lint_check #2902 quantum- gateway- next for gnuoy mp254221
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/2902/