From 7df7d0487e9e244592ecda598248102dcf1a97e7 Mon Sep 17 00:00:00 2001 From: Joe Mills Date: Wed, 25 Sep 2013 08:43:30 +0000 Subject: [PATCH] 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 --- neutron/plugins/midonet/plugin.py | 25 +++++++++++-------- .../tests/unit/midonet/test_midonet_plugin.py | 5 ++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/neutron/plugins/midonet/plugin.py b/neutron/plugins/midonet/plugin.py index ca2cb9c186..e7af120926 100644 --- a/neutron/plugins/midonet/plugin.py +++ b/neutron/plugins/midonet/plugin.py @@ -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]: diff --git a/neutron/tests/unit/midonet/test_midonet_plugin.py b/neutron/tests/unit/midonet/test_midonet_plugin.py index e432db8614..5ecab720da 100644 --- a/neutron/tests/unit/midonet/test_midonet_plugin.py +++ b/neutron/tests/unit/midonet/test_midonet_plugin.py @@ -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):