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

Proposed by Edward Hope-Morley
Status: Superseded
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) Needs Fixing
Review via email: mp+258107@code.launchpad.net

This proposal has been superseded by a proposal from 2015-05-20.

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

Approve

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

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) :
review: Needs Fixing
370. By Edward Hope-Morley

fix py3 compat

371. By Edward Hope-Morley

sync trunk

Revision history for this message
Edward Hope-Morley (hopem) wrote :

Fixed

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/neutron.py'
2--- charmhelpers/contrib/openstack/neutron.py 2015-04-13 07:40:54 +0000
3+++ charmhelpers/contrib/openstack/neutron.py 2015-05-20 19:41:56 +0000
4@@ -256,11 +256,14 @@
5 def parse_mappings(mappings):
6 parsed = {}
7 if mappings:
8- mappings = mappings.split(' ')
9+ mappings = mappings.split()
10 for m in mappings:
11 p = m.partition(':')
12- if p[1] == ':':
13- parsed[p[0].strip()] = p[2].strip()
14+ key = p[0].strip()
15+ if p[1]:
16+ parsed[key] = p[2].strip()
17+ else:
18+ parsed[key] = ''
19
20 return parsed
21
22@@ -283,13 +286,13 @@
23 Returns dict of the form {bridge:port}.
24 """
25 _mappings = parse_mappings(mappings)
26- if not _mappings:
27+ if not _mappings or list(_mappings.values()) == ['']:
28 if not mappings:
29 return {}
30
31 # For backwards-compatibility we need to support port-only provided in
32 # config.
33- _mappings = {default_bridge: mappings.split(' ')[0]}
34+ _mappings = {default_bridge: mappings.split()[0]}
35
36 bridges = _mappings.keys()
37 ports = _mappings.values()
38@@ -309,6 +312,8 @@
39
40 Mappings must be a space-delimited list of provider:start:end mappings.
41
42+ The start:end range is optional and may be omitted.
43+
44 Returns dict of the form {provider: (start, end)}.
45 """
46 _mappings = parse_mappings(mappings)
47
48=== modified file 'tests/contrib/openstack/test_neutron_utils.py'
49--- tests/contrib/openstack/test_neutron_utils.py 2015-03-12 09:48:13 +0000
50+++ tests/contrib/openstack/test_neutron_utils.py 2015-05-20 19:41:56 +0000
51@@ -197,3 +197,6 @@
52 ret = neutron.parse_vlan_range_mappings('physnet1:1001:2000 physnet2:2001:3000')
53 self.assertEqual(ret, {'physnet1': ('1001', '2000'),
54 'physnet2': ('2001', '3000')})
55+ ret = neutron.parse_vlan_range_mappings('physnet1 physnet2:2001:3000')
56+ self.assertEqual(ret, {'physnet1': ('',),
57+ 'physnet2': ('2001', '3000')})

Subscribers

People subscribed via source and target branches