From 1b46d36269adc5c64c8cd55a2d9f2c47e42b341f Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Fri, 27 Jun 2014 11:18:48 +0100 Subject: [PATCH] changes ovs agent to get bridges via ovs_lib ip_lib is currently used to list the bridges in the Open vSwitch neutron agent. use of ip_lib blocks reuse of the Open vSwitch agent with userspace only open vSwitchs implementations. this patch replaces calls to ip_lib with ovs_lib.get_bridges Closes-Bug: #1331569 Change-Id: I5935d39b314055063a64266bda0cc4c2d1ac05fc --- neutron/plugins/openvswitch/agent/ovs_neutron_agent.py | 3 ++- .../tests/unit/openvswitch/test_ovs_neutron_agent.py | 10 +++++++--- neutron/tests/unit/openvswitch/test_ovs_tunnel.py | 9 +++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index a79d1f9717b..6ee023f037c 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -898,13 +898,14 @@ class OVSNeutronAgent(n_rpc.RpcCallback, self.int_ofports = {} self.phys_ofports = {} ip_wrapper = ip_lib.IPWrapper(self.root_helper) + ovs_bridges = ovs_lib.get_bridges(self.root_helper) for physical_network, bridge in bridge_mappings.iteritems(): LOG.info(_("Mapping physical network %(physical_network)s to " "bridge %(bridge)s"), {'physical_network': physical_network, 'bridge': bridge}) # setup physical bridge - if not ip_lib.device_exists(bridge, self.root_helper): + if bridge not in ovs_bridges: LOG.error(_("Bridge %(bridge)s for physical network " "%(physical_network)s does not exist. Agent " "terminated!"), diff --git a/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py b/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py index b9422fa67b2..446e1d9a1ab 100644 --- a/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py @@ -125,6 +125,8 @@ class TestOvsNeutronAgent(base.BaseTestCase): return_value='00:00:00:00:00:01'), mock.patch('neutron.agent.linux.utils.get_interface_mac', return_value='00:00:00:00:00:01'), + mock.patch('neutron.agent.linux.ovs_lib.' + 'get_bridges'), mock.patch('neutron.openstack.common.loopingcall.' 'FixedIntervalLoopingCall', new=MockFixedIntervalLoopingCall), @@ -516,10 +518,11 @@ class TestOvsNeutronAgent(base.BaseTestCase): mock.patch.object(ip_lib.IPWrapper, "add_veth"), mock.patch.object(ip_lib.IpLinkCommand, "delete"), mock.patch.object(ip_lib.IpLinkCommand, "set_up"), - mock.patch.object(ip_lib.IpLinkCommand, "set_mtu") + mock.patch.object(ip_lib.IpLinkCommand, "set_mtu"), + mock.patch.object(ovs_lib, "get_bridges") ) as (devex_fn, sysexit_fn, utilsexec_fn, remflows_fn, ovs_addfl_fn, - ovs_addport_fn, ovs_delport_fn, br_addport_fn, - br_delport_fn, addveth_fn, linkdel_fn, linkset_fn, linkmtu_fn): + ovs_addport_fn, ovs_delport_fn, br_addport_fn, br_delport_fn, + addveth_fn, linkdel_fn, linkset_fn, linkmtu_fn, get_br_fn): devex_fn.return_value = True parent = mock.MagicMock() parent.attach_mock(utilsexec_fn, 'utils_execute') @@ -529,6 +532,7 @@ class TestOvsNeutronAgent(base.BaseTestCase): ip_lib.IPDevice("phy-br-eth1")) ovs_addport_fn.return_value = "int_ofport" br_addport_fn.return_value = "phys_veth" + get_br_fn.return_value = ["br-eth"] self.agent.setup_physical_bridges({"physnet1": "br-eth"}) expected_calls = [mock.call.link_delete(), mock.call.utils_execute(['/sbin/udevadm', diff --git a/neutron/tests/unit/openvswitch/test_ovs_tunnel.py b/neutron/tests/unit/openvswitch/test_ovs_tunnel.py index b02b9da795c..4600abf4635 100644 --- a/neutron/tests/unit/openvswitch/test_ovs_tunnel.py +++ b/neutron/tests/unit/openvswitch/test_ovs_tunnel.py @@ -241,14 +241,12 @@ class TunnelTest(base.BaseTestCase): actions="drop") ] - self.device_exists_expected = [ - mock.call(self.MAP_TUN_BRIDGE, 'sudo'), - ] + self.device_exists_expected = [] self.ipdevice_expected = [] self.ipwrapper_expected = [mock.call('sudo')] - self.get_bridges_expected = [mock.call('sudo')] + self.get_bridges_expected = [mock.call('sudo'), mock.call('sudo')] self.inta_expected = [] self.intb_expected = [] @@ -656,7 +654,6 @@ class TunnelTestUseVethInterco(TunnelTest): ] self.device_exists_expected = [ - mock.call(self.MAP_TUN_BRIDGE, 'sudo'), mock.call('int-%s' % self.MAP_TUN_BRIDGE, 'sudo'), ] @@ -670,7 +667,7 @@ class TunnelTestUseVethInterco(TunnelTest): 'phy-%s' % self.MAP_TUN_BRIDGE) ] - self.get_bridges_expected = [mock.call('sudo')] + self.get_bridges_expected = [mock.call('sudo'), mock.call('sudo')] self.inta_expected = [mock.call.link.set_up()] self.intb_expected = [mock.call.link.set_up()]