From 6579dd4ae99b24bb4dfc2a69fafdd1415b85b7a6 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Tue, 11 Feb 2014 19:39:11 -0800 Subject: [PATCH] Fix log-related tracebacks in nsx plugin Closes-bug: 1279163 Change-Id: I2a6f0fdbd4d72b74c6a4329cb5e02d9d979705dd --- neutron/plugins/nicira/api_client/request.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/nicira/api_client/request.py b/neutron/plugins/nicira/api_client/request.py index c54ed1bdf..4cc00f868 100644 --- a/neutron/plugins/nicira/api_client/request.py +++ b/neutron/plugins/nicira/api_client/request.py @@ -100,6 +100,7 @@ class NvpApiRequest(object): issued_time = time.time() is_conn_error = False is_conn_service_unavail = False + response = None try: redirects = 0 while (redirects <= self._redirects): @@ -133,12 +134,13 @@ class NvpApiRequest(object): response = conn.getresponse() response.body = response.read() response.headers = response.getheaders() + elapsed_time = time.time() - issued_time LOG.debug(_("[%(rid)d] Completed request '%(conn)s': " - "%(status)s (%(sec)0.2f seconds)"), + "%(status)s (%(elapsed)s seconds)"), {'rid': self._rid(), 'conn': self._request_str(conn, url), 'status': response.status, - 'sec': time.time() - issued_time}) + 'elapsed': elapsed_time}) new_gen = response.getheader('X-Nvp-Config-Generation', None) if new_gen: @@ -204,10 +206,12 @@ class NvpApiRequest(object): msg = (_("Invalid server response")) else: msg = unicode(e) + if response is None: + elapsed_time = time.time() - issued_time LOG.warn(_("[%(rid)d] Failed request '%(conn)s': '%(msg)s' " - "(%(sec)0.2f seconds)"), + "(%(elapsed)s seconds)"), {'rid': self._rid(), 'conn': self._request_str(conn, url), - 'msg': msg, 'sec': time.time() - issued_time}) + 'msg': msg, 'elapsed': elapsed_time}) self._request_error = e is_conn_error = True return e -- 2.45.2