diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index 61788272b83..bb3ed49b6e8 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -410,6 +410,8 @@ class DhcpAgent(manager.Manager): return for subnet in network.subnets: + # TODO(isabek): in Y release below 'if' can be removed + # because only dhcp enbaled subnets are returned from server if subnet.enable_dhcp: if self.call_driver('enable', network): self.update_isolated_metadata_proxy(network) diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py index cc34c0b1d23..20dcdb5a9b3 100644 --- a/neutron/api/rpc/handlers/dhcp_rpc.py +++ b/neutron/api/rpc/handlers/dhcp_rpc.py @@ -73,10 +73,11 @@ class DhcpRpcCallback(object): # the major version as above applies here too. # 1.7 - Add get_networks # 1.8 - Add get_dhcp_port + # 1.9 - get_network_info returns info with only DHCP enabled subnets target = oslo_messaging.Target( namespace=constants.RPC_NAMESPACE_DHCP_PLUGIN, - version='1.8') + version='1.9') def _get_active_networks(self, context, **kwargs): """Retrieve and return a list of the active networks.""" @@ -207,7 +208,11 @@ class DhcpRpcCallback(object): return networks def get_network_info(self, context, **kwargs): - """Retrieve and return extended information about a network.""" + """Retrieve and return information about a network. + + Retrieve and return extended information about a network + with only DHCP enabled subnets. + """ network_id = kwargs.get('network_id') host = kwargs.get('host') LOG.debug('Network %(network_id)s requested from ' @@ -220,8 +225,8 @@ class DhcpRpcCallback(object): LOG.debug("Network %s could not be found, it might have " "been deleted concurrently.", network_id) return - filters = dict(network_id=[network_id]) - subnets = plugin.get_subnets(context, filters=filters) + subnet_filters = {'network_id': [network_id], 'enable_dhcp': [True]} + subnets = plugin.get_subnets(context, filters=subnet_filters) seg_plug = directory.get_plugin( segment_ext.SegmentPluginBase.get_plugin_type()) nonlocal_subnets = [] @@ -247,7 +252,8 @@ class DhcpRpcCallback(object): network['subnets'] = sorted(subnets, key=operator.itemgetter('id')) network['non_local_subnets'] = sorted(nonlocal_subnets, key=operator.itemgetter('id')) - network['ports'] = plugin.get_ports(context, filters=filters) + port_filters = {'network_id': [network_id]} + network['ports'] = plugin.get_ports(context, filters=port_filters) return network @db_api.retry_db_errors diff --git a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py index 7933e5cdcf6..743328a634d 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py @@ -245,6 +245,12 @@ class TestDhcpRpcCallback(base.BaseTestCase): self.assertEqual(retval['non_local_subnets'], sorted_nonlocal_subnet_retval) self.assertEqual(retval['ports'], port_retval) + subnet_filters = {'network_id': [network_retval['id']], + 'enable_dhcp': [True]} + self.plugin.assert_has_calls( + [mock.call.get_network(mock.ANY, 'a'), + mock.call.get_subnets(mock.ANY, filters=subnet_filters), + mock.call.get_ports(mock.ANY, filters={'network_id': ['a']})]) def test_get_network_info(self): self._test_get_network_info()