use DVR constants from neutron-lib

The L3_AGENT_MODE_DVR_NO_EXTERNAL and DVR_SNAT_BOUND constants were
rehomed into neutron-lib with Ieb9374f5483a0ab2306592ab901686ca374db1c8
This patch consumes them by removing them from neutron and using the
constants from neutron-lib instead.

NeutronLibImpact

Change-Id: Ib63a523721a2fa3d1a978a729de28e6a2e560ef6
This commit is contained in:
Boden R 2018-02-21 11:44:58 -07:00
parent 8e3730538c
commit f6de54fa4f
13 changed files with 40 additions and 47 deletions

View File

@ -491,7 +491,7 @@ class L3NATAgent(ha.AgentMixin,
def _process_updated_router(self, router):
is_dvr_only_agent = (self.conf.agent_mode in
[lib_const.L3_AGENT_MODE_DVR,
l3_constants.L3_AGENT_MODE_DVR_NO_EXTERNAL])
lib_const.L3_AGENT_MODE_DVR_NO_EXTERNAL])
# For HA routers check that DB state matches actual state
if router.get('ha') and not is_dvr_only_agent:
self.check_ha_state_for_router(

View File

@ -20,7 +20,6 @@ from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import router_info as router
from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_manager
from neutron.common import constants as n_const
LOG = logging.getLogger(__name__)
@ -338,7 +337,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
(fixed_ip, floating_ip))]
def _set_floating_ip_nat_rules_for_centralized_floatingip(self, fip):
if fip.get(n_const.DVR_SNAT_BOUND):
if fip.get(lib_constants.DVR_SNAT_BOUND):
fixed = fip['fixed_ip_address']
fip_ip = fip['floating_ip_address']
for chain, rule in self._centralized_floating_forward_rules(

View File

@ -64,7 +64,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
if not self.fip_ns:
return []
if fip.get(n_const.DVR_SNAT_BOUND):
if fip.get(lib_constants.DVR_SNAT_BOUND):
return []
fixed_ip = fip['fixed_ip_address']
@ -105,7 +105,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
def floating_ip_added_dist(self, fip, fip_cidr):
"""Add floating IP to respective namespace based on agent mode."""
if fip.get(n_const.DVR_SNAT_BOUND):
if fip.get(lib_constants.DVR_SNAT_BOUND):
floating_ip_status = self.add_centralized_floatingip(fip, fip_cidr)
if floating_ip_status == lib_constants.FLOATINGIP_STATUS_ACTIVE:
self.centralized_floatingips_set.add(fip_cidr)
@ -570,7 +570,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
def process_external(self):
if self.agent_conf.agent_mode != (
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
lib_constants.L3_AGENT_MODE_DVR_NO_EXTERNAL):
ex_gw_port = self.get_ex_gw_port()
if ex_gw_port:
self.create_dvr_external_gateway_on_agent(ex_gw_port)

View File

@ -28,7 +28,6 @@ from neutron.api.rpc.callbacks.consumer import registry
from neutron.api.rpc.callbacks import events
from neutron.api.rpc.callbacks import resources
from neutron.api.rpc.handlers import resources_rpc
from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
LOG = logging.getLogger(__name__)
@ -306,7 +305,7 @@ class FipQosAgentExtension(l3_extension.L3AgentExtension):
is_distributed_router = router_info.router.get('distributed')
agent_mode = router_info.agent_conf.agent_mode
if is_distributed_router and agent_mode == (
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL):
# condition 3: dvr local router and dvr_no_external agent
return
device = self._get_rate_limit_ip_device(router_info)

View File

@ -31,8 +31,6 @@ HA_ROUTER_STATE_KEY = '_ha_state'
METERING_LABEL_KEY = '_metering_labels'
FLOATINGIP_AGENT_INTF_KEY = '_floatingip_agent_interfaces'
SNAT_ROUTER_INTF_KEY = '_snat_router_interfaces'
DVR_SNAT_BOUND = 'dvr_snat_bound'
L3_AGENT_MODE_DVR_NO_EXTERNAL = 'dvr_no_external'
HA_NETWORK_NAME = 'HA network tenant %s'
HA_SUBNET_NAME = 'HA subnet tenant %s'

View File

@ -18,7 +18,6 @@ from neutron_lib import constants
from oslo_config import cfg
from neutron._i18n import _
from neutron.common import constants as common_consts
from neutron.conf.agent import common as config
@ -27,7 +26,7 @@ OPTS = [
choices=(constants.L3_AGENT_MODE_DVR,
constants.L3_AGENT_MODE_DVR_SNAT,
constants.L3_AGENT_MODE_LEGACY,
common_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL),
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL),
help=_("The working mode for the agent. Allowed modes are: "
"'legacy' - this preserves the existing behavior "
"where the L3 agent is deployed on a centralized "

View File

@ -22,7 +22,6 @@ from oslo_log import log as logging
import oslo_messaging
from neutron.agent.common import utils as agent_utils
from neutron.common import constants as l_consts
from neutron.common import utils as n_utils
from neutron.conf.db import l3_agentschedulers_db
from neutron.db import agentschedulers_db
@ -95,7 +94,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
agent_mode = self._get_agent_mode(agent)
if agent_mode in [constants.L3_AGENT_MODE_DVR,
l_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL]:
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL]:
raise l3agentscheduler.DVRL3CannotAssignToDvrAgent()
if (agent_mode == constants.L3_AGENT_MODE_LEGACY and
@ -182,7 +181,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
agent = self._get_agent(context, agent_id)
agent_mode = self._get_agent_mode(agent)
if agent_mode in [constants.L3_AGENT_MODE_DVR,
l_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL]:
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL]:
raise l3agentscheduler.DVRL3CannotRemoveFromDvrAgent()
self._unbind_router(context, router_id, agent_id)
@ -420,7 +419,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
constants.L3_AGENT_MODE_LEGACY)
if (agent_mode == constants.L3_AGENT_MODE_DVR or
agent_mode == l_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL or
agent_mode == constants.L3_AGENT_MODE_DVR_NO_EXTERNAL or
(agent_mode == constants.L3_AGENT_MODE_LEGACY and
is_router_distributed)):
continue

