Merge "Avoid unnecessarily checking the existence of a device"

This commit is contained in:
Jenkins 2014-03-05 07:27:49 +00:00 committed by Gerrit Code Review
commit 0ce1327913
4 changed files with 29 additions and 24 deletions

View File

@ -602,9 +602,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
def external_gateway_added(self, ri, ex_gw_port, def external_gateway_added(self, ri, ex_gw_port,
interface_name, internal_cidrs): interface_name, internal_cidrs):
if not ip_lib.device_exists(interface_name,
root_helper=self.root_helper,
namespace=ri.ns_name()):
self.driver.plug(ex_gw_port['network_id'], self.driver.plug(ex_gw_port['network_id'],
ex_gw_port['id'], interface_name, ex_gw_port['id'], interface_name,
ex_gw_port['mac_address'], ex_gw_port['mac_address'],
@ -639,9 +636,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
def external_gateway_removed(self, ri, ex_gw_port, def external_gateway_removed(self, ri, ex_gw_port,
interface_name, internal_cidrs): interface_name, internal_cidrs):
if ip_lib.device_exists(interface_name,
root_helper=self.root_helper,
namespace=ri.ns_name()):
self.driver.unplug(interface_name, self.driver.unplug(interface_name,
bridge=self.conf.external_network_bridge, bridge=self.conf.external_network_bridge,
namespace=ri.ns_name(), namespace=ri.ns_name(),

View File

@ -162,12 +162,12 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
if not bridge: if not bridge:
bridge = self.conf.ovs_integration_bridge bridge = self.conf.ovs_integration_bridge
self.check_bridge_exists(bridge)
if not ip_lib.device_exists(device_name, if not ip_lib.device_exists(device_name,
self.root_helper, self.root_helper,
namespace=namespace): namespace=namespace):
self.check_bridge_exists(bridge)
ip = ip_lib.IPWrapper(self.root_helper) ip = ip_lib.IPWrapper(self.root_helper)
tap_name = self._get_tap_name(device_name, prefix) tap_name = self._get_tap_name(device_name, prefix)
@ -199,7 +199,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
if self.conf.ovs_use_veth: if self.conf.ovs_use_veth:
root_dev.link.set_up() root_dev.link.set_up()
else: else:
LOG.warn(_("Device %s already exists"), device_name) LOG.info(_("Device %s already exists"), device_name)
def unplug(self, device_name, bridge=None, namespace=None, prefix=None): def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
"""Unplug the interface.""" """Unplug the interface."""
@ -253,14 +253,17 @@ class MidonetInterfaceDriver(LinuxInterfaceDriver):
utils.execute(cmd, self.root_helper) utils.execute(cmd, self.root_helper)
else: else:
LOG.warn(_("Device %s already exists"), device_name) LOG.info(_("Device %s already exists"), device_name)
def unplug(self, device_name, bridge=None, namespace=None, prefix=None): def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
# the port will be deleted by the dhcp agent that will call the plugin # the port will be deleted by the dhcp agent that will call the plugin
device = ip_lib.IPDevice(device_name, device = ip_lib.IPDevice(device_name,
self.root_helper, self.root_helper,
namespace) namespace)
try:
device.link.delete() device.link.delete()
except RuntimeError:
LOG.error(_("Failed unplugging interface '%s'"), device_name)
LOG.debug(_("Unplugged interface '%s'"), device_name) LOG.debug(_("Unplugged interface '%s'"), device_name)
ip_lib.IPWrapper( ip_lib.IPWrapper(
@ -312,7 +315,7 @@ class IVSInterfaceDriver(LinuxInterfaceDriver):
ns_dev.link.set_up() ns_dev.link.set_up()
root_dev.link.set_up() root_dev.link.set_up()
else: else:
LOG.warn(_("Device %s already exists"), device_name) LOG.info(_("Device %s already exists"), device_name)
def unplug(self, device_name, bridge=None, namespace=None, prefix=None): def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
"""Unplug the interface.""" """Unplug the interface."""
@ -361,7 +364,7 @@ class BridgeInterfaceDriver(LinuxInterfaceDriver):
ns_veth.link.set_up() ns_veth.link.set_up()
else: else:
LOG.warn(_("Device %s already exists"), device_name) LOG.info(_("Device %s already exists"), device_name)
def unplug(self, device_name, bridge=None, namespace=None, prefix=None): def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
"""Unplug the interface.""" """Unplug the interface."""

View File

@ -388,6 +388,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
agent.process_router_floating_ip_nat_rules = mock.Mock() agent.process_router_floating_ip_nat_rules = mock.Mock()
agent.process_router_floating_ip_addresses.return_value = { agent.process_router_floating_ip_addresses.return_value = {
fake_fip_id: 'ACTIVE'} fake_fip_id: 'ACTIVE'}
agent.external_gateway_added = mock.Mock()
router = self._prepare_router_data() router = self._prepare_router_data()
fake_floatingips1 = {'floatingips': [ fake_floatingips1 = {'floatingips': [
{'id': fake_fip_id, {'id': fake_fip_id,
@ -577,6 +578,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data(enable_snat=True) router = self._prepare_router_data(enable_snat=True)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
agent.process_router(ri) agent.process_router(ri)
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
@ -598,6 +600,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data(enable_snat=False) router = self._prepare_router_data(enable_snat=False)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
# Process without NAT # Process without NAT
agent.process_router(ri) agent.process_router(ri)
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
@ -619,6 +622,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data() router = self._prepare_router_data()
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
agent.process_router(ri) agent.process_router(ri)
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
@ -648,6 +652,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data(num_internal_ports=2) router = self._prepare_router_data(num_internal_ports=2)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
agent.process_router(ri) agent.process_router(ri)
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
@ -669,6 +674,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data() router = self._prepare_router_data()
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
with mock.patch.object( with mock.patch.object(
l3_agent.L3NATAgent, l3_agent.L3NATAgent,
'internal_network_added') as internal_network_added: 'internal_network_added') as internal_network_added:
@ -694,6 +700,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
router = self._prepare_router_data() router = self._prepare_router_data()
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
# add an internal port # add an internal port
agent.process_router(ri) agent.process_router(ri)
@ -734,6 +741,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper, ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router) self.conf.use_namespaces, router=router)
agent.external_gateway_added = mock.Mock()
agent.process_router(ri) agent.process_router(ri)
# Assess the call for putting the floating IP up was performed # Assess the call for putting the floating IP up was performed
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(

View File

@ -336,7 +336,7 @@ class TestBridgeInterfaceDriver(TestBase):
def test_plug_dev_exists(self): def test_plug_dev_exists(self):
self.device_exists.return_value = True self.device_exists.return_value = True
with mock.patch('neutron.agent.linux.interface.LOG.warn') as log: with mock.patch('neutron.agent.linux.interface.LOG.info') as log:
br = interface.BridgeInterfaceDriver(self.conf) br = interface.BridgeInterfaceDriver(self.conf)
br.plug('01234567-1234-1234-99', br.plug('01234567-1234-1234-99',
'port-1234', 'port-1234',