Add enable_dhcp filter in get_network_info rpc
Add enable_dhcp, to make a filter to avoid unnecessary net_info data transfer through rpc. Change-Id: Ibcef366f5b1f4b7da4f47f1f538a17111da0faa1 Closes-Bug: #1552614
This commit is contained in:
parent
8367d28621
commit
1483b63ffa
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue