From 51c87074158193e3a7786d0252f0896190466414 Mon Sep 17 00:00:00 2001 From: chen-li Date: Thu, 24 Apr 2014 10:46:28 +0800 Subject: [PATCH] Integrate the new oslotest library There is a new support library named 'oslotest' extracted from oslo incubator. So, we add it to test-requirements.txt and remove deprecated modules from rally.openstack.common Change-Id: I1d9efaf2f8a5a4948c454ea3f2e75262479133e8 --- .../common/db/sqlalchemy/test_base.py | 4 +- .../common/db/sqlalchemy/test_migrations.py | 4 +- rally/openstack/common/fixture/mockpatch.py | 62 ------------ rally/openstack/common/fixture/moxstubout.py | 43 -------- rally/openstack/common/test.py | 99 ------------------- test-requirements.txt | 1 + .../benchmark/scenarios/glance/test_utils.py | 2 +- tests/benchmark/scenarios/nova/test_utils.py | 2 +- tests/cmd/commands/test_deployment.py | 4 +- tests/cmd/commands/test_task.py | 4 +- tests/cmd/commands/test_use.py | 5 +- tests/cmd/commands/test_verify.py | 5 +- tests/deploy/engines/test_devstack.py | 4 +- .../serverprovider/providers/test_lxc.py | 8 +- .../providers/test_openstack.py | 3 +- .../serverprovider/providers/test_virsh.py | 9 +- tests/test.py | 4 +- 17 files changed, 30 insertions(+), 233 deletions(-) delete mode 100644 rally/openstack/common/fixture/mockpatch.py delete mode 100644 rally/openstack/common/fixture/moxstubout.py delete mode 100644 rally/openstack/common/test.py diff --git a/rally/openstack/common/db/sqlalchemy/test_base.py b/rally/openstack/common/db/sqlalchemy/test_base.py index 9dc4f9f139..a572b0dbf6 100644 --- a/rally/openstack/common/db/sqlalchemy/test_base.py +++ b/rally/openstack/common/db/sqlalchemy/test_base.py @@ -23,7 +23,7 @@ import six from rally.openstack.common.db.sqlalchemy import session from rally.openstack.common.db.sqlalchemy import utils from rally.openstack.common.fixture import lockutils -from rally.openstack.common import test +from tests import test class DbFixture(fixtures.Fixture): @@ -51,7 +51,7 @@ class DbFixture(fixtures.Fixture): self.addCleanup(self.test.engine.dispose) -class DbTestCase(test.BaseTestCase): +class DbTestCase(test.TestCase): """Base class for testing of DB code. Using `DbFixture`. Intended to be the main database test case to use all diff --git a/rally/openstack/common/db/sqlalchemy/test_migrations.py b/rally/openstack/common/db/sqlalchemy/test_migrations.py index 9ab479b5c0..ce25c6c5f6 100644 --- a/rally/openstack/common/db/sqlalchemy/test_migrations.py +++ b/rally/openstack/common/db/sqlalchemy/test_migrations.py @@ -27,7 +27,7 @@ import sqlalchemy.exc from rally.openstack.common.db.sqlalchemy import utils from rally.openstack.common.gettextutils import _LE -from rally.openstack.common import test +from tests import test LOG = logging.getLogger(__name__) @@ -68,7 +68,7 @@ def _set_db_lock(lock_path=None, lock_prefix=None): return decorator -class BaseMigrationTestCase(test.BaseTestCase): +class BaseMigrationTestCase(test.TestCase): """Base class fort testing of migration utils.""" def __init__(self, *args, **kwargs): diff --git a/rally/openstack/common/fixture/mockpatch.py b/rally/openstack/common/fixture/mockpatch.py deleted file mode 100644 index 5ee4f9ece3..0000000000 --- a/rally/openstack/common/fixture/mockpatch.py +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# Copyright 2013 Hewlett-Packard Development Company, L.P. -# 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. - -############################################################################## -############################################################################## -## -## DO NOT MODIFY THIS FILE -## -## This file is being graduated to the rallytest library. Please make all -## changes there, and only backport critical fixes here. - dhellmann -## -############################################################################## -############################################################################## - -import fixtures -import mock - - -class PatchObject(fixtures.Fixture): - """Deal with code around mock.""" - - def __init__(self, obj, attr, new=mock.DEFAULT, **kwargs): - self.obj = obj - self.attr = attr - self.kwargs = kwargs - self.new = new - - def setUp(self): - super(PatchObject, self).setUp() - _p = mock.patch.object(self.obj, self.attr, self.new, **self.kwargs) - self.mock = _p.start() - self.addCleanup(_p.stop) - - -class Patch(fixtures.Fixture): - - """Deal with code around mock.patch.""" - - def __init__(self, obj, new=mock.DEFAULT, **kwargs): - self.obj = obj - self.kwargs = kwargs - self.new = new - - def setUp(self): - super(Patch, self).setUp() - _p = mock.patch(self.obj, self.new, **self.kwargs) - self.mock = _p.start() - self.addCleanup(_p.stop) diff --git a/rally/openstack/common/fixture/moxstubout.py b/rally/openstack/common/fixture/moxstubout.py deleted file mode 100644 index 2d703b9bd5..0000000000 --- a/rally/openstack/common/fixture/moxstubout.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# Copyright 2013 Hewlett-Packard Development Company, L.P. -# 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. - -############################################################################## -############################################################################## -## -## DO NOT MODIFY THIS FILE -## -## This file is being graduated to the rallytest library. Please make all -## changes there, and only backport critical fixes here. - dhellmann -## -############################################################################## -############################################################################## - -import fixtures -from six.moves import mox - - -class MoxStubout(fixtures.Fixture): - """Deal with code around mox and stubout as a fixture.""" - - def setUp(self): - super(MoxStubout, self).setUp() - # emulate some of the mox stuff, we can't use the metaclass - # because it screws with our generators - self.mox = mox.Mox() - self.stubs = self.mox.stubs - self.addCleanup(self.mox.UnsetStubs) - self.addCleanup(self.mox.VerifyAll) diff --git a/rally/openstack/common/test.py b/rally/openstack/common/test.py deleted file mode 100644 index e20fb79e8f..0000000000 --- a/rally/openstack/common/test.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# 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. - -############################################################################## -############################################################################## -## -## DO NOT MODIFY THIS FILE -## -## This file is being graduated to the rallytest library. Please make all -## changes there, and only backport critical fixes here. - dhellmann -## -############################################################################## -############################################################################## - -"""Common utilities used in testing""" - -import logging -import os -import tempfile - -import fixtures -import testtools - -_TRUE_VALUES = ('True', 'true', '1', 'yes') -_LOG_FORMAT = "%(levelname)8s [%(name)s] %(message)s" - - -class BaseTestCase(testtools.TestCase): - - def setUp(self): - super(BaseTestCase, self).setUp() - self._set_timeout() - self._fake_output() - self._fake_logs() - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.TempHomeDir()) - self.tempdirs = [] - - def _set_timeout(self): - test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) - try: - test_timeout = int(test_timeout) - except ValueError: - # If timeout value is invalid do not set a timeout. - test_timeout = 0 - if test_timeout > 0: - self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) - - def _fake_output(self): - if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: - stdout = self.useFixture(fixtures.StringStream('stdout')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: - stderr = self.useFixture(fixtures.StringStream('stderr')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - - def _fake_logs(self): - if os.environ.get('OS_DEBUG') in _TRUE_VALUES: - level = logging.DEBUG - else: - level = logging.INFO - capture_logs = os.environ.get('OS_LOG_CAPTURE') in _TRUE_VALUES - if capture_logs: - self.useFixture( - fixtures.FakeLogger( - format=_LOG_FORMAT, - level=level, - nuke_handlers=capture_logs, - ) - ) - else: - logging.basicConfig(format=_LOG_FORMAT, level=level) - - def create_tempfiles(self, files, ext='.conf'): - tempfiles = [] - for (basename, contents) in files: - if not os.path.isabs(basename): - (fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext) - else: - path = basename + ext - fd = os.open(path, os.O_CREAT | os.O_WRONLY) - tempfiles.append(path) - try: - os.write(fd, contents) - finally: - os.close(fd) - return tempfiles diff --git a/test-requirements.txt b/test-requirements.txt index 3eaf8b0771..9f9145aac0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,3 +9,4 @@ testtools>=0.9.34 sphinx>=1.1.2,<1.2 oslosphinx +oslotest diff --git a/tests/benchmark/scenarios/glance/test_utils.py b/tests/benchmark/scenarios/glance/test_utils.py index 4e6096c45e..1793c2c9e8 100644 --- a/tests/benchmark/scenarios/glance/test_utils.py +++ b/tests/benchmark/scenarios/glance/test_utils.py @@ -13,11 +13,11 @@ # under the License. import mock +from oslotest import mockpatch from rally.benchmark.scenarios.glance import utils from rally.benchmark import utils as butils from rally import exceptions as rally_exceptions -from rally.openstack.common.fixture import mockpatch from tests.benchmark.scenarios import test_utils from tests import fakes from tests import test diff --git a/tests/benchmark/scenarios/nova/test_utils.py b/tests/benchmark/scenarios/nova/test_utils.py index 603f99b66c..c4a429536a 100644 --- a/tests/benchmark/scenarios/nova/test_utils.py +++ b/tests/benchmark/scenarios/nova/test_utils.py @@ -15,11 +15,11 @@ import mock from oslo.config import cfg +from oslotest import mockpatch from rally.benchmark.scenarios.nova import utils from rally.benchmark import utils as butils from rally import exceptions as rally_exceptions -from rally.openstack.common.fixture import mockpatch from tests.benchmark.scenarios import test_utils from tests import fakes from tests import test diff --git a/tests/cmd/commands/test_deployment.py b/tests/cmd/commands/test_deployment.py index 943518067b..659098ceb2 100644 --- a/tests/cmd/commands/test_deployment.py +++ b/tests/cmd/commands/test_deployment.py @@ -19,10 +19,10 @@ import uuid from rally.cmd.commands import deployment from rally import exceptions -from rally.openstack.common import test +from tests import test -class DeploymentCommandsTestCase(test.BaseTestCase): +class DeploymentCommandsTestCase(test.TestCase): def setUp(self): super(DeploymentCommandsTestCase, self).setUp() self.deployment = deployment.DeploymentCommands() diff --git a/tests/cmd/commands/test_task.py b/tests/cmd/commands/test_task.py index 8313d96ad4..81376af772 100644 --- a/tests/cmd/commands/test_task.py +++ b/tests/cmd/commands/test_task.py @@ -18,10 +18,10 @@ import uuid from rally.cmd.commands import task from rally import exceptions -from rally.openstack.common import test +from tests import test -class TaskCommandsTestCase(test.BaseTestCase): +class TaskCommandsTestCase(test.TestCase): def setUp(self): super(TaskCommandsTestCase, self).setUp() diff --git a/tests/cmd/commands/test_use.py b/tests/cmd/commands/test_use.py index 8fc1c1e83d..c41de27ce4 100644 --- a/tests/cmd/commands/test_use.py +++ b/tests/cmd/commands/test_use.py @@ -19,14 +19,13 @@ import uuid from rally.cmd.commands import use from rally.cmd import envutils -from rally.openstack.common import test - from rally import exceptions +from tests import test MOD = 'rally.cmd.commands.use.' -class UseCommandsTestCase(test.BaseTestCase): +class UseCommandsTestCase(test.TestCase): def setUp(self): super(UseCommandsTestCase, self).setUp() self.use = use.UseCommands() diff --git a/tests/cmd/commands/test_verify.py b/tests/cmd/commands/test_verify.py index 3b0e1968cb..24d364c6b0 100644 --- a/tests/cmd/commands/test_verify.py +++ b/tests/cmd/commands/test_verify.py @@ -13,15 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. - import mock import uuid from rally.cmd.commands import verify -from rally.openstack.common import test +from tests import test -class VerifyCommandsTestCase(test.BaseTestCase): +class VerifyCommandsTestCase(test.TestCase): def setUp(self): super(VerifyCommandsTestCase, self).setUp() self.verify = verify.VerifyCommands() diff --git a/tests/deploy/engines/test_devstack.py b/tests/deploy/engines/test_devstack.py index 870a1c0637..216689a4a1 100644 --- a/tests/deploy/engines/test_devstack.py +++ b/tests/deploy/engines/test_devstack.py @@ -18,7 +18,7 @@ import mock import uuid from rally.deploy.engines import devstack -from rally.openstack.common import test +from tests import test SAMPLE_CONFIG = { @@ -35,7 +35,7 @@ SAMPLE_CONFIG = { DEVSTACK_REPO = 'https://github.com/openstack-dev/devstack.git' -class DevstackEngineTestCase(test.BaseTestCase): +class DevstackEngineTestCase(test.TestCase): def setUp(self): super(DevstackEngineTestCase, self).setUp() diff --git a/tests/deploy/serverprovider/providers/test_lxc.py b/tests/deploy/serverprovider/providers/test_lxc.py index c09c3b9453..57899f841a 100644 --- a/tests/deploy/serverprovider/providers/test_lxc.py +++ b/tests/deploy/serverprovider/providers/test_lxc.py @@ -19,13 +19,13 @@ import netaddr from rally.deploy.serverprovider.providers import lxc from rally import exceptions -from rally.openstack.common import test +from tests import test MOD_NAME = 'rally.deploy.serverprovider.providers.lxc.' -class HelperFunctionsTestCase(test.BaseTestCase): +class HelperFunctionsTestCase(test.TestCase): @mock.patch(MOD_NAME + 'open', create=True, return_value='fake_script') def test__get_script(self, m_open): @@ -48,7 +48,7 @@ class HelperFunctionsTestCase(test.BaseTestCase): m_sio.assert_called_once_with('fake_data v1 v2') -class LxcHostTestCase(test.BaseTestCase): +class LxcHostTestCase(test.TestCase): def setUp(self): super(LxcHostTestCase, self).setUp() @@ -250,7 +250,7 @@ class LxcHostTestCase(test.BaseTestCase): m_gso.mock_calls) -class LxcProviderTestCase(test.BaseTestCase): +class LxcProviderTestCase(test.TestCase): def setUp(self): super(LxcProviderTestCase, self).setUp() diff --git a/tests/deploy/serverprovider/providers/test_openstack.py b/tests/deploy/serverprovider/providers/test_openstack.py index d7c7e4fbf9..a2bc4a56c7 100644 --- a/tests/deploy/serverprovider/providers/test_openstack.py +++ b/tests/deploy/serverprovider/providers/test_openstack.py @@ -16,11 +16,12 @@ """Tests for OpenStack VM provider.""" import jsonschema + import mock +from oslotest import mockpatch from rally.deploy.serverprovider.providers import openstack as provider from rally import exceptions -from rally.openstack.common.fixture import mockpatch from tests import fakes from tests import test diff --git a/tests/deploy/serverprovider/providers/test_virsh.py b/tests/deploy/serverprovider/providers/test_virsh.py index bae1ed30b4..6384e616f4 100644 --- a/tests/deploy/serverprovider/providers/test_virsh.py +++ b/tests/deploy/serverprovider/providers/test_virsh.py @@ -14,16 +14,17 @@ # under the License. import jsonschema -import mock import netaddr import os +import mock +from oslotest import mockpatch + from rally.deploy.serverprovider.providers import virsh -from rally.openstack.common.fixture import mockpatch -from rally.openstack.common import test +from tests import test -class VirshProviderTestCase(test.BaseTestCase): +class VirshProviderTestCase(test.TestCase): def setUp(self): super(VirshProviderTestCase, self).setUp() self.deployment = mock.Mock() diff --git a/tests/test.py b/tests/test.py index b1c5ed92ea..4aed5bf78f 100644 --- a/tests/test.py +++ b/tests/test.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +from oslotest import base from rally import db from rally.openstack.common.fixture import config -from rally.openstack.common import test class DatabaseFixture(config.Config): @@ -29,7 +29,7 @@ class DatabaseFixture(config.Config): db.db_create() -class TestCase(test.BaseTestCase): +class TestCase(base.BaseTestCase): """Test case base class for all unit tests.""" pass