Generate new context for each DHCP RPC call
The DHCP agent was using the same context for every RPC request so it made it difficult to tell server side where one RPC request began and where another one ended. This patch has it generate a new context for each RPC request so they can be tracked independently. In the long term it would be better if the agent kept the context for server-initiated events so actions could be tracked end-to-end under the same request-ID. Change-Id: I1d6dc28ba4752d3f9f1020851af2960859aae520 Closes-Bug: #1618231
This commit is contained in:
parent
b1803737ea
commit
0f43042521
|
@ -58,8 +58,7 @@ class DhcpAgent(manager.Manager):
|
|||
self.conf = conf or cfg.CONF
|
||||
self.cache = NetworkCache()
|
||||
self.dhcp_driver_cls = importutils.import_class(self.conf.dhcp_driver)
|
||||
ctx = context.get_admin_context_without_session()
|
||||
self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, ctx, self.conf.host)
|
||||
self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, self.conf.host)
|
||||
# create dhcp dir to store dhcp info
|
||||
dhcp_dir = os.path.dirname("/%s/dhcp/" % self.conf.state_path)
|
||||
utils.ensure_dir(dhcp_dir)
|
||||
|
@ -467,8 +466,7 @@ class DhcpPluginApi(object):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, topic, context, host):
|
||||
self.context = context
|
||||
def __init__(self, topic, host):
|
||||
self.host = host
|
||||
target = oslo_messaging.Target(
|
||||
topic=topic,
|
||||
|
@ -476,6 +474,15 @@ class DhcpPluginApi(object):
|
|||
version='1.0')
|
||||
self.client = n_rpc.get_client(target)
|
||||
|
||||
@property
|
||||
def context(self):
|
||||
# TODO(kevinbenton): the context should really be passed in to each of
|
||||
# these methods so a call can be tracked all of the way through the
|
||||
# system but that will require a larger refactor to pass the context
|
||||
# everywhere. We just generate a new one here on each call so requests
|
||||
# can be independently tracked server side.
|
||||
return context.get_admin_context_without_session()
|
||||
|
||||
def get_active_networks_info(self):
|
||||
"""Make a remote process call to retrieve all network info."""
|
||||
cctxt = self.client.prepare(version='1.1')
|
||||
|
|
|
@ -35,7 +35,6 @@ from neutron.common import config as common_config
|
|||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils
|
||||
from neutron.conf.agent import dhcp as dhcp_config
|
||||
from neutron import context
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
|
@ -1087,8 +1086,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
|||
|
||||
class TestDhcpPluginApiProxy(base.BaseTestCase):
|
||||
def _test_dhcp_api(self, method, **kwargs):
|
||||
ctxt = context.get_admin_context()
|
||||
proxy = dhcp_agent.DhcpPluginApi('foo', ctxt, host='foo')
|
||||
proxy = dhcp_agent.DhcpPluginApi('foo', host='foo')
|
||||
|
||||
with mock.patch.object(proxy.client, 'call') as rpc_mock,\
|
||||
mock.patch.object(proxy.client, 'prepare') as prepare_mock:
|
||||
|
@ -1104,7 +1102,7 @@ class TestDhcpPluginApiProxy(base.BaseTestCase):
|
|||
|
||||
prepare_mock.assert_called_once_with(**prepare_args)
|
||||
kwargs['host'] = proxy.host
|
||||
rpc_mock.assert_called_once_with(ctxt, method, **kwargs)
|
||||
rpc_mock.assert_called_once_with(mock.ANY, method, **kwargs)
|
||||
|
||||
def test_get_active_networks_info(self):
|
||||
self._test_dhcp_api('get_active_networks_info', version='1.1')
|
||||
|
|
Loading…
Reference in New Issue