Merge lp:~mattrae/charm-helpers/lp1635067 into lp:charm-helpers

Proposed by Matt Rae
Status: Superseded
Proposed branch: lp:~mattrae/charm-helpers/lp1635067
Merge into: lp:charm-helpers
Diff against target: 74 lines (+46/-0)
2 files modified
charmhelpers/contrib/network/ovs/__init__.py (+29/-0)
tests/contrib/network/test_ovs.py (+17/-0)
To merge this branch: bzr merge lp:~mattrae/charm-helpers/lp1635067
Reviewer Review Type Date Requested Status
Jorge Niedbalski (community) Needs Fixing
Review via email: mp+314364@code.launchpad.net

This proposal has been superseded by a proposal from 2017-01-14.

Description of the change

Adding functions to create an ovs bridge and check if an interface is a linux bridge.

This is needed in charm-helpers in order to add support for using a linuxbridge bridge in data-port config of neutron-gateway and neutron-openvswitch charms, such as 'juju set neutron-openvswitch data-port="br-ex:br-eno1"' where br-eno1 is the bridge created on eno1 by juju by default.

https://review.openstack.org/#/c/392212/

To post a comment you must log in.
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

LGTM, however I am missing unit tests for the change.

review: Needs Fixing
lp:~mattrae/charm-helpers/lp1635067 updated
673. By Matt Rae

adding tests for add_ovsbridge_linuxbridge

Revision history for this message
Matt Rae (mattrae) wrote :

Thanks Jorge, I added a unit test for add_ovsbridge_linuxbridge. I'm not exactly sure how to add a test for is_linuxbridge_interface, but it might be trival enough that it doesn't need testing. let me know if i should test is_linuxbridge_interface as well.

lp:~mattrae/charm-helpers/lp1635067 updated
674. By Matt Rae

changing is_linuxbridge_interface to use os.path.exists and adding tests

675. By Matt Rae

cleanup formatting

676. By Matt Rae

updating add_ovsbridge_linuxbridge to be idempotent

677. By Matt Rae

adding levels to log statements

678. By Matt Rae

making veth persistent by adding to interfaces.d

679. By Matt Rae

swap names of veth pair to make debugging easier

680. By Matt Rae

dropping log level to DEBUG

681. By Matt Rae

documenting functions and removing unneeded close()

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/network/ovs/__init__.py'
2--- charmhelpers/contrib/network/ovs/__init__.py 2016-07-06 14:41:05 +0000
3+++ charmhelpers/contrib/network/ovs/__init__.py 2017-01-13 23:44:05 +0000
4@@ -15,6 +15,7 @@
5 ''' Helpers for interacting with OpenvSwitch '''
6 import subprocess
7 import os
8+import glob
9 from charmhelpers.core.hookenv import (
10 log, WARNING
11 )
12@@ -60,6 +61,34 @@
13 subprocess.check_call(["ip", "link", "set", port, "promisc", "off"])
14
15
16+def add_ovsbridge_linuxbridge(name, bridge):
17+ ''' Add linux bridge to the named openvswitch bridge '''
18+ ovsbridge_port = "veth-" + name
19+ linuxbridge_port = "veth-" + bridge
20+ log('Adding linuxbridge {} to ovsbridge {}'.format(bridge, name))
21+ try:
22+ subprocess.check_call(["ip", "link", "add", "name", linuxbridge_port,
23+ "type", "veth", "peer", "name",
24+ ovsbridge_port])
25+ subprocess.check_call(["ip", "link", "set", ovsbridge_port, "up"])
26+ subprocess.check_call(["ip", "link", "set", linuxbridge_port, "up"])
27+ subprocess.check_call(["ip", "link", "set", linuxbridge_port, "master",
28+ bridge])
29+ except subprocess.CalledProcessError:
30+ log('Interfaces {} and {} already exist'.format(ovsbridge_port,
31+ linuxbridge_port))
32+ return
33+ add_bridge_port(name, ovsbridge_port)
34+
35+
36+def is_linuxbridge_interface(port):
37+ ''' Check if the interface is a linuxbridge bridge '''
38+ for sdir in glob.glob('/'.join(['/sys/class/net', port, '*'])):
39+ if 'bridge' in sdir.split("/")[-1]:
40+ return True
41+ return False
42+
43+
44 def set_manager(manager):
45 ''' Set the controller for the local openvswitch '''
46 log('Setting manager for local ovs to {}'.format(manager))
47
48=== modified file 'tests/contrib/network/test_ovs.py'
49--- tests/contrib/network/test_ovs.py 2016-03-23 10:55:08 +0000
50+++ tests/contrib/network/test_ovs.py 2017-01-13 23:44:05 +0000
51@@ -172,6 +172,23 @@
52
53 @patch.object(ovs, 'log')
54 @patch('subprocess.check_call')
55+ def test_add_ovsbridge_linuxbridge(self, check_call, log):
56+ ovs.add_ovsbridge_linuxbridge('br-ex', 'br-eno1')
57+ check_call.assert_has_calls([
58+ call(["ip", "link", "add", "name", "veth-br-eno1",
59+ "type", "veth", "peer", "name", "veth-br-ex"]),
60+ call(["ip", "link", "set", "veth-br-ex", "up"]),
61+ call(["ip", "link", "set", "veth-br-eno1", "up"]),
62+ call(["ip", "link", "set", "veth-br-eno1", "master", "br-eno1"]),
63+ call(["ovs-vsctl", "--", "--may-exist", "add-port",
64+ 'br-ex', 'veth-br-ex']),
65+ call(['ip', 'link', 'set', 'veth-br-ex', 'up']),
66+ call(['ip', 'link', 'set', 'veth-br-ex', 'promisc', 'off'])
67+ ])
68+ self.assertTrue(log.call_count == 2)
69+
70+ @patch.object(ovs, 'log')
71+ @patch('subprocess.check_call')
72 def test_set_manager(self, check_call, log):
73 ovs.set_manager('manager')
74 check_call.assert_called_with(['ovs-vsctl', 'set-manager',

Subscribers

People subscribed via source and target branches