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
This commit is contained in:
parent
8b272caa4d
commit
51c8707415
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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)
|
@ -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)
|
@ -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
|
@ -9,3 +9,4 @@ testtools>=0.9.34
|
||||
|
||||
sphinx>=1.1.2,<1.2
|
||||
oslosphinx
|
||||
oslotest
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user