From 32641b4f2770625fea9858c87201995819ae6cbd Mon Sep 17 00:00:00 2001 From: Victor Sergeyev Date: Mon, 10 Feb 2014 10:26:01 +0200 Subject: [PATCH] Update common apiclient from Oslo Updated openstack.common.apiclient code from oslo-incubator to commit 8630a44d64c92a0d479e4652bf5ba2cd22416eae List of changes: 9f1e7eb Correct docstring in load_plugin_from_args 0c4d2c7 Removed set_loaded() method from Resource class 3b248dd Add to_dict() method to apiclient Resource be81d6b Cleanup unused log related code 8575d87 Removed copyright from empty files bbaf317 Use encode() instead of strutils.safe_encode() in fake_client 41dc2b4 Encode response from FakeHTTPClient Removed Resource class from client's code - we should use Resource from common code. Change-Id: I0b90999e7832f3796201e40f7df4de7148b832fa --- tuskarclient/common/base.py | 18 ----------------- .../openstack/common/apiclient/__init__.py | 14 ------------- .../openstack/common/apiclient/auth.py | 6 +----- .../openstack/common/apiclient/base.py | 20 ++++++++++--------- .../openstack/common/apiclient/exceptions.py | 5 +++++ .../openstack/common/apiclient/fake_client.py | 3 +++ tuskarclient/v1/overcloud_roles.py | 3 ++- tuskarclient/v1/overclouds.py | 3 ++- 8 files changed, 24 insertions(+), 48 deletions(-) diff --git a/tuskarclient/common/base.py b/tuskarclient/common/base.py index 8f508b2..efa95a1 100644 --- a/tuskarclient/common/base.py +++ b/tuskarclient/common/base.py @@ -17,11 +17,6 @@ Base utilities to build API operation managers and objects on top of. """ -import copy - -from tuskarclient.openstack.common.apiclient import base - - # Python 2.4 compat try: all @@ -117,16 +112,3 @@ class Manager(object): def _delete(self, url): self.api.raw_request('DELETE', url) - - -class Resource(base.Resource): - """A resource represents a particular instance of an object (tenant, user, - etc). This is pretty much just a bag for attributes. - - :param manager: Manager object - :param info: dictionary representing resource attributes - :param loaded: prevent lazy-loading if set to True - """ - - def to_dict(self): - return copy.deepcopy(self._info) diff --git a/tuskarclient/openstack/common/apiclient/__init__.py b/tuskarclient/openstack/common/apiclient/__init__.py index f3d0cde..e69de29 100644 --- a/tuskarclient/openstack/common/apiclient/__init__.py +++ b/tuskarclient/openstack/common/apiclient/__init__.py @@ -1,14 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. diff --git a/tuskarclient/openstack/common/apiclient/auth.py b/tuskarclient/openstack/common/apiclient/auth.py index 5fae339..e23e053 100644 --- a/tuskarclient/openstack/common/apiclient/auth.py +++ b/tuskarclient/openstack/common/apiclient/auth.py @@ -19,7 +19,6 @@ import abc import argparse -import logging import os import six @@ -28,9 +27,6 @@ from stevedore import extension from tuskarclient.openstack.common.apiclient import exceptions -logger = logging.getLogger(__name__) - - _discovered_plugins = {} @@ -80,7 +76,7 @@ def load_plugin_from_args(args): alphabetical order. :type args: argparse.Namespace - :raises: AuthorizationFailure + :raises: AuthPluginOptionsMissing """ auth_system = args.os_auth_system if auth_system: diff --git a/tuskarclient/openstack/common/apiclient/base.py b/tuskarclient/openstack/common/apiclient/base.py index f3b54b1..04349b5 100644 --- a/tuskarclient/openstack/common/apiclient/base.py +++ b/tuskarclient/openstack/common/apiclient/base.py @@ -24,6 +24,7 @@ Base utilities to build API operation managers and objects on top of. # pylint: disable=E1102 import abc +import copy import six @@ -84,8 +85,8 @@ class HookableMixin(object): class BaseManager(HookableMixin): """Basic manager type providing common operations. - Managers interact with a particular type of API (servers, images, etc.) and - provide CRUD operations for them. + Managers interact with a particular type of API (servers, flavors, images, + etc.) and provide CRUD operations for them. """ resource_class = None @@ -456,17 +457,17 @@ class Resource(object): def __getattr__(self, k): if k not in self.__dict__: #NOTE(bcwaldon): disallow lazy-loading if already loaded once - if not self.is_loaded(): - self.get() + if not self.is_loaded: + self._get() return self.__getattr__(k) raise AttributeError(k) else: return self.__dict__[k] - def get(self): - # set_loaded() first ... so if we have to bail, we know we tried. - self.set_loaded(True) + def _get(self): + # set _loaded first ... so if we have to bail, we know we tried. + self._loaded = True if not hasattr(self.manager, 'get'): return @@ -484,8 +485,9 @@ class Resource(object): return self.id == other.id return self._info == other._info + @property def is_loaded(self): return self._loaded - def set_loaded(self, val): - self._loaded = val + def to_dict(self): + return copy.deepcopy(self._info) diff --git a/tuskarclient/openstack/common/apiclient/exceptions.py b/tuskarclient/openstack/common/apiclient/exceptions.py index b364d60..4776d58 100644 --- a/tuskarclient/openstack/common/apiclient/exceptions.py +++ b/tuskarclient/openstack/common/apiclient/exceptions.py @@ -60,6 +60,11 @@ class AuthorizationFailure(ClientException): pass +class ConnectionRefused(ClientException): + """Cannot connect to API service.""" + pass + + class AuthPluginOptionsMissing(AuthorizationFailure): """Auth plugin misses some options.""" def __init__(self, opt_names): diff --git a/tuskarclient/openstack/common/apiclient/fake_client.py b/tuskarclient/openstack/common/apiclient/fake_client.py index 890c90d..0f6ba0b 100644 --- a/tuskarclient/openstack/common/apiclient/fake_client.py +++ b/tuskarclient/openstack/common/apiclient/fake_client.py @@ -27,6 +27,7 @@ places where actual behavior differs from the spec. import json import requests +import six from tuskarclient.openstack.common.apiclient import client from tuskarclient.openstack.common.py3kcompat import urlutils @@ -61,6 +62,8 @@ class TestResponse(requests.Response): else: self._content = text default_headers = {} + if six.PY3 and isinstance(self._content, six.string_types): + self._content = self._content.encode('utf-8', 'strict') self.headers = data.get('headers') or default_headers else: self.status_code = data diff --git a/tuskarclient/v1/overcloud_roles.py b/tuskarclient/v1/overcloud_roles.py index 34da389..e5ea7c3 100644 --- a/tuskarclient/v1/overcloud_roles.py +++ b/tuskarclient/v1/overcloud_roles.py @@ -11,9 +11,10 @@ # under the License. from tuskarclient.common import base +from tuskarclient.openstack.common.apiclient import base as common_base -class OvercloudRole(base.Resource): +class OvercloudRole(common_base.Resource): """Represents an instance of an Overcloud Role in the Tuskar API. :param manager: Manager object diff --git a/tuskarclient/v1/overclouds.py b/tuskarclient/v1/overclouds.py index 6de84b7..f94ab87 100644 --- a/tuskarclient/v1/overclouds.py +++ b/tuskarclient/v1/overclouds.py @@ -11,9 +11,10 @@ # under the License. from tuskarclient.common import base +from tuskarclient.openstack.common.apiclient import base as common_base -class Overcloud(base.Resource): +class Overcloud(common_base.Resource): """Represents an instance of a Overcloud in the Tuskar API. :param manager: Manager object