summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Martinelli <s.martinelli@gmail.com>2016-11-10 10:00:24 -0500
committerSteve Martinelli <s.martinelli@gmail.com>2016-11-10 10:02:08 -0500
commiteed19c835fc5706099ce2cee872fc66d99836cf8 (patch)
treec529014e6b3c472c63ea0e76b69e8cb28bcdc5ef
parentc4d9ebb66d28fa6ab4ac0ece3803184108893e94 (diff)
downloadpython-troveclient-eed19c835fc5706099ce2cee872fc66d99836cf8.tar.gz
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
-rw-r--r--.coveragerc2
-rw-r--r--troveclient/apiclient/__init__.py (renamed from troveclient/openstack/__init__.py)0
-rw-r--r--troveclient/apiclient/auth.py (renamed from troveclient/openstack/common/apiclient/auth.py)4
-rw-r--r--troveclient/apiclient/base.py (renamed from troveclient/openstack/common/apiclient/base.py)2
-rw-r--r--troveclient/apiclient/client.py (renamed from troveclient/openstack/common/apiclient/client.py)4
-rw-r--r--troveclient/apiclient/exceptions.py (renamed from troveclient/openstack/common/apiclient/exceptions.py)0
-rw-r--r--troveclient/base.py4
-rw-r--r--troveclient/client.py8
-rw-r--r--troveclient/common.py3
-rw-r--r--troveclient/exceptions.py2
-rw-r--r--troveclient/openstack/common/__init__.py0
-rw-r--r--troveclient/openstack/common/apiclient/__init__.py0
-rw-r--r--troveclient/openstack/common/apiclient/fake_client.py175
-rw-r--r--troveclient/service_catalog.py2
-rw-r--r--troveclient/shell.py11
-rw-r--r--troveclient/tests/test_base.py2
-rw-r--r--troveclient/tests/test_client.py2
-rw-r--r--troveclient/utils.py5
-rw-r--r--troveclient/v1/limits.py2
19 files changed, 24 insertions, 204 deletions
diff --git a/.coveragerc b/.coveragerc
index 307bd79..a8d4925 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -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
diff --git a/troveclient/openstack/__init__.py b/troveclient/apiclient/__init__.py
index e69de29..e69de29 100644
--- a/troveclient/openstack/__init__.py
+++ b/troveclient/apiclient/__init__.py
diff --git a/troveclient/openstack/common/apiclient/auth.py b/troveclient/apiclient/auth.py
index ded1435..48a096c 100644
--- a/troveclient/openstack/common/apiclient/auth.py
+++ b/troveclient/apiclient/auth.py
@@ -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)
diff --git a/troveclient/openstack/common/apiclient/base.py b/troveclient/apiclient/base.py
index 8dd26e1..72ec0c7 100644
--- a/troveclient/openstack/common/apiclient/base.py
+++ b/troveclient/apiclient/base.py
@@ -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):
diff --git a/troveclient/openstack/common/apiclient/client.py b/troveclient/apiclient/client.py
index 2773433..a94f46d 100644
--- a/troveclient/openstack/common/apiclient/client.py
+++ b/troveclient/apiclient/client.py
@@ -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,
diff --git a/troveclient/openstack/common/apiclient/exceptions.py b/troveclient/apiclient/exceptions.py
index c48df3a..c48df3a 100644
--- a/troveclient/openstack/common/apiclient/exceptions.py
+++ b/troveclient/apiclient/exceptions.py
diff --git a/troveclient/base.py b/troveclient/base.py
index 41bd7a8..7af8668 100644
--- a/troveclient/base.py
+++ b/troveclient/base.py
@@ -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
diff --git a/troveclient/client.py b/troveclient/client.py
index 76f87d0..a0a67ae 100644
--- a/troveclient/client.py
+++ b/troveclient/client.py
@@ -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
+import requests
+import six.moves.urllib.parse as urlparse
+
+from troveclient.apiclient import client
from troveclient import exceptions
-from troveclient.openstack.common.apiclient import client
from troveclient import service_catalog
-import six.moves.urllib.parse as urlparse
-
try:
import eventlet as sleep_lib
except ImportError:
diff --git a/troveclient/common.py b/troveclient/common.py
index dc7a94a..9c99b53 100644
--- a/troveclient/common.py
+++ b/troveclient/common.py
@@ -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):
diff --git a/troveclient/exceptions.py b/troveclient/exceptions.py
index d232a69..27a6cf0 100644
--- a/troveclient/exceptions.py
+++ b/troveclient/exceptions.py
@@ -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):
diff --git a/troveclient/openstack/common/__init__.py b/troveclient/openstack/common/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/troveclient/openstack/common/__init__.py
+++ /dev/null
diff --git a/troveclient/openstack/common/apiclient/__init__.py b/troveclient/openstack/common/apiclient/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/troveclient/openstack/common/apiclient/__init__.py
+++ /dev/null
diff --git a/troveclient/openstack/common/apiclient/fake_client.py b/troveclient/openstack/common/apiclient/fake_client.py
deleted file mode 100644
index 2cee578..0000000
--- a/troveclient/openstack/common/apiclient/fake_client.py
+++ /dev/null
@@ -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,
- })
diff --git a/troveclient/service_catalog.py b/troveclient/service_catalog.py
index 921ffa1..19bdda0 100644
--- a/troveclient/service_catalog.py
+++ b/troveclient/service_catalog.py
@@ -16,7 +16,7 @@
# limitations under the License.
-from troveclient.openstack.common.apiclient import exceptions
+from troveclient.apiclient import exceptions
class ServiceCatalog(object):
diff --git a/troveclient/shell.py b/troveclient/shell.py
index 6b9080d..0466f37 100644
--- a/troveclient/shell.py
+++ b/troveclient/shell.py
@@ -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
diff --git a/troveclient/tests/test_base.py b/troveclient/tests/test_base.py
index f0a5144..e3e8970 100644
--- a/troveclient/tests/test_base.py
+++ b/troveclient/tests/test_base.py
@@ -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
"""
diff --git a/troveclient/tests/test_client.py b/troveclient/tests/test_client.py
index 789e353..0d858d4 100644
--- a/troveclient/tests/test_client.py
+++ b/troveclient/tests/test_client.py
@@ -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
diff --git a/troveclient/utils.py b/troveclient/utils.py
index 65accef..9fb12b1 100644
--- a/troveclient/utils.py
+++ b/troveclient/utils.py
@@ -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):
diff --git a/troveclient/v1/limits.py b/troveclient/v1/limits.py
index 2e4f5d7..1f40297 100644
--- a/troveclient/v1/limits.py
+++ b/troveclient/v1/limits.py
@@ -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):