move old apiclient code out of openstack/common

As part of the first community-wide goal [1], teams were asked
to remove the openstack/common package of their projects
if one existed. This was a byproduct of the old oslo-incubator
form of syncing common functionality.

The package, apiclient, was moved to a top level location
and cliutils was moved to the common module. There are no oslo
specific libraries, the recommended solution is to move it
in tree and maintain it there.

Specifically in this patch, I also rearranged some of the
imports to make them match up with the hacking guidelines
while I was re-ordering them for the refactor anyway.

Lastly, the apiclient/fake_client.py was deleted since it
was not used.

[1] http://governance.openstack.org/goals/ocata/remove-incubated-oslo-code.html

Change-Id: Ib7b691240b819c9c91b100ca47ffaba75b281c78
This commit is contained in:
Steve Martinelli 2016-11-10 10:00:24 -05:00
parent c4d9ebb66d
commit eed19c835f
19 changed files with 25 additions and 205 deletions

View File

@ -3,7 +3,7 @@
branch = True
source=troveclient
omit=troveclient/tests*,troveclient/compat/tests*,troveclient/openstack*
omit=troveclient/tests*,troveclient/compat/tests*
[report]
# Regexes for lines to exclude from consideration

View File

@ -24,7 +24,7 @@ import os
import six
from stevedore import extension
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
_discovered_plugins = {}
@ -41,7 +41,7 @@ def discover_auth_systems():
def add_plugin(ext):
_discovered_plugins[ext.name] = ext.plugin
ep_namespace = "troveclient.openstack.common.apiclient.auth"
ep_namespace = "troveclient.apiclient.auth"
mgr = extension.ExtensionManager(ep_namespace)
mgr.map(add_plugin)

View File

@ -31,7 +31,7 @@ from oslo_utils import strutils
import six
from six.moves.urllib import parse
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
def getid(obj):

View File

@ -36,7 +36,7 @@ except ImportError:
import requests
from oslo_utils import importutils
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
_logger = logging.getLogger(__name__)
@ -60,7 +60,7 @@ class HTTPClient(object):
into terminal and send the same request with curl.
"""
user_agent = "troveclient.openstack.common.apiclient"
user_agent = "troveclient.apiclient"
def __init__(self,
auth_plugin,

View File

@ -26,9 +26,9 @@ import os
import six
from six.moves.urllib import parse
from troveclient.apiclient import base
from troveclient.apiclient import exceptions
from troveclient import common
from troveclient.openstack.common.apiclient import base
from troveclient.openstack.common.apiclient import exceptions
from troveclient import utils
# Python 2.4 compat

View File

@ -22,16 +22,16 @@ OpenStack Client interface. Handles the REST calls and responses.
from __future__ import print_function
import logging
import requests
from keystoneauth1 import adapter
from oslo_utils import importutils
from troveclient import exceptions
from troveclient.openstack.common.apiclient import client
from troveclient import service_catalog
import requests
import six.moves.urllib.parse as urlparse
from troveclient.apiclient import client
from troveclient import exceptions
from troveclient import service_catalog
try:
import eventlet as sleep_lib
except ImportError:

View File

@ -13,9 +13,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from six.moves.urllib import parse
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
def check_for_exceptions(resp, body, url):

View File

@ -20,7 +20,7 @@ Exception definitions
"""
# alias exceptions from apiclient for users of this module
from troveclient.openstack.common.apiclient.exceptions import * # noqa
from troveclient.apiclient.exceptions import * # noqa
class NoTokenLookupException(Exception):

View File