View File

@ -667,7 +667,7 @@ class _DVRAgentInterfaceMixin(object):
agent_mode = self._get_agent_mode(agent)
if (agent_mode in [const.L3_AGENT_MODE_LEGACY,
const.L3_AGENT_MODE_DVR] and
floating_ip.get(l3_const.DVR_SNAT_BOUND)):
floating_ip.get(const.DVR_SNAT_BOUND)):
return True
# Skip if it is bound, but not to the given host
@ -739,11 +739,11 @@ class _DVRAgentInterfaceMixin(object):
# agent on re-syncs then we need to add the appropriate
# port['agent'] before updating the dict.
if (l3_agent_mode == (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL) and
const.L3_AGENT_MODE_DVR_NO_EXTERNAL) and
requesting_agent_mode == (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL)):
const.L3_AGENT_MODE_DVR_NO_EXTERNAL)):
port['agent'] = (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL)
const.L3_AGENT_MODE_DVR_NO_EXTERNAL)
port_dict.update({port['id']: port})
# Consider the ports where the portbinding host and
@ -753,11 +753,11 @@ class _DVRAgentInterfaceMixin(object):
# the portbinding host resides in dvr_no_external
# agent then include the port.
if (l3_agent_mode == (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL) and
const.L3_AGENT_MODE_DVR_NO_EXTERNAL) and
requesting_agent_mode == (
const.L3_AGENT_MODE_DVR_SNAT)):
port['agent'] = (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL)
const.L3_AGENT_MODE_DVR_NO_EXTERNAL)
port_dict.update({port['id']: port})
# Add the port binding host to the floatingip dictionary
for fip in floating_ips:
@ -774,7 +774,7 @@ class _DVRAgentInterfaceMixin(object):
context, fip['port_id'], port=vm_port))
vm_port_agent_mode = vm_port.get('agent', None)
if vm_port_agent_mode != (
l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
# For floatingip configured on ports that do not
# reside on a 'dvr_no_external' agent, add the
# fip host binding, else it will be created
@ -784,7 +784,7 @@ class _DVRAgentInterfaceMixin(object):
# for the private ports that are associated with
# floating ip.
if fip['host'] == l3_const.FLOATING_IP_HOST_NEEDS_BINDING:
fip[l3_const.DVR_SNAT_BOUND] = True
fip[const.DVR_SNAT_BOUND] = True
routers_dict = self._process_routers(context, routers, agent)
self._process_floating_ips_dvr(context, routers_dict,
floating_ips, host, agent)
@ -863,7 +863,7 @@ class _DVRAgentInterfaceMixin(object):
l3_agent_db = self._get_agent_by_type_and_host(
context, const.AGENT_TYPE_L3, host)
l3_agent_mode = self._get_agent_mode(l3_agent_db)
if l3_agent_mode == l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL:
if l3_agent_mode == const.L3_AGENT_MODE_DVR_NO_EXTERNAL:
return
if l3_agent_db:
LOG.debug("Agent ID exists: %s", l3_agent_db['id'])
@ -1046,7 +1046,7 @@ class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin,
l3_agent_on_host = self.get_dvr_agent_on_host(
context, host)
agent_mode = self._get_agent_mode(l3_agent_on_host[0])
if agent_mode == l3_const.L3_AGENT_MODE_DVR_NO_EXTERNAL:
if agent_mode == const.L3_AGENT_MODE_DVR_NO_EXTERNAL:
# If the agent hosting the fixed port is in
# 'dvr_no_external' mode, then set the host to None,
# since we would be centralizing the floatingip for

View File

@ -23,7 +23,6 @@ from neutron_lib.plugins import directory
from oslo_log import log as logging
from sqlalchemy import or_
from neutron.common import constants as l3_consts
from neutron.common import utils as n_utils
from neutron.db import agentschedulers_db
@ -320,7 +319,7 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
# dvr serviceable ports, so need special handling
if (self._get_agent_mode(agent_db) in
[n_const.L3_AGENT_MODE_DVR,
l3_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL,
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL,
n_const.L3_AGENT_MODE_DVR_SNAT]):
if not router_ids:
result_set |= set(self._get_dvr_router_ids_for_host(

View File

@ -628,7 +628,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
dvr_agent_mode = (
agent_mode in [constants.L3_AGENT_MODE_DVR_SNAT,
constants.L3_AGENT_MODE_DVR,
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL])
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL])
if (dvr_agent_mode and n_utils.is_extension_supported(
self, constants.L3_DISTRIBUTED_EXT_ALIAS)):
# DVR has to be handled differently

View File

@ -19,7 +19,6 @@ from oslo_utils import uuidutils
from neutron.agent.l3 import agent as neutron_l3_agent
from neutron.agent.l3.extensions import fip_qos
from neutron.common import constants as n_const
from neutron.common import exceptions
from neutron.common import utils as common_utils
from neutron.objects.qos import policy
@ -207,7 +206,7 @@ class TestL3AgentFipQosExtensionDVR(
self._test_dvr_fip_qos(enable_ha=True)
def _test_agent_mode_dvr_no_external(self, enable_ha=False):
self.agent.conf.agent_mode = n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL
self.agent.conf.agent_mode = constants.L3_AGENT_MODE_DVR_NO_EXTERNAL
router_info = self.generate_dvr_router_info(
enable_ha=enable_ha,
enable_floating_ip=True, enable_centralized_fip=True,

View File

@ -469,7 +469,7 @@ class TestDvrRouter(framework.L3AgentTestFramework):
floating_ip['host'] = agent.conf.host
if snat_bound_fip:
floating_ip[n_const.DVR_SNAT_BOUND] = True
floating_ip[lib_constants.DVR_SNAT_BOUND] = True
if enable_floating_ip and enable_centralized_fip:
# For centralizing the fip, we are emulating the legacy
# router behavior were the fip dict does not contain any
@ -1056,7 +1056,8 @@ class TestDvrRouter(framework.L3AgentTestFramework):
def test_floating_ip_not_deployed_on_dvr_no_external_agent(self):
"""Test to check floating ips not configured for dvr_no_external."""
self.agent.conf.agent_mode = n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL
self.agent.conf.agent_mode = (
lib_constants.L3_AGENT_MODE_DVR_NO_EXTERNAL)
router_info = self.generate_dvr_router_info(
enable_floating_ip=True, enable_centralized_fip=True)
router1 = self.manage_router(self.agent, router_info)

View File

@ -342,7 +342,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.context, {'floatingip': floating_ip})
if dvr:
if test_agent_mode == (
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL):
if router['ha']:
expected_calls = [
mock.call(self.context,
@ -373,7 +373,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
def test_create_floating_ip_agent_notification_for_dvr_no_external_agent(
self):
agent_mode = n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL
agent_mode = constants.L3_AGENT_MODE_DVR_NO_EXTERNAL
self._test_create_floating_ip_agent_notification(
test_agent_mode=agent_mode)
@ -438,7 +438,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
{'floatingip': updated_floating_ip})
if dvr:
if test_agent_mode == (
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL):
if router1['ha'] and router2['ha']:
self.assertEqual(
4,
@ -491,7 +491,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
def test_update_floating_ip_agent_notification_with_dvr_no_external_agents(
self):
agent_mode = n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL
agent_mode = constants.L3_AGENT_MODE_DVR_NO_EXTERNAL
self._test_update_floating_ip_agent_notification(
test_agent_mode=agent_mode)
@ -537,7 +537,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.context, floating_ip['id'])
if dvr:
if test_agent_mode == (
n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL):
constants.L3_AGENT_MODE_DVR_NO_EXTERNAL):
if router['ha']:
expected_calls = [
mock.call(self.context,
@ -568,7 +568,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
def test_delete_floating_ip_agent_notification_with_dvr_no_external_agents(
self):
agent_mode = n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL
agent_mode = constants.L3_AGENT_MODE_DVR_NO_EXTERNAL
self._test_delete_floating_ip_agent_notification(
test_agent_mode=agent_mode)
@ -746,7 +746,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, self.l3_agent['host'], [router['id']]))
floatingips = router_info[0][constants.FLOATINGIP_KEY]
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
def test_dvr_process_floatingips_for_dvr_on_full_sync(self):
HOST1 = 'host1'
@ -818,7 +818,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.context, self.l3_agent['host'], [router['id']]))
floatingips = router_info[0][constants.FLOATINGIP_KEY]
self.assertEqual(1, len(floatingips))
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
self.assertEqual(n_const.FLOATING_IP_HOST_NEEDS_BINDING,
floatingips[0]['host'])
router1_info = (
@ -887,7 +887,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, self.l3_agent['host'], [router['id']]))
floatingips = router_info[0][constants.FLOATINGIP_KEY]
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
# Now do the host binding to the fip port
self.core_plugin.update_port(
self.context, int_port1['port']['id'],
@ -901,13 +901,13 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, HOST1, [router['id']]))
floatingips = updated_router_info[0][constants.FLOATINGIP_KEY]
self.assertFalse(floatingips[0].get(n_const.DVR_SNAT_BOUND))
self.assertFalse(floatingips[0].get(constants.DVR_SNAT_BOUND))
self.assertEqual(HOST1, floatingips[0]['host'])
def test_dvr_router_centralized_floating_ip(self):
HOST1 = 'host1'
helpers.register_l3_agent(
host=HOST1, agent_mode=n_const.L3_AGENT_MODE_DVR_NO_EXTERNAL)
host=HOST1, agent_mode=constants.L3_AGENT_MODE_DVR_NO_EXTERNAL)
router = self._create_router(ha=False)
private_net1 = self._make_network(self.fmt, 'net1', True)
kwargs = {'arg_list': (extnet_apidef.EXTERNAL,),
@ -968,7 +968,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, self.l3_agent['host'], [router['id']]))
floatingips = router_info[0][constants.FLOATINGIP_KEY]
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
# Test case to make sure when an agent in this case
# dvr_no_external restarts and does a full sync, we need
# to make sure that the returned router_info has
@ -978,7 +978,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, HOST1, [router['id']]))
floatingips = router_sync_info[0][constants.FLOATINGIP_KEY]
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
def test_allowed_addr_pairs_delayed_fip_and_update_arp_entry(self):
HOST1 = 'host1'
@ -1117,7 +1117,7 @@ class L3DvrTestCase(L3DvrTestCaseBase):
self.l3_plugin.list_active_sync_routers_on_active_l3_agent(
self.context, self.l3_agent['host'], [router['id']]))
floatingips = router_info[0][constants.FLOATINGIP_KEY]
self.assertTrue(floatingips[0][n_const.DVR_SNAT_BOUND])
self.assertTrue(floatingips[0][constants.DVR_SNAT_BOUND])
def test_dvr_gateway_host_binding_is_set(self):
router = self._create_router(ha=False)