Browse Source

Use metadata constants from n-lib

Change-Id: I8045d1670045a68c955b0bf95077137ea07fd72e
Partial-Bug: #1460177
changes/05/745705/4
Bence Romsics 8 months ago
committed by Slawek Kaplonski
parent
commit
3f30727c0a
11 changed files with 27 additions and 41 deletions
  1. +3
    -3
      neutron/agent/dhcp/agent.py
  2. +6
    -4
      neutron/agent/l3/router_info.py
  3. +2
    -9
      neutron/agent/linux/dhcp.py
  4. +2
    -3
      neutron/agent/metadata/driver.py
  5. +2
    -2
      neutron/agent/ovn/metadata/agent.py
  6. +0
    -5
      neutron/common/ovn/constants.py
  7. +2
    -2
      neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py
  8. +3
    -3
      neutron/tests/functional/agent/l3/test_metadata_proxy.py
  9. +5
    -7
      neutron/tests/unit/agent/dhcp/test_agent.py
  10. +1
    -1
      neutron/tests/unit/agent/linux/test_dhcp.py
  11. +1
    -2
      neutron/tests/unit/agent/ovn/metadata/test_agent.py

+ 3
- 3
neutron/agent/dhcp/agent.py View File

@ -747,7 +747,7 @@ class DhcpAgent(manager.Manager):
]
if len(dhcp_ifaces) == 1:
kwargs['bind_interface'] = dhcp_ifaces[0]
kwargs['bind_address_v6'] = dhcp.METADATA_V6_IP
kwargs['bind_address_v6'] = constants.METADATA_V6_IP
else:
LOG.error(
'Unexpected number of DHCP interfaces for metadata '
@ -761,8 +761,8 @@ class DhcpAgent(manager.Manager):
self.dhcp_driver_class)
metadata_driver.MetadataDriver.spawn_monitored_metadata_proxy(
self._process_monitor, network.namespace, dhcp.METADATA_PORT,
self.conf, bind_address=dhcp.METADATA_DEFAULT_IP, **kwargs)
self._process_monitor, network.namespace, constants.METADATA_PORT,
self.conf, bind_address=constants.METADATA_V4_IP, **kwargs)
def disable_isolated_metadata_proxy(self, network):
if (self.conf.enable_metadata_network and


+ 6
- 4
neutron/agent/l3/router_info.py View File

@ -1079,11 +1079,12 @@ class RouterInfo(BaseRouterInfo):
# requests that arrive before the filter metadata redirect
# rule is installed will be dropped.
mark_metadata_for_internal_interfaces = (
'-d 169.254.169.254/32 '
'-d %(metadata_cidr)s '
'-i %(interface_name)s '
'-p tcp -m tcp --dport 80 '
'-j MARK --set-xmark %(value)s/%(mask)s' %
{'interface_name': INTERNAL_DEV_PREFIX + '+',
{'metadata_cidr': lib_constants.METADATA_V4_CIDR,
'interface_name': INTERNAL_DEV_PREFIX + '+',
'value': self.agent_conf.metadata_access_mark,
'mask': lib_constants.ROUTER_MARK_MASK})
self.iptables_manager.ipv4['mangle'].add_rule(
@ -1091,11 +1092,12 @@ class RouterInfo(BaseRouterInfo):
if netutils.is_ipv6_enabled():
mark_metadata_v6_for_internal_interfaces = (
'-d fe80::a9fe:a9fe/128 '
'-d %(metadata_v6_ip)s/128 '
'-i %(interface_name)s '
'-p tcp -m tcp --dport 80 '
'-j MARK --set-xmark %(value)s/%(mask)s' %
{'interface_name': INTERNAL_DEV_PREFIX + '+',
{'metadata_v6_ip': lib_constants.METADATA_V6_IP,
'interface_name': INTERNAL_DEV_PREFIX + '+',
'value': self.agent_conf.metadata_access_mark,
'mask': lib_constants.ROUTER_MARK_MASK})
self.iptables_manager.ipv6['mangle'].add_rule(


+ 2
- 9
neutron/agent/linux/dhcp.py View File

@ -48,13 +48,6 @@ from neutron.privileged.agent.linux import dhcp as priv_dhcp
LOG = logging.getLogger(__name__)
DNS_PORT = 53
# TODO(bence romsics): use the rehomed constants when they get released:
# https://review.opendev.org/738205
METADATA_DEFAULT_IP = '169.254.169.254'
METADATA_SUBNET_CIDR = '169.254.0.0/16'
METADATA_V6_IP = 'fe80::a9fe:a9fe'
METADATA_V6_CIDR = 'fe80::a9fe:a9fe/64'
METADATA_PORT = 80
WIN2k3_STATIC_DNS = 249
NS_PREFIX = 'qdhcp-'
DNSMASQ_SERVICE_NAME = 'dnsmasq'
@ -1316,7 +1309,7 @@ class Dnsmasq(DhcpLocalProcess):
@staticmethod
def has_metadata_subnet(subnets):
"""Check if the subnets has a metadata subnet."""
meta_cidr = netaddr.IPNetwork(METADATA_SUBNET_CIDR)
meta_cidr = netaddr.IPNetwork(constants.METADATA_V4_SUBNET)
if any(netaddr.IPNetwork(s.cidr) in meta_cidr
for s in subnets):
return True
@ -1721,7 +1714,7 @@ class DeviceManager(object):
if self.conf.force_metadata or self.conf.enable_isolated_metadata:
ip_cidrs.append(constants.METADATA_CIDR)
if netutils.is_ipv6_enabled():
ip_cidrs.append(METADATA_V6_CIDR)
ip_cidrs.append(constants.METADATA_V6_CIDR)
self.driver.init_l3(interface_name, ip_cidrs,
namespace=network.namespace)


+ 2
- 3
neutron/agent/metadata/driver.py View File

@ -30,7 +30,6 @@ from oslo_utils import netutils
from neutron._i18n import _
from neutron.agent.l3 import ha_router
from neutron.agent.l3 import namespaces
from neutron.agent.linux import dhcp
from neutron.agent.linux import external_process
from neutron.agent.linux import ip_lib
@ -208,7 +207,7 @@ class MetadataDriver(object):
@classmethod
def metadata_nat_rules(
cls, port, metadata_address=(dhcp.METADATA_DEFAULT_IP + '/32')):
cls, port, metadata_address=constants.METADATA_V4_CIDR):
return [('PREROUTING', '-d %(metadata_address)s '
'-i %(interface_name)s '
'-p tcp -m tcp --dport 80 -j REDIRECT '
@ -314,7 +313,7 @@ def after_router_added(resource, event, l3_agent, **kwargs):
if ipv6_enabled:
for c, r in proxy.metadata_nat_rules(
proxy.metadata_port,
metadata_address=(dhcp.METADATA_V6_IP + '/128')):
metadata_address=(constants.METADATA_V6_IP + '/128')):
router.iptables_manager.ipv6['nat'].add_rule(c, r)
router.iptables_manager.apply()


+ 2
- 2
neutron/agent/ovn/metadata/agent.py View File

@ -470,8 +470,8 @@ class MetadataAgent(object):
# Spawn metadata proxy if it's not already running.
metadata_driver.MetadataDriver.spawn_monitored_metadata_proxy(
self._process_monitor, namespace, ovn_const.METADATA_PORT,
self.conf, bind_address=ovn_const.METADATA_DEFAULT_IP,
self._process_monitor, namespace, n_const.METADATA_PORT,
self.conf, bind_address=n_const.METADATA_V4_IP,
network_id=datapath)
self.update_chassis_metadata_networks(datapath)


+ 0
- 5
neutron/common/ovn/constants.py View File

@ -278,11 +278,6 @@ LSP_OPTIONS_VIRTUAL_IP_KEY = 'virtual-ip'
HA_CHASSIS_GROUP_DEFAULT_NAME = 'default_ha_chassis_group'
HA_CHASSIS_GROUP_HIGHEST_PRIORITY = 32767
# TODO(lucasagomes): Move this to neutron-lib later.
# Metadata constants
METADATA_DEFAULT_IP = '169.254.169.254'
METADATA_PORT = 80
# OVN igmp options
MCAST_SNOOP = 'mcast_snoop'
MCAST_FLOOD_UNREGISTERED = 'mcast_flood_unregistered'


+ 2
- 2
neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py View File

@ -1816,8 +1816,8 @@ class OVNClient(object):
routes = []
if metadata_port_ip:
routes.append('%s/32,%s' % (
ovn_const.METADATA_DEFAULT_IP, metadata_port_ip))
routes.append('%s,%s' % (
const.METADATA_V4_CIDR, metadata_port_ip))
# Add subnet host_routes to 'classless_static_route' dhcp option
routes.extend(['%s,%s' % (route['destination'], route['nexthop'])


+ 3
- 3
neutron/tests/functional/agent/l3/test_metadata_proxy.py View File

@ -15,11 +15,11 @@
import os.path
import time
from neutron_lib import constants
import webob
import webob.dec
import webob.exc
from neutron.agent.linux import dhcp
from neutron.agent.linux import utils
from neutron.tests.common import machine_fixtures
from neutron.tests.common import net_helpers
@ -59,8 +59,8 @@ class MetadataL3AgentTestCase(framework.L3AgentTestFramework):
workers=0, backlog=4096, mode=self.SOCKET_MODE)
def _query_metadata_proxy(self, machine):
url = 'http://%(host)s:%(port)s' % {'host': dhcp.METADATA_DEFAULT_IP,
'port': dhcp.METADATA_PORT}
url = 'http://%(host)s:%(port)s' % {'host': constants.METADATA_V4_IP,
'port': constants.METADATA_PORT}
cmd = 'curl', '--max-time', METADATA_REQUEST_TIMEOUT, '-D-', url
i = 0
CONNECTION_REFUSED_TIMEOUT = METADATA_REQUEST_TIMEOUT // 2


+ 5
- 7
neutron/tests/unit/agent/dhcp/test_agent.py View File

@ -217,8 +217,6 @@ fake_down_network = dhcp.NetModel(id='12345678-dddd-dddd-1234567890ab',
class TestDhcpAgent(base.BaseTestCase):
METADATA_DEFAULT_IP = dhcp.METADATA_DEFAULT_IP
def setUp(self):
super(TestDhcpAgent, self).setUp()
entry.register_options(cfg.CONF)
@ -580,7 +578,7 @@ class TestDhcpAgent(base.BaseTestCase):
dhcp.configure_dhcp_for_network(fake_network)
md_cls.spawn_monitored_metadata_proxy.assert_called_once_with(
mock.ANY, mock.ANY, mock.ANY, mock.ANY,
bind_address=self.METADATA_DEFAULT_IP,
bind_address=const.METADATA_V4_IP,
network_id=fake_network.id)
md_cls.reset_mock()
dhcp.disable_dhcp_helper(fake_network.id)
@ -599,7 +597,7 @@ class TestDhcpAgent(base.BaseTestCase):
mock.ANY, fake_network.id, mock.ANY, fake_network.namespace)
md_cls.spawn_monitored_metadata_proxy.assert_called_once_with(
mock.ANY, mock.ANY, mock.ANY, mock.ANY,
bind_address=self.METADATA_DEFAULT_IP,
bind_address=const.METADATA_V4_IP,
network_id=fake_network.id)
def test_report_state_revival_logic(self):
@ -1001,10 +999,10 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
'.spawn_monitored_metadata_proxy')
with mock.patch(method_path) as spawn:
self.dhcp.enable_isolated_metadata_proxy(network)
metadata_ip = dhcp.METADATA_DEFAULT_IP
metadata_ip = const.METADATA_V4_IP
spawn.assert_called_once_with(self.dhcp._process_monitor,
network.namespace,
dhcp.METADATA_PORT,
const.METADATA_PORT,
cfg.CONF,
bind_address=metadata_ip,
router_id='forzanapoli')
@ -1031,7 +1029,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
self.dhcp.enable_isolated_metadata_proxy(network)
spawn.assert_called_once_with(self.dhcp._process_monitor,
network.namespace,
dhcp.METADATA_PORT,
const.METADATA_PORT,
cfg.CONF,
bind_address='169.254.169.254',
network_id=network.id,


+ 1
- 1
neutron/tests/unit/agent/linux/test_dhcp.py View File

@ -3153,7 +3153,7 @@ class TestDeviceManager(TestConfBase):
if enable_isolated_metadata or force_metadata:
expect_ips.extend([
constants.METADATA_CIDR,
dhcp.METADATA_V6_CIDR])
constants.METADATA_V6_CIDR])
mgr.driver.init_l3.assert_called_with('ns-XXX',
expect_ips,
namespace='qdhcp-ns')


+ 1
- 2
neutron/tests/unit/agent/ovn/metadata/test_agent.py View File

@ -26,7 +26,6 @@ from neutron.agent.linux.ip_lib import IpNetnsCommand as ip_netns
from neutron.agent.linux.ip_lib import IPWrapper as ip_wrap
from neutron.agent.ovn.metadata import agent
from neutron.agent.ovn.metadata import driver
from neutron.common.ovn import constants as ovn_const
from neutron.conf.agent.metadata import config as meta_conf
from neutron.conf.agent.ovn.metadata import config as ovn_meta_conf
from neutron.tests import base
@ -266,7 +265,7 @@ class TestMetadataAgent(base.BaseTestCase):
# Check that metadata proxy has been spawned
spawn_mdp.assert_called_once_with(
mock.ANY, 'namespace', 80, mock.ANY,
bind_address=ovn_const.METADATA_DEFAULT_IP, network_id='1')
bind_address=n_const.METADATA_V4_IP, network_id='1')
# Check that the chassis has been updated with the datapath.
update_chassis.assert_called_once_with('1')


Loading…
Cancel
Save