Merge "dhcp agent start md-proxy with vrouter id only when has metadata subnet"
This commit is contained in:
commit
10ddc33331
|
@ -505,8 +505,11 @@ class DhcpAgent(manager.Manager):
|
|||
{'port_num': len(router_ports),
|
||||
'port_id': router_ports[0].id,
|
||||
'router_id': router_ports[0].device_id})
|
||||
all_subnets = self.dhcp_driver_cls._get_all_subnets(network)
|
||||
if self.dhcp_driver_cls.has_metadata_subnet(all_subnets):
|
||||
kwargs = {'router_id': router_ports[0].device_id}
|
||||
self._metadata_routers[network.id] = router_ports[0].device_id
|
||||
self._metadata_routers[network.id] = (
|
||||
router_ports[0].device_id)
|
||||
|
||||
metadata_driver.MetadataDriver.spawn_monitored_metadata_proxy(
|
||||
self._process_monitor, network.namespace, dhcp.METADATA_PORT,
|
||||
|
|
|
@ -1066,6 +1066,15 @@ class Dnsmasq(DhcpLocalProcess):
|
|||
|
||||
return isolated_subnets
|
||||
|
||||
@staticmethod
|
||||
def has_metadata_subnet(subnets):
|
||||
"""Check if the subnets has a metadata subnet."""
|
||||
meta_cidr = netaddr.IPNetwork(METADATA_DEFAULT_CIDR)
|
||||
if any(netaddr.IPNetwork(s.cidr) in meta_cidr
|
||||
for s in subnets):
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def should_enable_metadata(cls, conf, network):
|
||||
"""Determine whether the metadata proxy is needed for a network
|
||||
|
@ -1094,11 +1103,8 @@ class Dnsmasq(DhcpLocalProcess):
|
|||
if not conf.enable_isolated_metadata:
|
||||
return False
|
||||
|
||||
if conf.enable_metadata_network:
|
||||
# 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 all_subnets):
|
||||
if (conf.enable_metadata_network and
|
||||
cls.has_metadata_subnet(all_subnets)):
|
||||
return True
|
||||
|
||||
isolated_subnets = cls.get_isolated_subnets(network)
|
||||
|
|
|
@ -2279,6 +2279,14 @@ class TestDnsmasq(TestBase):
|
|||
self.safe.assert_has_calls([mock.call(exp_host_name, exp_host_data),
|
||||
mock.call(exp_opt_name, exp_opt_data)])
|
||||
|
||||
def test_has_metadata_subnet_returns_true(self):
|
||||
self.assertTrue(dhcp.Dnsmasq.has_metadata_subnet(
|
||||
[FakeV4MetadataSubnet()]))
|
||||
|
||||
def test_has_metadata_subnet_returns_false(self):
|
||||
self.assertFalse(dhcp.Dnsmasq.has_metadata_subnet(
|
||||
[FakeV4Subnet()]))
|
||||
|
||||
def test_should_enable_metadata_isolated_network_returns_true(self):
|
||||
self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(
|
||||
self.conf, FakeV4NetworkNoRouter()))
|
||||
|
|
Loading…
Reference in New Issue