move old oslo-incubator code out of openstack/common

As part of the first community-wide goal, 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 a new i18n module was created. There is no oslo.apiclient
library or equivalent, the recommended solution is to move it
in tree and maintain it there.

Change-Id: Ia788313e0926dc872a87b090ef0a350898bfb079
This commit is contained in:
Steve Martinelli 2016-10-29 18:05:26 +02:00
parent dc7e779891
commit c1141ed5be
29 changed files with 102 additions and 115 deletions

View File

@ -37,7 +37,7 @@ import os
import six
from stevedore import extension
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.apiclient import exceptions
_discovered_plugins = {}
@ -54,7 +54,7 @@ def discover_auth_systems():
def add_plugin(ext):
_discovered_plugins[ext.name] = ext.plugin
ep_namespace = "ceilometerclient.openstack.common.apiclient.auth"
ep_namespace = "ceilometerclient.apiclient.auth"
mgr = extension.ExtensionManager(ep_namespace)
mgr.map(add_plugin)
@ -156,8 +156,7 @@ class BaseAuthPlugin(object):
@classmethod
def add_opts(cls, parser):
"""Populate the parser with the options for this plugin.
"""
"""Populate the parser with the options for this plugin."""
for opt in cls.opt_names:
# use `BaseAuthPlugin.common_opt_names` since it is never
# changed in child classes
@ -166,8 +165,7 @@ class BaseAuthPlugin(object):
@classmethod
def add_common_opts(cls, parser):
"""Add options that are common for several plugins.
"""
"""Add options that are common for several plugins."""
for opt in cls.common_opt_names:
cls._parser_add_opt(parser, opt)
@ -204,8 +202,7 @@ class BaseAuthPlugin(object):
@abc.abstractmethod
def _do_authenticate(self, http_client):
"""Protected method for authentication.
"""
"""Protected method for authentication."""
def sufficient_options(self):
"""Check if all required options are present.

View File

@ -40,13 +40,13 @@ Base utilities to build API operation managers and objects on top of.
import abc
import copy
from oslo_utils import reflection
from oslo_utils import strutils
import six
from six.moves.urllib import parse
from oslo_utils import reflection
from ceilometerclient.openstack.common._i18n import _
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.apiclient import exceptions
from ceilometerclient.i18n import _
def getid(obj):
@ -470,8 +470,7 @@ class Resource(object):
@property
def human_id(self):
"""Human-readable ID which can be used for bash completion.
"""
"""Human-readable ID which can be used for bash completion."""
if self.HUMAN_ID:
name = getattr(self, self.NAME_ATTR, None)
if name is not None:

View File

@ -38,8 +38,8 @@ from oslo_utils import encodeutils
from oslo_utils import importutils
import requests
from ceilometerclient.openstack.common._i18n import _
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.apiclient import exceptions
from ceilometerclient.i18n import _
_logger = logging.getLogger(__name__)
SENSITIVE_HEADERS = ('X-Auth-Token', 'X-Subject-Token',)
@ -64,7 +64,7 @@ class HTTPClient(object):
into terminal and send the same request with curl.
"""
user_agent = "ceilometerclient.openstack.common.apiclient"
user_agent = "ceilometerclient.apiclient"
def __init__(self,
auth_plugin,

View File

@ -38,12 +38,11 @@ import sys
import six
from ceilometerclient.openstack.common._i18n import _
from ceilometerclient.i18n import _
class ClientException(Exception):
"""The base exception class for all exceptions this library raises.
"""
"""The base exception class for all exceptions this library raises."""
pass
@ -118,8 +117,7 @@ class AmbiguousEndpoints(EndpointException):
class HttpError(ClientException):
"""The base exception class for all HTTP exceptions.
"""
"""The base exception class for all HTTP exceptions."""
http_status = 0
message = _("HTTP Error")

View File

@ -43,7 +43,7 @@ import requests
import six
from six.moves.urllib import parse
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.apiclient import client
def assert_has_keys(dct, required=None, optional=None):
@ -59,8 +59,7 @@ def assert_has_keys(dct, required=None, optional=None):
class TestResponse(requests.Response):
"""Wrap requests.Response and provide a convenient initialization.
"""
"""Wrap requests.Response and provide a convenient initialization."""
def __init__(self, data):
super(TestResponse, self).__init__()
@ -99,8 +98,7 @@ class FakeHTTPClient(client.HTTPClient):
super(FakeHTTPClient, self).__init__(*args, **kwargs)
def assert_called(self, method, url, body=None, pos=-1):
"""Assert than an API method was just called.
"""
"""Assert than an API method was just called."""
expected = (method, url)
called = self.callstack[pos][0:2]
assert self.callstack, \
@ -115,8 +113,7 @@ class FakeHTTPClient(client.HTTPClient):
(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.
"""
"""Assert than an API method was called anytime in the test."""
expected = (method, url)
assert self.callstack, \

View File

@ -28,8 +28,8 @@ from oslo_utils import encodeutils
from oslo_utils import uuidutils
import six
from ceilometerclient.openstack.common._i18n import _
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.apiclient import exceptions
from ceilometerclient.i18n import _
def find_resource(manager, name_or_id, **find_args):

View File

@ -23,10 +23,10 @@ from oslo_utils import importutils
from oslo_utils import strutils
import six.moves.urllib.parse as urlparse
from ceilometerclient.apiclient import auth
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import exceptions
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import auth
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import exceptions
def _discover_auth_versions(session, auth_url):

View File

@ -19,9 +19,9 @@ Base utilities to build API operation managers and objects on top of.
import copy
from ceilometerclient.apiclient import base
from ceilometerclient.apiclient import exceptions
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import base
from ceilometerclient.openstack.common.apiclient import exceptions
def getid(obj):

37
ceilometerclient/i18n.py Normal file
View File

@ -0,0 +1,37 @@
# Copyright 2014 IBM Corp.
#
# 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.
"""oslo.i18n integration module.
See http://docs.openstack.org/developer/oslo.i18n/usage.html .
"""
import oslo_i18n
_translators = oslo_i18n.TranslatorFactory(domain='ceilometerclient')
# The primary translation function using the well-known name "_"
_ = _translators.primary
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical

View File

@ -1,45 +0,0 @@
# 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.
"""oslo.i18n integration module.
See http://docs.openstack.org/developer/oslo.i18n/usage.html
"""
try:
import oslo_i18n
# NOTE(dhellmann): This reference to o-s-l-o will be replaced by the
# application name when this module is synced into the separate
# repository. It is OK to have more than one translation function
# using the same domain, since there will still only be one message
# catalog.
_translators = oslo_i18n.TranslatorFactory(domain='ceilometerclient')
# The primary translation function using the well-known name "_"
_ = _translators.primary
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
except ImportError:
# NOTE(dims): Support for cases where a project wants to use
# code from oslo-incubator, but is not ready to be internationalized
# (like tempest)
_ = _LI = _LW = _LE = _LC = lambda x: x

View File

@ -19,9 +19,9 @@ from keystoneauth1 import session as ks_session
import mock
import requests
from ceilometerclient.apiclient import exceptions
from ceilometerclient import client
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.tests.unit import utils
from ceilometerclient.v2 import client as v2client
@ -132,7 +132,7 @@ class ClientTest(utils.BaseTestCase):
'user_agent': None,
'debug': None,
}
cls = 'ceilometerclient.openstack.common.apiclient.client.HTTPClient'
cls = 'ceilometerclient.apiclient.client.HTTPClient'
with mock.patch(cls) as mocked:
self.create_client(env)
mocked.assert_called_with(**expected)
@ -194,7 +194,7 @@ class ClientTestWithAodh(ClientTest):
def create_client(env, api_version=2, endpoint=None, exclude=[]):
env = dict((k, v) for k, v in env.items()
if k not in exclude)
with mock.patch('ceilometerclient.openstack.common.apiclient.client.'
with mock.patch('ceilometerclient.apiclient.client.'
'HTTPClient.client_request',
return_value=mock.MagicMock()):
return client.get_client(api_version, **env)
@ -219,7 +219,7 @@ class ClientTestWithAodh(ClientTest):
def test_ceilometerclient_available_without_aodh_services_running(self):
env = FAKE_ENV.copy()
env.pop('auth_plugin', None)
with mock.patch('ceilometerclient.openstack.common.apiclient.client.'
with mock.patch('ceilometerclient.apiclient.client.'
'HTTPClient.client_request') as mocked_request:
mocked_request.side_effect = requests.exceptions.ConnectionError
ceiloclient = client.get_client(2, **env)
@ -250,7 +250,7 @@ class ClientAuthTest(utils.BaseTestCase):
def create_client(env, api_version=2, endpoint=None, exclude=[]):
env = dict((k, v) for k, v in env.items()
if k not in exclude)
with mock.patch('ceilometerclient.openstack.common.apiclient.client.'
with mock.patch('ceilometerclient.apiclient.client.'
'HTTPClient.client_request',
return_value=mock.MagicMock()):
return client.get_client(api_version, **env)

View File

@ -19,9 +19,9 @@ import mock
import six
from testtools import matchers
from ceilometerclient.apiclient import client as api_client
from ceilometerclient import client
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import client as api_client
from ceilometerclient import shell as ceilometer_shell
from ceilometerclient.tests.unit import utils

View File

@ -19,9 +19,9 @@ import six
from six.moves import xrange # noqa
import testtools
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.v2 import alarms
AN_ALARM = {u'alarm_actions': [u'http://site:8000/alarm'],

View File

@ -14,8 +14,8 @@
import testtools
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.v2 import capabilities

View File

@ -13,8 +13,8 @@
# under the License.
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.event_types

View File

@ -11,8 +11,8 @@
# 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 ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.events

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
from ceilometerclient.v2 import query

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
from ceilometerclient.v2 import query

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
from ceilometerclient.v2 import query

View File

@ -12,8 +12,8 @@
# 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 ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.resources

View File

@ -15,8 +15,8 @@
import copy
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.samples

View File

@ -651,7 +651,7 @@ class ShellAlarmGnocchiCommandTest(test_shell.ShellTestBase):
def _test_alarm_gnocchi_resources_arguments(self, action, argv):
self.make_env(test_shell.FAKE_V2_ENV)
with mock.patch.object(alarms.AlarmManager, action) as mocked:
with mock.patch('ceilometerclient.openstack.common.apiclient.'
with mock.patch('ceilometerclient.apiclient.'
'client.HTTPClient.client_request') as request:
request.site_effect = exceptions.EndpointNotFound
base_shell.main(argv)
@ -673,7 +673,7 @@ class ShellAlarmGnocchiCommandTest(test_shell.ShellTestBase):
def _test_alarm_gnocchi_aggr_by_metrics_arguments(self, action, argv):
self.make_env(test_shell.FAKE_V2_ENV)
with mock.patch.object(alarms.AlarmManager, action) as mocked:
with mock.patch('ceilometerclient.openstack.common.apiclient.'
with mock.patch('ceilometerclient.apiclient.'
'client.HTTPClient.client_request') as request:
request.site_effect = exceptions.EndpointNotFound
base_shell.main(argv)
@ -695,7 +695,7 @@ class ShellAlarmGnocchiCommandTest(test_shell.ShellTestBase):
def _test_alarm_gnocchi_aggr_by_resources_arguments(self, action, argv):
self.make_env(test_shell.FAKE_V2_ENV)
with mock.patch.object(alarms.AlarmManager, action) as mocked:
with mock.patch('ceilometerclient.openstack.common.apiclient.'
with mock.patch('ceilometerclient.apiclient.'
'client.HTTPClient.client_request') as request:
request.site_effect = exceptions.EndpointNotFound
base_shell.main(argv)
@ -1633,7 +1633,7 @@ class ShellShadowedArgsTest(test_shell.ShellTestBase):
'--user-id', 'the-user-id-i-want-to-set',
'--name', 'project-id-test'] + args
with mock.patch.object(alarms.AlarmManager, method) as mocked:
with mock.patch('ceilometerclient.openstack.common.apiclient.'
with mock.patch('ceilometerclient.apiclient.'
'client.HTTPClient.client_request') as request:
request.site_effect = exceptions.EndpointNotFound
base_shell.main(cli_args)
@ -1724,7 +1724,7 @@ class ShellShadowedArgsTest(test_shell.ShellTestBase):
'--meter-unit', 'ns',
'--sample-volume', '10086',
]
with mock.patch('ceilometerclient.openstack.common.apiclient.client.'
with mock.patch('ceilometerclient.apiclient.client.'
'HTTPClient.client_request') as client_request:
client_request.site_effect = exceptions.EndpointNotFound
base_shell.main(cli_args)

View File

@ -12,8 +12,8 @@
# 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 ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.statistics

View File

@ -11,8 +11,8 @@
# 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 ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.trait_descriptions

View File

@ -11,8 +11,8 @@
# 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 ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.openstack.common.apiclient import fake_client
from ceilometerclient.apiclient import client
from ceilometerclient.apiclient import fake_client
from ceilometerclient.tests.unit import utils
import ceilometerclient.v2.traits

View File

@ -36,3 +36,7 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
[flake8]
show-source = True
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools
[hacking]
import_exceptions =
ceilometerclient.i18n