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
This commit is contained in:
Sean Mooney 2014-06-27 11:18:48 +01:00
parent 52e281c736
commit 1b46d36269
3 changed files with 12 additions and 10 deletions

View File

@ -898,13 +898,14 @@ class OVSNeutronAgent(n_rpc.RpcCallback,
self.int_ofports = {} self.int_ofports = {}
self.phys_ofports = {} self.phys_ofports = {}
ip_wrapper = ip_lib.IPWrapper(self.root_helper) 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(): for physical_network, bridge in bridge_mappings.iteritems():
LOG.info(_("Mapping physical network %(physical_network)s to " LOG.info(_("Mapping physical network %(physical_network)s to "
"bridge %(bridge)s"), "bridge %(bridge)s"),
{'physical_network': physical_network, {'physical_network': physical_network,
'bridge': bridge}) 'bridge': bridge})
# setup physical 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 " LOG.error(_("Bridge %(bridge)s for physical network "
"%(physical_network)s does not exist. Agent " "%(physical_network)s does not exist. Agent "
"terminated!"), "terminated!"),

View File

@ -125,6 +125,8 @@ class TestOvsNeutronAgent(base.BaseTestCase):
return_value='00:00:00:00:00:01'), return_value='00:00:00:00:00:01'),
mock.patch('neutron.agent.linux.utils.get_interface_mac', mock.patch('neutron.agent.linux.utils.get_interface_mac',
return_value='00:00:00:00:00:01'), return_value='00:00:00:00:00:01'),
mock.patch('neutron.agent.linux.ovs_lib.'
'get_bridges'),
mock.patch('neutron.openstack.common.loopingcall.' mock.patch('neutron.openstack.common.loopingcall.'
'FixedIntervalLoopingCall', 'FixedIntervalLoopingCall',
new=MockFixedIntervalLoopingCall), new=MockFixedIntervalLoopingCall),
@ -516,10 +518,11 @@ class TestOvsNeutronAgent(base.BaseTestCase):
mock.patch.object(ip_lib.IPWrapper, "add_veth"), mock.patch.object(ip_lib.IPWrapper, "add_veth"),
mock.patch.object(ip_lib.IpLinkCommand, "delete"), mock.patch.object(ip_lib.IpLinkCommand, "delete"),
mock.patch.object(ip_lib.IpLinkCommand, "set_up"), 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, ) as (devex_fn, sysexit_fn, utilsexec_fn, remflows_fn, ovs_addfl_fn,
ovs_addport_fn, ovs_delport_fn, br_addport_fn, ovs_addport_fn, ovs_delport_fn, br_addport_fn, br_delport_fn,
br_delport_fn, addveth_fn, linkdel_fn, linkset_fn, linkmtu_fn): addveth_fn, linkdel_fn, linkset_fn, linkmtu_fn, get_br_fn):
devex_fn.return_value = True devex_fn.return_value = True
parent = mock.MagicMock() parent = mock.MagicMock()
parent.attach_mock(utilsexec_fn, 'utils_execute') parent.attach_mock(utilsexec_fn, 'utils_execute')
@ -529,6 +532,7 @@ class TestOvsNeutronAgent(base.BaseTestCase):
ip_lib.IPDevice("phy-br-eth1")) ip_lib.IPDevice("phy-br-eth1"))
ovs_addport_fn.return_value = "int_ofport" ovs_addport_fn.return_value = "int_ofport"
br_addport_fn.return_value = "phys_veth" br_addport_fn.return_value = "phys_veth"
get_br_fn.return_value = ["br-eth"]
self.agent.setup_physical_bridges({"physnet1": "br-eth"}) self.agent.setup_physical_bridges({"physnet1": "br-eth"})
expected_calls = [mock.call.link_delete(), expected_calls = [mock.call.link_delete(),
mock.call.utils_execute(['/sbin/udevadm', mock.call.utils_execute(['/sbin/udevadm',

View File

@ -241,14 +241,12 @@ class TunnelTest(base.BaseTestCase):
actions="drop") actions="drop")
] ]
self.device_exists_expected = [ self.device_exists_expected = []
mock.call(self.MAP_TUN_BRIDGE, 'sudo'),
]
self.ipdevice_expected = [] self.ipdevice_expected = []
self.ipwrapper_expected = [mock.call('sudo')] 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.inta_expected = []
self.intb_expected = [] self.intb_expected = []
@ -656,7 +654,6 @@ class TunnelTestUseVethInterco(TunnelTest):
] ]
self.device_exists_expected = [ self.device_exists_expected = [
mock.call(self.MAP_TUN_BRIDGE, 'sudo'),
mock.call('int-%s' % 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) '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.inta_expected = [mock.call.link.set_up()]
self.intb_expected = [mock.call.link.set_up()] self.intb_expected = [mock.call.link.set_up()]