From a5f30d173f59cf30d47ae413c134dc6682d676a1 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 7 Jun 2015 10:11:13 -0400 Subject: [PATCH] cleanup openstack-common.conf and sync updated files Changes include: e782594 Add last_request_id only if it is not none 18bf5ca Fix usage of NotFound exception in apiclient.base 3bc8231 deprecate apiclient package Depends-On: Ia83ef6136da1c551ea947679dc546a0d7ad2f876 Change-Id: I0b5917c657d6adc3d34229b14833a5224c168e07 --- novaclient/base.py | 4 ++++ novaclient/client.py | 3 +++ novaclient/openstack/common/apiclient/base.py | 19 ++++++++++++++++++- .../openstack/common/apiclient/fake_client.py | 3 +-- novaclient/tests/unit/v2/fakes.py | 1 + openstack-common.conf | 1 - 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/novaclient/base.py b/novaclient/base.py index 01b4bac94..e541c8e30 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -57,6 +57,10 @@ class Manager(base.HookableMixin): def __init__(self, api): self.api = api + @property + def client(self): + return self.api.client + def _list(self, url, response_key, obj_class=None, body=None): if body: _resp, body = self.api.client.post(url, body=body) diff --git a/novaclient/client.py b/novaclient/client.py index abb1c29c6..f8858b003 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -221,6 +221,7 @@ class HTTPClient(object): self.service_catalog = None self.services_url = {} + self.last_request_id = None def use_token_cache(self, use_it): self.os_cache = use_it @@ -392,6 +393,8 @@ class HTTPClient(object): else: body = None + self.last_request_id = (resp.headers.get('x-openstack-request-id') + if resp.headers else None) if resp.status_code >= 400: raise exceptions.from_response(resp, body, url, method) diff --git a/novaclient/openstack/common/apiclient/base.py b/novaclient/openstack/common/apiclient/base.py index ae067c6f1..89688151f 100644 --- a/novaclient/openstack/common/apiclient/base.py +++ b/novaclient/openstack/common/apiclient/base.py @@ -20,6 +20,20 @@ Base utilities to build API operation managers and objects on top of. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-novaclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + + # E1102: %s is not callable # pylint: disable=E1102 @@ -388,7 +402,7 @@ class CrudManager(BaseManager): 'name': self.resource_class.__name__, 'args': kwargs } - raise exceptions.NotFound(404, msg) + raise exceptions.NotFound(msg) elif num > 1: raise exceptions.NoUniqueMatch else: @@ -495,6 +509,9 @@ class Resource(object): new = self.manager.get(self.id) if new: self._add_details(new._info) + if self.manager.client.last_request_id: + self._add_details( + {'x_request_id': self.manager.client.last_request_id}) def __eq__(self, other): if not isinstance(other, Resource): diff --git a/novaclient/openstack/common/apiclient/fake_client.py b/novaclient/openstack/common/apiclient/fake_client.py index 1a0324c8a..2d2a728b1 100644 --- a/novaclient/openstack/common/apiclient/fake_client.py +++ b/novaclient/openstack/common/apiclient/fake_client.py @@ -181,8 +181,7 @@ class FakeHTTPClient(client.HTTPClient): else: status, body = resp headers = {} - self.last_request_id = headers.get('x-openstack-request-id', - 'req-test') + self.last_request_id = headers.get('x-openstack-request-id') return TestResponse({ "status_code": status, "text": body, diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 1c3e93bd2..f3052252e 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -56,6 +56,7 @@ class FakeHTTPClient(base_client.HTTPClient): self.bypass_url = 'bypass_url' self.os_cache = 'os_cache' self.http_log_debug = 'http_log_debug' + self.last_request_id = None def _cs_request(self, url, method, **kwargs): # Check that certain things are called correctly diff --git a/openstack-common.conf b/openstack-common.conf index 01962c84a..a987faae9 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -3,7 +3,6 @@ # The list of modules to copy from oslo-incubator module=apiclient module=cliutils -module=install_venv_common # The base module to hold the copy of openstack.common base=novaclient