Fix enable_metadata_network flag
The following patch:9569b2fe
broke the desired functionality of the enable_metadata_network flag, by not allowing the metadata proxy to be spawn for 'metadata networks', which are used for accessing the metadata service when the logical router is not implemented through the l3 agent. This patch enables spawning of the metadata proxy for metadata networks when the appropriate flag is set to True. The patch also adds rather pedant unit test coverage for the should_enable_metadata method which previously had no unit test. Closes-bug: 1394020 (cherry picked from commitc45842af38
) Conflicts: neutron/agent/dhcp_agent.py neutron/tests/unit/test_linux_dhcp.py Change-Id: I8dca1fce9fbc83e75ba7e4ce948531427bf7e88b
This commit is contained in:
parent
dbc1ab2904
commit
5495f2b056
@ -18,7 +18,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
import netaddr
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from neutron.agent.common import config
|
from neutron.agent.common import config
|
||||||
@ -326,10 +326,9 @@ class DhcpAgent(manager.Manager):
|
|||||||
# or all the networks connected via a router
|
# or all the networks connected via a router
|
||||||
# to the one passed as a parameter
|
# to the one passed as a parameter
|
||||||
neutron_lookup_param = '--network_id=%s' % network.id
|
neutron_lookup_param = '--network_id=%s' % network.id
|
||||||
meta_cidr = netaddr.IPNetwork(dhcp.METADATA_DEFAULT_CIDR)
|
# When the metadata network is enabled, the proxy might
|
||||||
has_metadata_subnet = any(netaddr.IPNetwork(s.cidr) in meta_cidr
|
# be started for the router attached to the network
|
||||||
for s in network.subnets)
|
if self.conf.enable_metadata_network:
|
||||||
if (self.conf.enable_metadata_network and has_metadata_subnet):
|
|
||||||
router_ports = [port for port in network.ports
|
router_ports = [port for port in network.ports
|
||||||
if (port.device_owner ==
|
if (port.device_owner ==
|
||||||
constants.DEVICE_OWNER_ROUTER_INTF)]
|
constants.DEVICE_OWNER_ROUTER_INTF)]
|
||||||
|
@ -663,8 +663,25 @@ class Dnsmasq(DhcpLocalProcess):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def should_enable_metadata(cls, conf, network):
|
def should_enable_metadata(cls, conf, network):
|
||||||
"""True if there exists a subnet for which a metadata proxy is needed
|
"""Determine whether the metadata proxy is needed for a network
|
||||||
|
|
||||||
|
This method returns True for truly isolated networks (ie: not attached
|
||||||
|
to a router), when the enable_isolated_metadata flag is True.
|
||||||
|
|
||||||
|
This method also returns True when enable_metadata_network is True,
|
||||||
|
and the network passed as a parameter has a subnet in the link-local
|
||||||
|
CIDR, thus characterizing it as a "metadata" network. The metadata
|
||||||
|
network is used by solutions which do not leverage the l3 agent for
|
||||||
|
providing access to the metadata service via logical routers built
|
||||||
|
with 3rd party backends.
|
||||||
"""
|
"""
|
||||||
|
if conf.enable_metadata_network and conf.enable_isolated_metadata:
|
||||||
|
# check if the network has a metadata subnet
|
||||||
|
meta_cidr = netaddr.IPNetwork(METADATA_DEFAULT_CIDR)
|
||||||
|
if any(netaddr.IPNetwork(s.cidr) in meta_cidr
|
||||||
|
for s in network.subnets):
|
||||||
|
return True
|
||||||
|
|
||||||
if not conf.use_namespaces or not conf.enable_isolated_metadata:
|
if not conf.use_namespaces or not conf.enable_isolated_metadata:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -83,12 +83,12 @@ class FakeRouterPort:
|
|||||||
id = 'rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr'
|
id = 'rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr'
|
||||||
admin_state_up = True
|
admin_state_up = True
|
||||||
device_owner = constants.DEVICE_OWNER_ROUTER_INTF
|
device_owner = constants.DEVICE_OWNER_ROUTER_INTF
|
||||||
fixed_ips = [FakeIPAllocation('192.168.0.1',
|
|
||||||
'dddddddd-dddd-dddd-dddd-dddddddddddd')]
|
|
||||||
mac_address = '00:00:0f:rr:rr:rr'
|
mac_address = '00:00:0f:rr:rr:rr'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, ip_address='192.168.0.1'):
|
||||||
self.extra_dhcp_opts = []
|
self.extra_dhcp_opts = []
|
||||||
|
self.fixed_ips = [FakeIPAllocation(
|
||||||
|
ip_address, 'dddddddd-dddd-dddd-dddd-dddddddddddd')]
|
||||||
|
|
||||||
|
|
||||||
class FakePortMultipleAgents1:
|
class FakePortMultipleAgents1:
|
||||||
@ -140,6 +140,16 @@ class FakeV4Subnet:
|
|||||||
dns_nameservers = ['8.8.8.8']
|
dns_nameservers = ['8.8.8.8']
|
||||||
|
|
||||||
|
|
||||||
|
class FakeV4MetadataSubnet:
|
||||||
|
id = 'dddddddd-dddd-dddd-dddd-dddddddddddd'
|
||||||
|
ip_version = 4
|
||||||
|
cidr = '169.254.169.254/30'
|
||||||
|
gateway_ip = '169.254.169.253'
|
||||||
|
enable_dhcp = True
|
||||||
|
host_routes = []
|
||||||
|
dns_nameservers = []
|
||||||
|
|
||||||
|
|
||||||
class FakeV4SubnetGatewayRoute:
|
class FakeV4SubnetGatewayRoute:
|
||||||
id = 'dddddddd-dddd-dddd-dddd-dddddddddddd'
|
id = 'dddddddd-dddd-dddd-dddd-dddddddddddd'
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
@ -273,6 +283,12 @@ class FakeV4NetworkNoRouter:
|
|||||||
ports = [FakePort1()]
|
ports = [FakePort1()]
|
||||||
|
|
||||||
|
|
||||||
|
class FakeV4MetadataNetwork:
|
||||||
|
id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
|
||||||
|
subnets = [FakeV4MetadataSubnet()]
|
||||||
|
ports = [FakeRouterPort(ip_address='169.254.169.253')]
|
||||||
|
|
||||||
|
|
||||||
class FakeDualV4Pxe3Ports:
|
class FakeDualV4Pxe3Ports:
|
||||||
id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
|
id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
|
||||||
subnets = [FakeV4Subnet(), FakeV4SubnetNoDHCP()]
|
subnets = [FakeV4Subnet(), FakeV4SubnetNoDHCP()]
|
||||||
@ -397,13 +413,15 @@ class TestBase(base.BaseTestCase):
|
|||||||
self.conf.register_opts(base_config.core_opts)
|
self.conf.register_opts(base_config.core_opts)
|
||||||
self.conf.register_opts(dhcp.OPTS)
|
self.conf.register_opts(dhcp.OPTS)
|
||||||
config.register_interface_driver_opts_helper(self.conf)
|
config.register_interface_driver_opts_helper(self.conf)
|
||||||
|
config.register_use_namespaces_opts_helper(self.conf)
|
||||||
instance = mock.patch("neutron.agent.linux.dhcp.DeviceManager")
|
instance = mock.patch("neutron.agent.linux.dhcp.DeviceManager")
|
||||||
self.mock_mgr = instance.start()
|
self.mock_mgr = instance.start()
|
||||||
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
|
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
|
||||||
default=True))
|
default=True))
|
||||||
|
self.conf.register_opt(cfg.BoolOpt('enable_metadata_network',
|
||||||
|
default=False))
|
||||||
self.conf(args=args)
|
self.conf(args=args)
|
||||||
self.conf.set_override('state_path', '')
|
self.conf.set_override('state_path', '')
|
||||||
self.conf.use_namespaces = True
|
|
||||||
|
|
||||||
self.replace_p = mock.patch('neutron.agent.linux.utils.replace_file')
|
self.replace_p = mock.patch('neutron.agent.linux.utils.replace_file')
|
||||||
self.execute_p = mock.patch('neutron.agent.linux.utils.execute')
|
self.execute_p = mock.patch('neutron.agent.linux.utils.execute')
|
||||||
@ -1244,3 +1262,26 @@ tag:tag0,option:router""".lstrip()
|
|||||||
|
|
||||||
def test_check_version_failed_cmd_execution(self):
|
def test_check_version_failed_cmd_execution(self):
|
||||||
self._check_version('Error while executing command', 0)
|
self._check_version('Error while executing command', 0)
|
||||||
|
|
||||||
|
def test_should_enable_metadata_namespaces_disabled_returns_false(self):
|
||||||
|
self.conf.set_override('use_namespaces', False)
|
||||||
|
self.assertFalse(dhcp.Dnsmasq.should_enable_metadata(self.conf,
|
||||||
|
mock.ANY))
|
||||||
|
|
||||||
|
def test_should_enable_metadata_isolated_network_returns_true(self):
|
||||||
|
self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(
|
||||||
|
self.conf, FakeV4NetworkNoRouter()))
|
||||||
|
|
||||||
|
def test_should_enable_metadata_non_isolated_network_returns_false(self):
|
||||||
|
self.assertFalse(dhcp.Dnsmasq.should_enable_metadata(
|
||||||
|
self.conf, FakeV4MetadataNetwork()))
|
||||||
|
|
||||||
|
def test_should_enable_metadata_isolated_meta_disabled_returns_false(self):
|
||||||
|
self.conf.set_override('enable_isolated_metadata', False)
|
||||||
|
self.assertFalse(dhcp.Dnsmasq.should_enable_metadata(self.conf,
|
||||||
|
mock.ANY))
|
||||||
|
|
||||||
|
def test_should_enable_metadata_with_metadata_network_returns_true(self):
|
||||||
|
self.conf.set_override('enable_metadata_network', True)
|
||||||
|
self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(
|
||||||
|
self.conf, FakeV4MetadataNetwork()))
|
||||||
|
Loading…
Reference in New Issue
Block a user