]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add a constant for router interface device owners
authorMaru Newby <marun@redhat.com>
Tue, 28 Oct 2014 19:50:31 +0000 (19:50 +0000)
committerMaru Newby <marun@redhat.com>
Wed, 31 Dec 2014 02:17:19 +0000 (18:17 -0800)
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

neutron/agent/l3/agent.py
neutron/agent/linux/dhcp.py
neutron/agent/metadata/agent.py
neutron/common/constants.py
neutron/db/db_base_plugin_v2.py
neutron/db/l3_dvr_db.py
neutron/db/securitygroups_rpc_base.py
neutron/tests/unit/test_metadata_agent.py

index 98953e5265fabcd0ec7293d559935ea6977589b5..ca3a27bba6867776eae654aee936fa4764fa1598 100644 (file)
@@ -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'],
index 773b9eb2c01de416bc3b81f9c61939a12528144c..ff8c1a6541a00e5abda0c7a2482f04fb99ace82b 100644 (file)
@@ -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:
index b52b46dfbb229f91509ed546075b41f18c0fb993..fef96e92ddf9e9accf046813ade4de1e81f52dba 100644 (file)
@@ -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:
index 687bf500b86cbf8932c75a6e6d1a7526fa14bf05..bdaac61a01772d7b138e568d5338587d141a5db6 100644 (file)
@@ -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'
index 0aafa8265b250d418b3fac647d4ea0b039e49cdf..11ff00eb9205732ed52981572d7773b88485188b 100644 (file)
@@ -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") %
index c146eda36d43090b0e1b90c92d71c8151eefb9d9..d3974db8f780bf6fa0a829a0373d1c1f684493fa 100644 (file)
@@ -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'])
index 88f80f7528b247ebb6513a01671801e6a42fceea..eb241fc36dcefcc2e50bbfdedfef65efb61c0985 100644 (file)
@@ -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):
index ea87913da6cccba092eee0ba8356abcb991eccad..1d7f4beaaec50a31da5d968f4d1f937da17cd672 100644 (file)
@@ -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,