Skip to content

Commit

Permalink
Merge "Not check subnet with dhcp disabled when get_isolated_subnets"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 25, 2016
2 parents b2c2edb + 753f4ea commit 787c42c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion neutron/agent/linux/dhcp.py
Expand Up @@ -1043,7 +1043,8 @@ def get_isolated_subnets(cls, network):
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:
if (alloc.subnet_id in subnets and
subnets[alloc.subnet_id].gateway_ip == alloc.ip_address):
isolated_subnets[alloc.subnet_id] = False

return isolated_subnets
Expand Down
38 changes: 38 additions & 0 deletions neutron/tests/unit/agent/linux/test_dhcp.py
Expand Up @@ -281,6 +281,23 @@ def __init__(self, dev_owner=constants.DEVICE_OWNER_ROUTER_INTF,
for ip in self.fixed_ips]


class FakeRouterPortNoDHCP(object):
def __init__(self, dev_owner=constants.DEVICE_OWNER_ROUTER_INTF,
ip_address='192.168.0.1', domain='openstacklocal'):
self.id = 'ssssssss-ssss-ssss-ssss-ssssssssssss'
self.admin_state_up = True
self.device_owner = constants.DEVICE_OWNER_ROUTER_INTF
self.mac_address = '00:00:0f:rr:rr:rr'
self.device_id = 'fake_router_port_no_dhcp'
self.dns_assignment = []
self.extra_dhcp_opts = []
self.device_owner = dev_owner
self.fixed_ips = [FakeIPAllocation(
ip_address, 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee')]
self.dns_assignment = [FakeDNSAssignment(ip.ip_address, domain=domain)
for ip in self.fixed_ips]


class FakeRouterPort2(object):
def __init__(self):
self.id = 'rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr'
Expand Down Expand Up @@ -602,6 +619,15 @@ def __init__(self):
self.namespace = 'qdhcp-ns'


class FakeDualNetworkSingleDHCPBothAttaced(object):
def __init__(self):
self.id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
# dhcp-agent actually can't get the subnet with dhcp disabled
self.subnets = [FakeV4Subnet()]
self.ports = [FakePort1(), FakeRouterPortNoDHCP(), FakeRouterPort()]
self.namespace = 'qdhcp-ns'


class FakeDualNetworkDualDHCP(object):
def __init__(self):
self.id = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
Expand Down Expand Up @@ -1336,6 +1362,18 @@ def test_output_opts_file_single_dhcp(self):

self._test_output_opts_file(expected, FakeDualNetworkSingleDHCP())

def test_output_opts_file_single_dhcp_both_not_isolated(self):
expected = (
'tag:tag0,option:dns-server,8.8.8.8\n'
'tag:tag0,option:classless-static-route,20.0.0.1/24,20.0.0.1,'
'169.254.169.254/32,192.168.0.1,0.0.0.0/0,192.168.0.1\n'
'tag:tag0,249,20.0.0.1/24,20.0.0.1,'
'169.254.169.254/32,192.168.0.1,0.0.0.0/0,192.168.0.1\n'
'tag:tag0,option:router,192.168.0.1').lstrip()

self._test_output_opts_file(expected,
FakeDualNetworkSingleDHCPBothAttaced())

def test_output_opts_file_dual_dhcp_rfc3442(self):
expected = (
'tag:tag0,option:dns-server,8.8.8.8\n'
Expand Down

0 comments on commit 787c42c

Please sign in to comment.