From: Maru Newby Date: Tue, 28 Oct 2014 19:50:31 +0000 (+0000) Subject: Add a constant for router interface device owners X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2bdf7d67a7e20cc688f292155ae2b29af785b920;p=openstack-build%2Fneutron-build.git Add a constant for router interface device owners In the absense of a port object that includes a check for whether a given port is implementing a router interface, this change adds the ROUTER_INTERFACE_OWNERS tuple containing the relevant DEVICE_OWNER_* constants. This change was suggested by https://review.openstack.org/#/c/129865/ Change-Id: I1c45c29617d692cc05b44f7f2c4ec1e5252be303 --- diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 98953e526..ca3a27bba 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -555,9 +555,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, subnet_id)) for p in subnet_ports: - if (p['device_owner'] not in ( - l3_constants.DEVICE_OWNER_ROUTER_INTF, - l3_constants.DEVICE_OWNER_DVR_INTERFACE)): + if p['device_owner'] not in l3_constants.ROUTER_INTERFACE_OWNERS: for fixed_ip in p['fixed_ips']: self._update_arp_entry(ri, fixed_ip['ip_address'], p['mac_address'], diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 773b9eb2c..ff8c1a654 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -736,8 +736,7 @@ class Dnsmasq(DhcpLocalProcess): subnets = dict((subnet.id, subnet) for subnet in network.subnets) for port in network.ports: - if port.device_owner not in (constants.DEVICE_OWNER_ROUTER_INTF, - constants.DEVICE_OWNER_DVR_INTERFACE): + if port.device_owner not in constants.ROUTER_INTERFACE_OWNERS: continue for alloc in port.fixed_ips: if subnets[alloc.subnet_id].gateway_ip == alloc.ip_address: diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index b52b46dfb..fef96e92d 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -179,9 +179,7 @@ class MetadataProxyHandler(object): filters = {} if router_id: filters['device_id'] = [router_id] - filters['device_owner'] = [ - n_const.DEVICE_OWNER_ROUTER_INTF, - n_const.DEVICE_OWNER_DVR_INTERFACE] + filters['device_owner'] = n_const.ROUTER_INTERFACE_OWNERS if ip_address: filters['fixed_ips'] = {'ip_address': [ip_address]} if networks: diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 687bf500b..bdaac61a0 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -39,6 +39,11 @@ DEVICE_OWNER_AGENT_GW = "network:floatingip_agent_gateway" DEVICE_OWNER_ROUTER_SNAT = "network:router_centralized_snat" DEVICE_OWNER_LOADBALANCER = "neutron:LOADBALANCER" +# Collection used to identify devices owned by router interfaces. +# DEVICE_OWNER_ROUTER_HA_INTF is a special case and so is not included. +ROUTER_INTERFACE_OWNERS = (DEVICE_OWNER_ROUTER_INTF, + DEVICE_OWNER_DVR_INTERFACE) + DEVICE_ID_RESERVED_DHCP_PORT = "reserved_dhcp_port" FLOATINGIP_KEY = '_floatingips' diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 0aafa8265..11ff00eb9 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -446,8 +446,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, 'subnet') % fixed['ip_address'] raise n_exc.InvalidInput(error_message=msg) if (ipv6_utils.is_slaac_subnet(subnet) and device_owner not in - (constants.DEVICE_OWNER_ROUTER_INTF, - constants.DEVICE_OWNER_DVR_INTERFACE)): + constants.ROUTER_INTERFACE_OWNERS): msg = (_("IPv6 address %(address)s can not be directly " "assigned to a port on subnet %(id)s with " "%(mode)s address mode") % diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index c146eda36..d3974db8f 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -156,9 +156,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, return router_intf_qry.filter( models_v2.Port.network_id == network_id, - l3_db.RouterPort.port_type.in_( - [l3_const.DEVICE_OWNER_ROUTER_INTF, DEVICE_OWNER_DVR_INTERFACE] - ) + l3_db.RouterPort.port_type.in_(l3_const.ROUTER_INTERFACE_OWNERS) ) def update_floatingip(self, context, id, floatingip): @@ -377,8 +375,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, def get_sync_data(self, context, router_ids=None, active=None): routers, interfaces, floating_ips = self._get_router_info_list( context, router_ids=router_ids, active=active, - device_owners=[l3_const.DEVICE_OWNER_ROUTER_INTF, - DEVICE_OWNER_DVR_INTERFACE]) + device_owners=l3_const.ROUTER_INTERFACE_OWNERS) # Add the port binding host to the floatingip dictionary for fip in floating_ips: fip['host'] = self.get_vm_port_hostid(context, fip['port_id']) diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py index 88f80f752..eb241fc36 100644 --- a/neutron/db/securitygroups_rpc_base.py +++ b/neutron/db/securitygroups_rpc_base.py @@ -14,7 +14,6 @@ # under the License. import netaddr -from sqlalchemy import or_ from sqlalchemy.orm import exc from neutron.common import constants as q_const @@ -352,10 +351,8 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): models_v2.IPAllocation.subnet_id == subnet['id']) query = query.filter( models_v2.IPAllocation.ip_address == subnet['gateway_ip']) - query = query.filter(or_(models_v2.Port.device_owner == - q_const.DEVICE_OWNER_ROUTER_INTF, - models_v2.Port.device_owner == - q_const.DEVICE_OWNER_DVR_INTERFACE)) + query = query.filter( + models_v2.Port.device_owner.in_(q_const.ROUTER_INTERFACE_OWNERS)) try: mac_address = query.one()[0] except (exc.NoResultFound, exc.MultipleResultsFound): diff --git a/neutron/tests/unit/test_metadata_agent.py b/neutron/tests/unit/test_metadata_agent.py index ea87913da..1d7f4beaa 100644 --- a/neutron/tests/unit/test_metadata_agent.py +++ b/neutron/tests/unit/test_metadata_agent.py @@ -25,12 +25,6 @@ from neutron.common import utils from neutron.tests import base -EXPECTED_OWNER_ROUTERS = [ - constants.DEVICE_OWNER_ROUTER_INTF, - constants.DEVICE_OWNER_DVR_INTERFACE -] - - class FakeConf(object): admin_user = 'neutron' admin_password = 'password' @@ -73,7 +67,7 @@ class TestMetadataProxyHandlerRpc(TestMetadataProxyHandlerBase): ip = '1.2.3.4' networks = ('net_id1', 'net_id2') expected = {'device_id': [router_id], - 'device_owner': EXPECTED_OWNER_ROUTERS, + 'device_owner': constants.ROUTER_INTERFACE_OWNERS, 'network_id': networks, 'fixed_ips': {'ip_address': [ip]}} actual = self.handler._get_port_filters(router_id, ip, networks) @@ -159,7 +153,7 @@ class TestMetadataProxyHandlerCache(TestMetadataProxyHandlerBase): networks = self.handler._get_router_networks(router_id) mock_list_ports.assert_called_once_with( device_id=router_id, - device_owner=EXPECTED_OWNER_ROUTERS) + device_owner=constants.ROUTER_INTERFACE_OWNERS) self.assertEqual(expected, networks) def _test_get_router_networks_twice_helper(self): @@ -174,7 +168,7 @@ class TestMetadataProxyHandlerCache(TestMetadataProxyHandlerBase): networks = self.handler._get_router_networks(router_id) mock_list_ports.assert_called_once_with( device_id=router_id, - device_owner=EXPECTED_OWNER_ROUTERS) + device_owner=constants.ROUTER_INTERFACE_OWNERS) self.assertEqual(expected_networks, networks) networks = self.handler._get_router_networks(router_id) @@ -275,7 +269,7 @@ class TestMetadataProxyHandlerCache(TestMetadataProxyHandlerBase): new_qclient_call, mock.call().list_ports( device_id=router_id, - device_owner=EXPECTED_OWNER_ROUTERS + device_owner=constants.ROUTER_INTERFACE_OWNERS ), mock.call().get_auth_info() ]) @@ -409,7 +403,7 @@ class TestMetadataProxyHandlerCache(TestMetadataProxyHandlerBase): new_qclient_call, mock.call().list_ports( device_id=router_id, - device_owner=EXPECTED_OWNER_ROUTERS + device_owner=constants.ROUTER_INTERFACE_OWNERS ), mock.call().get_auth_info(), cached_qclient_call,