Merge lp:~hopem/charm-helpers/lp1497517 into lp:charm-helpers

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 458
Proposed branch: lp:~hopem/charm-helpers/lp1497517
Merge into: lp:charm-helpers
Diff against target: 66 lines (+36/-1)
2 files modified
charmhelpers/contrib/openstack/context.py (+12/-1)
tests/contrib/openstack/test_os_contexts.py (+24/-0)
To merge this branch: bzr merge lp:~hopem/charm-helpers/lp1497517
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Billy Olsen Approve
OpenStack Charmers Pending
Review via email: mp+271933@code.launchpad.net

This proposal supersedes a proposal from 2015-09-21.

To post a comment you must log in.
Revision history for this message
Billy Olsen (billy-olsen) wrote : Posted in a previous version of this proposal

Changes seem generally fine to me, but would love to see a unit-test covering this new code.

Also note: there are unrelated py3 test failures.

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

Granted!

Revision history for this message
Billy Olsen (billy-olsen) wrote :

LGTM, thanks Ed!

review: Approve
lp:~hopem/charm-helpers/lp1497517 updated
455. By Edward Hope-Morley

avoid duplicate ports in list

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
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2015-09-15 17:52:15 +0000
3+++ charmhelpers/contrib/openstack/context.py 2015-09-25 16:12:01 +0000
4@@ -14,6 +14,7 @@
5 # You should have received a copy of the GNU Lesser General Public License
6 # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
7
8+import glob
9 import json
10 import os
11 import re
12@@ -1378,8 +1379,18 @@
13 ports = mappings.values()
14 napi_settings = NeutronAPIContext()()
15 mtu = napi_settings.get('network_device_mtu')
16+ all_ports = set()
17+ # If any of ports is a vlan device, its underlying device must have
18+ # mtu applied first.
19+ for port in ports:
20+ for lport in glob.glob("/sys/class/net/%s/lower_*" % port):
21+ lport = os.path.basename(lport)
22+ all_ports.add(lport.split('_')[1])
23+
24+ all_ports = list(all_ports)
25+ all_ports.extend(ports)
26 if mtu:
27- ctxt["devs"] = '\\n'.join(ports)
28+ ctxt["devs"] = '\\n'.join(all_ports)
29 ctxt['mtu'] = mtu
30
31 return ctxt
32
33=== modified file 'tests/contrib/openstack/test_os_contexts.py'
34--- tests/contrib/openstack/test_os_contexts.py 2015-09-15 17:52:15 +0000
35+++ tests/contrib/openstack/test_os_contexts.py 2015-09-25 16:12:01 +0000
36@@ -2564,6 +2564,30 @@
37 self.assertEquals(context.DataPortContext()(),
38 {'phybr1': 'eth1010'})
39
40+ @patch.object(context.NeutronAPIContext, '__call__', lambda *args:
41+ {'network_device_mtu': 5000})
42+ @patch.object(context, 'get_nic_hwaddr', lambda inst, port: port)
43+ @patch.object(context.NeutronPortContext, 'resolve_ports',
44+ lambda inst, ports: ports)
45+ def test_phy_nic_mtu_context(self):
46+ self.config.side_effect = fake_config({'data-port':
47+ 'phybr1:eth0'})
48+ ctxt = context.PhyNICMTUContext()()
49+ self.assertEqual(ctxt, {'devs': 'eth0', 'mtu': 5000})
50+
51+ @patch.object(context.glob, 'glob')
52+ @patch.object(context.NeutronAPIContext, '__call__', lambda *args:
53+ {'network_device_mtu': 5000})
54+ @patch.object(context, 'get_nic_hwaddr', lambda inst, port: port)
55+ @patch.object(context.NeutronPortContext, 'resolve_ports',
56+ lambda inst, ports: ports)
57+ def test_phy_nic_mtu_context_vlan(self, mock_glob):
58+ self.config.side_effect = fake_config({'data-port':
59+ 'phybr1:eth0.100'})
60+ mock_glob.return_value = ['/sys/class/net/eth0.100/lower_eth0']
61+ ctxt = context.PhyNICMTUContext()()
62+ self.assertEqual(ctxt, {'devs': 'eth0\\neth0.100', 'mtu': 5000})
63+
64 def test_neutronapicontext_defaults(self):
65 self.relation_ids.return_value = []
66 expected_keys = [

Subscribers

People subscribed via source and target branches