From bf0b8ef7e8731a4625e6cffd157cab98fa180a20 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 19 Oct 2017 11:36:09 +0300 Subject: [PATCH] Logging neutron request-id in NSX To simplify debugging neutron transaction in NSX, add neutron's request id to NSX manager log files. Change-Id: I894575160b3b86bd063220e46b8e298582268a25 --- requirements.txt | 1 + vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/requirements.txt b/requirements.txt index 2da71be0a1..0b77bf9b3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ neutron-lib>=1.10.0 # Apache-2.0 osc-lib>=1.7.0 # Apache-2.0 python-openstackclient>=3.12.0 # Apache-2.0 oslo.concurrency>=3.20.0 # Apache-2.0 +oslo.context!=2.19.1,>=2.14.0 # Apache-2.0 oslo.config>=4.6.0 # Apache-2.0 oslo.db>=4.27.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 diff --git a/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py b/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py index b68ec1b945..6b20c08bc6 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py +++ b/vmware_nsx/plugins/nsx_v/vshield/common/VcnsApiClient.py @@ -15,6 +15,7 @@ import base64 import xml.etree.ElementTree as et +from oslo_context import context as context_utils from oslo_serialization import jsonutils import requests import six @@ -118,6 +119,11 @@ class VcnsApiHelper(object): # We won't assume that integer error-code value is guaranteed. return None + def _get_request_id(self): + ctx = context_utils.get_current() + if ctx: + return ctx.__dict__.get('request_id') + def request(self, method, uri, params=None, headers=None, encodeparams=True): uri = self.address + uri @@ -127,6 +133,9 @@ class VcnsApiHelper(object): headers['Accept'] = 'application/' + self.format headers['Authorization'] = 'Basic ' + self.authToken.strip() headers['Content-Type'] = 'application/' + self.format + request_id = self._get_request_id() + if request_id: + headers['TicketNumber'] = request_id if params: if encodeparams is True: