summaryrefslogtreecommitdiff
path: root/neutron/notifiers
diff options
context:
space:
mode:
authoropenstack <neha.alhat@nttdata.com>2018-11-05 07:17:21 +0000
committeropenstack <neha.alhat@nttdata.com>2018-11-30 05:41:24 +0000
commit75d83b903277c094a8680f83d2eb364e0736ed86 (patch)
treef3c3d2a971264411d621bb0c8bed27c1c478f6e8 /neutron/notifiers
parent5ad2bfdbfe4731790b2731065ae8ba791e309bf0 (diff)
downloadneutron-75d83b903277c094a8680f83d2eb364e0736ed86.tar.gz
Send global_request_id for tracing calls from neutron to nova
Neutron makes call to nova for sending notifications but here no context object user/admin available, so generated a request_id and passed it as global_request_id during novaclient initialization so that nova will log both global_request_id and it's own generated request_id in the context formatter for traceability. As Notifier class is used as singleton mode, need to create novaclient every time events are sent from neutron to nova. Modified unit tests wherever applicable. Oslo spec I65de8261746b25d45e105394f4eeb95b9cb3bd42 Change-Id: I94257bd6ec9ec6b9a1f509c27c439e6305e43e63
Diffstat (limited to 'neutron/notifiers')
-rw-r--r--neutron/notifiers/nova.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py
index b3b996349b..246cff7b6c 100644
--- a/neutron/notifiers/nova.py
+++ b/neutron/notifiers/nova.py
@@ -25,6 +25,7 @@ from novaclient import api_versions
from novaclient import client as nova_client
from novaclient import exceptions as nova_exceptions
from oslo_config import cfg
+from oslo_context import context as common_context
from oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy.orm import attributes as sql_attr
@@ -56,23 +57,25 @@ class Notifier(object):
def __init__(self):
auth = ks_loading.load_auth_from_conf_options(cfg.CONF, 'nova')
-
- session = ks_loading.load_session_from_conf_options(
+ self.session = ks_loading.load_session_from_conf_options(
cfg.CONF,
'nova',
auth=auth)
-
- extensions = [
+ self.extensions = [
ext for ext in nova_client.discover_extensions(NOVA_API_VERSION)
if ext.name == "server_external_events"]
- self.nclient = nova_client.Client(
+ self.batch_notifier = batch_notifier.BatchNotifier(
+ cfg.CONF.send_events_interval, self.send_events)
+
+ def _get_nova_client(self):
+ global_id = common_context.generate_request_id()
+ return nova_client.Client(
api_versions.APIVersion(NOVA_API_VERSION),
- session=session,
+ session=self.session,
region_name=cfg.CONF.nova.region_name,
endpoint_type=cfg.CONF.nova.endpoint_type,
- extensions=extensions)
- self.batch_notifier = batch_notifier.BatchNotifier(
- cfg.CONF.send_events_interval, self.send_events)
+ extensions=self.extensions,
+ global_request_id=global_id)
def _is_compute_port(self, port):
try:
@@ -240,8 +243,9 @@ class Notifier(object):
def send_events(self, batched_events):
LOG.debug("Sending events: %s", batched_events)
+ novaclient = self._get_nova_client()
try:
- response = self.nclient.server_external_events.create(
+ response = novaclient.server_external_events.create(
batched_events)
except nova_exceptions.NotFound:
LOG.debug("Nova returned NotFound for event: %s",