Do not add DHCP info to subnet if DHCP is disabled

Currently the midonet plugin will add default DHCP information to
each subnet even if the subnet is configured to have DHCP disabled.
This change addresses this by checking the DHCP settings while
creating a subnet, and only adding DHCP information if DHCP is
enabled.

Closes-bug #1230073

Change-Id: I2c422866c60f505df30bfa18bfe8d03599665b7a
This commit is contained in:
Joe Mills 2013-09-25 08:43:30 +00:00 committed by Gerrit Code Review
parent 727e42aac7
commit 7df7d0487e
2 changed files with 20 additions and 10 deletions

View File

@ -250,6 +250,9 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
if subnet["ip_version"] == 6:
# TODO(ryu) handle IPv6
continue
if not subnet["enable_dhcp"]:
# Skip if DHCP is disabled
continue
yield subnet['cidr'], fixed_ip["ip_address"], mac
def _metadata_subnets(self, context, fixed_ips):
@ -405,17 +408,18 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
gateway_ip = s['gateway_ip']
cidr = s['cidr']
dns_nameservers = None
host_routes = None
if s['dns_nameservers'] is not attributes.ATTR_NOT_SPECIFIED:
dns_nameservers = s['dns_nameservers']
if s['enable_dhcp']:
dns_nameservers = None
host_routes = None
if s['dns_nameservers'] is not attributes.ATTR_NOT_SPECIFIED:
dns_nameservers = s['dns_nameservers']
if s['host_routes'] is not attributes.ATTR_NOT_SPECIFIED:
host_routes = s['host_routes']
if s['host_routes'] is not attributes.ATTR_NOT_SPECIFIED:
host_routes = s['host_routes']
self.client.create_dhcp(bridge, gateway_ip, cidr,
host_rts=host_routes,
dns_servers=dns_nameservers)
self.client.create_dhcp(bridge, gateway_ip, cidr,
host_rts=host_routes,
dns_servers=dns_nameservers)
# For external network, link the bridge to the provider router.
if net['router:external']:
@ -442,7 +446,8 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
super(MidonetPluginV2, self).delete_subnet(context, id)
bridge = self.client.get_bridge(subnet['network_id'])
self.client.delete_dhcp(bridge, subnet['cidr'])
if subnet['enable_dhcp']:
self.client.delete_dhcp(bridge, subnet['cidr'])
# If the network is external, clean up routes, links, ports
if net[ext_net.EXTERNAL]:

View File

@ -131,6 +131,11 @@ class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2,
def test_create_subnet_inconsistent_ipv6_gatewayv4(self):
pass
def test_create_subnet_dhcp_disabled(self):
super(TestMidonetSubnetsV2, self)._test_create_subnet(
enable_dhcp=False)
self.assertFalse(self.instance.return_value.create_dhcp.called)
class TestMidonetPortsV2(test_plugin.TestPortsV2,
MidonetPluginV2TestCase):