Merge lp:~hopem/charm-helpers/fix-network-vlan-ranges-parser into lp:charm-helpers

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 378
Proposed branch: lp:~hopem/charm-helpers/fix-network-vlan-ranges-parser
Merge into: lp:charm-helpers
Diff against target: 57 lines (+13/-5)
2 files modified
charmhelpers/contrib/openstack/neutron.py (+10/-5)
tests/contrib/openstack/test_neutron_utils.py (+3/-0)
To merge this branch: bzr merge lp:~hopem/charm-helpers/fix-network-vlan-ranges-parser
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
OpenStack Charmers Pending
Review via email: mp+259679@code.launchpad.net

This proposal supersedes a proposal from 2015-05-02.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote : Posted in a previous version of this proposal

Approve

review: Approve
Revision history for this message
Liam Young (gnuoy) wrote : Posted in a previous version of this proposal

Actually I'm hitting a unit test failure for py3.

FAIL: test_parse_data_port_mappings (tests.contrib.openstack.test_neutron_utils.NeutronTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/liam/branches/prove-it-to-ed/charm-helpers/tests/contrib/openstack/test_neutron_utils.py", line 187, in test_parse_data_port_mappings
    self.assertEqual(ret, {'br0': 'eth0'})
AssertionError: {'eth0': ''} != {'br0': 'eth0'}
- {'eth0': ''}
+ {'br0': 'eth0'}

Seems to be caused by {'key': ''}.values() != [''] in py3

Revision history for this message
Liam Young (gnuoy) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Edward Hope-Morley (hopem) wrote : Posted in a previous version of this proposal

Fixed

Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/neutron.py'
--- charmhelpers/contrib/openstack/neutron.py 2015-04-13 07:40:54 +0000
+++ charmhelpers/contrib/openstack/neutron.py 2015-05-20 19:52:41 +0000
@@ -256,11 +256,14 @@
256def parse_mappings(mappings):256def parse_mappings(mappings):
257 parsed = {}257 parsed = {}
258 if mappings:258 if mappings:
259 mappings = mappings.split(' ')259 mappings = mappings.split()
260 for m in mappings:260 for m in mappings:
261 p = m.partition(':')261 p = m.partition(':')
262 if p[1] == ':':262 key = p[0].strip()
263 parsed[p[0].strip()] = p[2].strip()263 if p[1]:
264 parsed[key] = p[2].strip()
265 else:
266 parsed[key] = ''
264267
265 return parsed268 return parsed
266269
@@ -283,13 +286,13 @@
283 Returns dict of the form {bridge:port}.286 Returns dict of the form {bridge:port}.
284 """287 """
285 _mappings = parse_mappings(mappings)288 _mappings = parse_mappings(mappings)
286 if not _mappings:289 if not _mappings or list(_mappings.values()) == ['']:
287 if not mappings:290 if not mappings:
288 return {}291 return {}
289292
290 # For backwards-compatibility we need to support port-only provided in293 # For backwards-compatibility we need to support port-only provided in
291 # config.294 # config.
292 _mappings = {default_bridge: mappings.split(' ')[0]}295 _mappings = {default_bridge: mappings.split()[0]}
293296
294 bridges = _mappings.keys()297 bridges = _mappings.keys()
295 ports = _mappings.values()298 ports = _mappings.values()
@@ -309,6 +312,8 @@
309312
310 Mappings must be a space-delimited list of provider:start:end mappings.313 Mappings must be a space-delimited list of provider:start:end mappings.
311314
315 The start:end range is optional and may be omitted.
316
312 Returns dict of the form {provider: (start, end)}.317 Returns dict of the form {provider: (start, end)}.
313 """318 """
314 _mappings = parse_mappings(mappings)319 _mappings = parse_mappings(mappings)
315320
=== modified file 'tests/contrib/openstack/test_neutron_utils.py'
--- tests/contrib/openstack/test_neutron_utils.py 2015-03-12 09:48:13 +0000
+++ tests/contrib/openstack/test_neutron_utils.py 2015-05-20 19:52:41 +0000
@@ -197,3 +197,6 @@
197 ret = neutron.parse_vlan_range_mappings('physnet1:1001:2000 physnet2:2001:3000')197 ret = neutron.parse_vlan_range_mappings('physnet1:1001:2000 physnet2:2001:3000')
198 self.assertEqual(ret, {'physnet1': ('1001', '2000'),198 self.assertEqual(ret, {'physnet1': ('1001', '2000'),
199 'physnet2': ('2001', '3000')})199 'physnet2': ('2001', '3000')})
200 ret = neutron.parse_vlan_range_mappings('physnet1 physnet2:2001:3000')
201 self.assertEqual(ret, {'physnet1': ('',),
202 'physnet2': ('2001', '3000')})

Subscribers

People subscribed via source and target branches