@ -1,175 +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.
"""
A fake server that "responds" to API methods with pre-canned responses.
All of these responses come from the spec, so if for some reason the spec's
wrong the tests might raise AssertionError. I've indicated in comments the
places where actual behavior differs from the spec.
"""
# W0102: Dangerous default value %s as argument
# pylint: disable=W0102
import json
import requests
import six
from six.moves.urllib import parse
from troveclient.openstack.common.apiclient import client
from troveclient.tests import utils
def assert_has_keys(dct, required=[], optional=[]):
for k in required:
try:
assert k in dct
except AssertionError:
extra_keys = set(dct.keys()).difference(set(required + optional))
raise AssertionError("found unexpected keys: %s" %
list(extra_keys))
class TestResponse(requests.Response):
"""Wrap requests.Response and provide a convenient initialization.
"""
def __init__(self, data):
super(TestResponse, self).__init__()
self._content_consumed = True
if isinstance(data, dict):
self.status_code = data.get('status_code', 200)
# Fake the text attribute to streamline Response creation
text = data.get('text', "")
if isinstance(text, (dict, list)):
self._content = json.dumps(text)
default_headers = {
"Content-Type": "application/json",
}
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
def __eq__(self, other):
return (self.status_code == other.status_code and
self.headers == other.headers and
self._content == other._content)
class FakeHTTPClient(client.HTTPClient):
def __init__(self, *args, **kwargs):
self.callstack = []
self.fixtures = kwargs.pop("fixtures", None) or {}
if not args and "auth_plugin" not in kwargs:
args = (None, )
super(FakeHTTPClient, self).__init__(*args, **kwargs)
def assert_called(self, method, url, body=None, pos=-1):
"""Assert than an API method was just called.
"""
expected = (method, utils.order_url(url))
called = (self.callstack[pos][0],
utils.order_url(self.callstack[pos][1]))
assert self.callstack, \
"Expected %s %s but no calls were made." % expected
assert expected == called, 'Expected %s %s; got %s %s' % \
(expected + called)
if body is not None:
if self.callstack[pos][3] != body:
raise AssertionError('%r != %r' %
(self.callstack[pos][3], body))
def assert_called_anytime(self, method, url, body=None):
"""Assert than an API method was called anytime in the test.
"""
expected = (method, utils.order_url(url))
assert self.callstack, \
"Expected %s %s but no calls were made." % expected
found = False
entry = None
for entry in self.callstack:
if expected == (entry[0], utils.order_url(entry[1])):
found = True
break
assert found, 'Expected %s %s; got %s' % \
(method, url, self.callstack)
if body is not None:
assert entry[3] == body, "%s != %s" % (entry[3], body)
self.callstack = []
def clear_callstack(self):
self.callstack = []
def authenticate(self):
pass
def client_request(self, client, method, url, **kwargs):
# Check that certain things are called correctly
if method in ["GET", "DELETE"]:
assert "json" not in kwargs
# Note the call
self.callstack.append(
(method,
url,
kwargs.get("headers") or {},
kwargs.get("json") or kwargs.get("data")))
try:
fixture = self.fixtures[url][method]
except KeyError:
pass
else:
return TestResponse({"headers": fixture[0],
"text": fixture[1]})
# Call the method
args = parse.parse_qsl(parse.urlparse(url)[4])
kwargs.update(args)
munged_url = url.rsplit('?', 1)[0]
munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
munged_url = munged_url.replace('-', '_')
callback = "%s_%s" % (method.lower(), munged_url)
if not hasattr(self, callback):
raise AssertionError('Called unknown API method: %s %s, '
'expected fakes method name: %s' %
(method, url, callback))
resp = getattr(self, callback)(**kwargs)
if len(resp) == 3:
status, headers, body = resp
else:
status, body = resp
headers = {}
return TestResponse({
"status_code": status,
"text": body,
"headers": headers,
})

View File

@ -16,7 +16,7 @@
# limitations under the License.
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
class ServiceCatalog(object):

View File

@ -30,24 +30,19 @@ import os
import pkgutil
import sys
import pkg_resources
import six
from keystoneauth1.identity.generic import password
from keystoneauth1.identity.generic import token
from keystoneauth1 import loading
from oslo_utils import encodeutils
from oslo_utils import importutils
import pkg_resources
import six
import troveclient
from troveclient.apiclient import exceptions as exc
import troveclient.auth_plugin
from troveclient import client
import troveclient.extension
from troveclient.i18n import _ # noqa
from troveclient.openstack.common.apiclient import exceptions as exc
from troveclient import utils
from troveclient.v1 import shell as shell_v1

View File

@ -21,9 +21,9 @@ import os
import mock
import testtools
from troveclient.apiclient import exceptions
from troveclient import base
from troveclient import common
from troveclient.openstack.common.apiclient import exceptions
from troveclient import utils
"""

View File

@ -22,9 +22,9 @@ import mock
import requests
import testtools
from troveclient.apiclient import client
from troveclient import client as other_client
from troveclient import exceptions
from troveclient.openstack.common.apiclient import client
from troveclient import service_catalog
import troveclient.v1.client

View File

@ -22,12 +22,11 @@ import simplejson as json
import sys
import uuid
from oslo_utils import encodeutils
import prettytable
import six
from oslo_utils import encodeutils
from troveclient.openstack.common.apiclient import exceptions
from troveclient.apiclient import exceptions
def arg(*args, **kwargs):

View File

@ -15,8 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from troveclient.apiclient import exceptions
from troveclient import base
from troveclient.openstack.common.apiclient import exceptions
class Limit(base.Resource):