Make L3 agent use different request-id for each request

Generate a new context object request-id for each reference
to self.context. This allows easier tracking of requests
in logs.

This is the L3 agent equivalent fix of
I1d6dc28ba4752d3f9f1020851af2960859aae520.

Related-Bug: #1618231
Closes-Bug: #1619524
Change-Id: I4a49f05ce0e7467084a1c27a64a0d4cf60a5f8cb
This commit is contained in:
Kevin Benton 2016-09-01 20:07:09 -07:00
parent 5f849165a6
commit c736948355
2 changed files with 13 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import eventlet
import netaddr
from neutron_lib import constants as lib_const
from oslo_config import cfg
from oslo_context import context as common_context
from oslo_log import log as logging
import oslo_messaging
from oslo_service import loopingcall
@ -191,7 +192,7 @@ class L3NATAgent(ha.AgentMixin,
self.driver = common_utils.load_interface_driver(self.conf)
self.context = n_context.get_admin_context_without_session()
self._context = n_context.get_admin_context_without_session()
self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
self.fullsync = True
self.sync_routers_chunk_size = SYNC_ROUTERS_MAX_CHUNK_SIZE
@ -610,6 +611,13 @@ class L3NATAgent(ha.AgentMixin,
action=queue.DELETE_ROUTER)
self._queue.add(update)
@property
def context(self):
# generate a new request-id on each call to make server side tracking
# of RPC calls easier.
self._context.request_id = common_context.generate_request_id()
return self._context
def after_start(self):
# Note: the FWaaS' vArmourL3NATAgent is a subclass of L3NATAgent. It
# calls this method here. So Removing this after_start() would break

View File

@ -184,6 +184,10 @@ class BasicRouterOperationsFramework(base.BaseTestCase):
class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_request_id_changes(self):
a = l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.assertNotEqual(a.context.request_id, a.context.request_id)
def test_init_ha_conf(self):
with mock.patch('os.path.dirname', return_value='/etc/ha/'):
l3_agent.L3NATAgent(HOSTNAME, self.conf)