From 2bcf7396d89582d50e21ca6a844b255ee7481023 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 10 May 2016 08:41:36 -0500 Subject: [PATCH] Begin moving bits to osc_lib * command * commandmanager * exceptions * logs * parseractions * session * timing * utils * test fakes, utils --- .testr.conf | 2 +- README.rst | 20 +++++++++++++++++ openstackclient/api/auth.py | 2 +- osc_lib/__init__.py | 22 +++++++++++++++++++ osc_lib/cli/__init__.py | 0 .../common => osc_lib/cli}/parseractions.py | 2 +- osc_lib/command/__init__.py | 0 .../common => osc_lib/command}/command.py | 0 .../command}/commandmanager.py | 0 .../common => osc_lib/command}/timing.py | 2 +- .../common => osc_lib}/exceptions.py | 0 {openstackclient => osc_lib}/i18n.py | 2 +- {openstackclient/common => osc_lib}/logs.py | 0 .../common => osc_lib}/session.py | 0 osc_lib/tests/__init__.py | 0 osc_lib/tests/cli/__init__.py | 0 .../tests/cli}/test_parseractions.py | 4 ++-- osc_lib/tests/command/__init__.py | 0 .../tests/command}/test_command.py | 10 +++++---- .../tests/command}/test_commandmanager.py | 4 ++-- .../tests/command}/test_timing.py | 6 ++--- {openstackclient => osc_lib}/tests/fakes.py | 0 .../common => osc_lib/tests}/test_logs.py | 16 +++++++------- .../common => osc_lib/tests}/test_utils.py | 8 +++---- {openstackclient => osc_lib}/tests/utils.py | 2 +- {openstackclient/common => osc_lib}/utils.py | 2 +- tox.ini | 2 +- 27 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 osc_lib/__init__.py create mode 100644 osc_lib/cli/__init__.py rename {openstackclient/common => osc_lib/cli}/parseractions.py (99%) create mode 100644 osc_lib/command/__init__.py rename {openstackclient/common => osc_lib/command}/command.py (100%) rename {openstackclient/common => osc_lib/command}/commandmanager.py (100%) rename {openstackclient/common => osc_lib/command}/timing.py (96%) rename {openstackclient/common => osc_lib}/exceptions.py (100%) rename {openstackclient => osc_lib}/i18n.py (93%) rename {openstackclient/common => osc_lib}/logs.py (100%) rename {openstackclient/common => osc_lib}/session.py (100%) create mode 100644 osc_lib/tests/__init__.py create mode 100644 osc_lib/tests/cli/__init__.py rename {openstackclient/tests/common => osc_lib/tests/cli}/test_parseractions.py (98%) create mode 100644 osc_lib/tests/command/__init__.py rename {openstackclient/tests/common => osc_lib/tests/command}/test_command.py (80%) rename {openstackclient/tests/common => osc_lib/tests/command}/test_commandmanager.py (97%) rename {openstackclient/tests/common => osc_lib/tests/command}/test_timing.py (95%) rename {openstackclient => osc_lib}/tests/fakes.py (100%) rename {openstackclient/tests/common => osc_lib/tests}/test_logs.py (94%) rename {openstackclient/tests/common => osc_lib/tests}/test_utils.py (98%) rename {openstackclient => osc_lib}/tests/utils.py (98%) rename {openstackclient/common => osc_lib}/utils.py (99%) diff --git a/.testr.conf b/.testr.conf index 90c80c1..e2aa24a 100644 --- a/.testr.conf +++ b/.testr.conf @@ -2,7 +2,7 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ - ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./openstackclient/tests} $LISTOPT $IDOPTION + ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./osc_lib/tests} $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/README.rst b/README.rst index 1c76b07..83c72dc 100644 --- a/README.rst +++ b/README.rst @@ -39,3 +39,23 @@ Getting Started osc-lib can be installed from PyPI using pip:: pip install osc-lib + +Transition From OpenStackclient +=============================== + +This library was extracted from the main OSC repo after the OSC 2.4.0 release. +The following are the changes to imports that will cover the majority of +transition to using osc-lib: + +* openstackclient.common.parseractions -> osc_lib.cli.parseractions +* openstackclient.common.command -> osc_lib.command.command +* openstackclient.common.exceptions -> osc_lib.exceptions +* openstackclient.common.logs -> osc_lib.logs +* openstackclient.common.session -> osc_lib.session +* openstackclient.common.utils -> osc_lib.utils +* openstackclient.i18n -> osc_lib.i18n + +Also, some of the test fixtures and modules may be used: + +* openstackclient.tests.fakes -> osc_lib.tests.fakes +* openstackclient.tests.utils -> osc_lib.tests.utils diff --git a/openstackclient/api/auth.py b/openstackclient/api/auth.py index 3d6f7bc..c6e70de 100644 --- a/openstackclient/api/auth.py +++ b/openstackclient/api/auth.py @@ -22,7 +22,7 @@ from keystoneclient.auth import base from openstackclient.common import exceptions as exc from openstackclient.common import utils -from openstackclient.i18n import _ +from osc_lib.i18n import _ LOG = logging.getLogger(__name__) diff --git a/osc_lib/__init__.py b/osc_lib/__init__.py new file mode 100644 index 0000000..89deee3 --- /dev/null +++ b/osc_lib/__init__.py @@ -0,0 +1,22 @@ +# 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. +# + +__all__ = ['__version__'] + +import pbr.version + +version_info = pbr.version.VersionInfo('python-openstackclient') +try: + __version__ = version_info.version_string() +except AttributeError: + __version__ = None diff --git a/osc_lib/cli/__init__.py b/osc_lib/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstackclient/common/parseractions.py b/osc_lib/cli/parseractions.py similarity index 99% rename from openstackclient/common/parseractions.py rename to osc_lib/cli/parseractions.py index 77798f9..8125c18 100644 --- a/openstackclient/common/parseractions.py +++ b/osc_lib/cli/parseractions.py @@ -17,7 +17,7 @@ import argparse -from openstackclient.i18n import _ +from osc_lib.i18n import _ class KeyValueAction(argparse.Action): diff --git a/osc_lib/command/__init__.py b/osc_lib/command/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstackclient/common/command.py b/osc_lib/command/command.py similarity index 100% rename from openstackclient/common/command.py rename to osc_lib/command/command.py diff --git a/openstackclient/common/commandmanager.py b/osc_lib/command/commandmanager.py similarity index 100% rename from openstackclient/common/commandmanager.py rename to osc_lib/command/commandmanager.py diff --git a/openstackclient/common/timing.py b/osc_lib/command/timing.py similarity index 96% rename from openstackclient/common/timing.py rename to osc_lib/command/timing.py index 71c2fec..dd2aeb8 100644 --- a/openstackclient/common/timing.py +++ b/osc_lib/command/timing.py @@ -13,7 +13,7 @@ """Timing Implementation""" -from openstackclient.common import command +from osc_lib.command import command class Timing(command.Lister): diff --git a/openstackclient/common/exceptions.py b/osc_lib/exceptions.py similarity index 100% rename from openstackclient/common/exceptions.py rename to osc_lib/exceptions.py diff --git a/openstackclient/i18n.py b/osc_lib/i18n.py similarity index 93% rename from openstackclient/i18n.py rename to osc_lib/i18n.py index 1d09772..14a2543 100644 --- a/openstackclient/i18n.py +++ b/osc_lib/i18n.py @@ -15,7 +15,7 @@ import oslo_i18n -_translators = oslo_i18n.TranslatorFactory(domain='openstackclient') +_translators = oslo_i18n.TranslatorFactory(domain='osc_lib') # The primary translation function using the well-known name "_" _ = _translators.primary diff --git a/openstackclient/common/logs.py b/osc_lib/logs.py similarity index 100% rename from openstackclient/common/logs.py rename to osc_lib/logs.py diff --git a/openstackclient/common/session.py b/osc_lib/session.py similarity index 100% rename from openstackclient/common/session.py rename to osc_lib/session.py diff --git a/osc_lib/tests/__init__.py b/osc_lib/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/osc_lib/tests/cli/__init__.py b/osc_lib/tests/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstackclient/tests/common/test_parseractions.py b/osc_lib/tests/cli/test_parseractions.py similarity index 98% rename from openstackclient/tests/common/test_parseractions.py rename to osc_lib/tests/cli/test_parseractions.py index 5c5ca3d..3225f93 100644 --- a/openstackclient/tests/common/test_parseractions.py +++ b/osc_lib/tests/cli/test_parseractions.py @@ -15,8 +15,8 @@ import argparse -from openstackclient.common import parseractions -from openstackclient.tests import utils +from osc_lib.cli import parseractions +from osc_lib.tests import utils class TestKeyValueAction(utils.TestCase): diff --git a/osc_lib/tests/command/__init__.py b/osc_lib/tests/command/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstackclient/tests/common/test_command.py b/osc_lib/tests/command/test_command.py similarity index 80% rename from openstackclient/tests/common/test_command.py rename to osc_lib/tests/command/test_command.py index 7467d9e..f551bd2 100644 --- a/openstackclient/tests/common/test_command.py +++ b/osc_lib/tests/command/test_command.py @@ -14,8 +14,8 @@ import mock -from openstackclient.common import command -from openstackclient.tests import utils as test_utils +from osc_lib.command import command +from osc_lib.tests import utils as test_utils class FakeCommand(command.Command): @@ -29,5 +29,7 @@ class TestCommand(test_utils.TestCase): def test_command_has_logger(self): cmd = FakeCommand(mock.Mock(), mock.Mock()) self.assertTrue(hasattr(cmd, 'log')) - self.assertEqual('openstackclient.tests.common.test_command.' - 'FakeCommand', cmd.log.name) + self.assertEqual( + 'osc_lib.tests.command.test_command.FakeCommand', + cmd.log.name, + ) diff --git a/openstackclient/tests/common/test_commandmanager.py b/osc_lib/tests/command/test_commandmanager.py similarity index 97% rename from openstackclient/tests/common/test_commandmanager.py rename to osc_lib/tests/command/test_commandmanager.py index e2b274d..8763a4d 100644 --- a/openstackclient/tests/common/test_commandmanager.py +++ b/osc_lib/tests/command/test_commandmanager.py @@ -15,8 +15,8 @@ import mock -from openstackclient.common import commandmanager -from openstackclient.tests import utils +from osc_lib.command import commandmanager +from osc_lib.tests import utils class FakeCommand(object): diff --git a/openstackclient/tests/common/test_timing.py b/osc_lib/tests/command/test_timing.py similarity index 95% rename from openstackclient/tests/common/test_timing.py rename to osc_lib/tests/command/test_timing.py index e33bb7a..0fbf35a 100644 --- a/openstackclient/tests/common/test_timing.py +++ b/osc_lib/tests/command/test_timing.py @@ -15,9 +15,9 @@ import datetime -from openstackclient.common import timing -from openstackclient.tests import fakes -from openstackclient.tests import utils +from osc_lib.command import timing +from osc_lib.tests import fakes +from osc_lib.tests import utils timing_url = 'GET http://localhost:5000' diff --git a/openstackclient/tests/fakes.py b/osc_lib/tests/fakes.py similarity index 100% rename from openstackclient/tests/fakes.py rename to osc_lib/tests/fakes.py diff --git a/openstackclient/tests/common/test_logs.py b/osc_lib/tests/test_logs.py similarity index 94% rename from openstackclient/tests/common/test_logs.py rename to osc_lib/tests/test_logs.py index 0386cdf..03df2d7 100644 --- a/openstackclient/tests/common/test_logs.py +++ b/osc_lib/tests/test_logs.py @@ -14,8 +14,8 @@ import logging import mock -from openstackclient.common import logs -from openstackclient.tests import utils +from osc_lib import logs +from osc_lib.tests import utils class TestContext(utils.TestCase): @@ -121,7 +121,7 @@ class TestLogConfigurator(utils.TestCase): @mock.patch('logging.StreamHandler') @mock.patch('logging.getLogger') - @mock.patch('openstackclient.common.logs.set_warning_filter') + @mock.patch('osc_lib.logs.set_warning_filter') def test_init(self, warning_filter, getLogger, handle): getLogger.side_effect = self.loggers console_logger = mock.Mock() @@ -142,7 +142,7 @@ class TestLogConfigurator(utils.TestCase): self.assertFalse(configurator.dump_trace) @mock.patch('logging.getLogger') - @mock.patch('openstackclient.common.logs.set_warning_filter') + @mock.patch('osc_lib.logs.set_warning_filter') def test_init_no_debug(self, warning_filter, getLogger): getLogger.side_effect = self.loggers self.options.debug = True @@ -155,8 +155,8 @@ class TestLogConfigurator(utils.TestCase): @mock.patch('logging.FileHandler') @mock.patch('logging.getLogger') - @mock.patch('openstackclient.common.logs.set_warning_filter') - @mock.patch('openstackclient.common.logs._FileFormatter') + @mock.patch('osc_lib.logs.set_warning_filter') + @mock.patch('osc_lib.logs._FileFormatter') def test_init_log_file(self, formatter, warning_filter, getLogger, handle): getLogger.side_effect = self.loggers self.options.log_file = '/tmp/log_file' @@ -176,8 +176,8 @@ class TestLogConfigurator(utils.TestCase): @mock.patch('logging.FileHandler') @mock.patch('logging.getLogger') - @mock.patch('openstackclient.common.logs.set_warning_filter') - @mock.patch('openstackclient.common.logs._FileFormatter') + @mock.patch('osc_lib.logs.set_warning_filter') + @mock.patch('osc_lib.logs._FileFormatter') def test_configure(self, formatter, warning_filter, getLogger, handle): getLogger.side_effect = self.loggers configurator = logs.LogConfigurator(self.options) diff --git a/openstackclient/tests/common/test_utils.py b/osc_lib/tests/test_utils.py similarity index 98% rename from openstackclient/tests/common/test_utils.py rename to osc_lib/tests/test_utils.py index 2248d04..bdeee9b 100644 --- a/openstackclient/tests/common/test_utils.py +++ b/osc_lib/tests/test_utils.py @@ -18,10 +18,10 @@ import uuid import mock -from openstackclient.common import exceptions -from openstackclient.common import utils -from openstackclient.tests import fakes -from openstackclient.tests import utils as test_utils +from osc_lib import exceptions +from osc_lib.tests import fakes +from osc_lib.tests import utils as test_utils +from osc_lib import utils PASSWORD = "Pa$$w0rd" WASSPORD = "Wa$$p0rd" diff --git a/openstackclient/tests/utils.py b/osc_lib/tests/utils.py similarity index 98% rename from openstackclient/tests/utils.py rename to osc_lib/tests/utils.py index 319c1c1..03fd647 100644 --- a/openstackclient/tests/utils.py +++ b/osc_lib/tests/utils.py @@ -19,7 +19,7 @@ import os import fixtures import testtools -from openstackclient.tests import fakes +from osc_lib.tests import fakes class ParserException(Exception): diff --git a/openstackclient/common/utils.py b/osc_lib/utils.py similarity index 99% rename from openstackclient/common/utils.py rename to osc_lib/utils.py index daa65c2..98dcc06 100644 --- a/openstackclient/common/utils.py +++ b/osc_lib/utils.py @@ -23,7 +23,7 @@ import time from oslo_utils import importutils -from openstackclient.common import exceptions +from osc_lib import exceptions def find_resource(manager, name_or_id, **kwargs): diff --git a/tox.ini b/tox.ini index b032533..f291973 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ commands = {posargs} [testenv:cover] commands = - python setup.py test --coverage --testr-args='{posargs}' + python setup.py test --coverage --coverage-package-name=osc_lib --testr-args='{posargs}' coverage report [testenv:debug]