]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not add DHCP info to subnet if DHCP is disabled
authorJoe Mills <joe@midokura.com>
Wed, 25 Sep 2013 08:43:30 +0000 (08:43 +0000)
committerGerrit Code Review <review@openstack.org>
Fri, 22 Nov 2013 02:15:36 +0000 (02:15 +0000)
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
neutron/tests/unit/midonet/test_midonet_plugin.py

index ca2cb9c186769ab432c62ca00381ac7651f36854..e7af1209263704c0756ae3016becf2c3a41d2da6 100644 (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]:
index e432db861465aa8c595b459fffc4222cd5c6a5a0..5ecab720da45004ff18e4de399af2aa6d52c6bb3 100644 (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):