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'],
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:
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:
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'
'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") %
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):
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'])
# under the License.
import netaddr
-from sqlalchemy import or_
from sqlalchemy.orm import exc
from neutron.common import constants as q_const
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):
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'
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)
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):
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)
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()
])
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,