From b19c55df4bb30a65e3e6abfa977dd9e857a330a4 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 17 Jul 2017 12:38:35 -0400 Subject: [PATCH] Migrate the preprov creds module to tempest lib This commit migrates the preprovisioned credentials provider from tempest/common into tempest/lib. As part of this 2 dependencies are also migrated to lib: the InvalidTestResource exception class and the tempest.common.fixed_network module. Change-Id: Ib9e909aaaf81f7cb57e2382cec44598e918747b8 --- doc/source/library/credential_providers.rst | 7 +++++++ ...migrate-preprov-creds-ef61a046ee1ec604.yaml | 11 +++++++++++ tempest/api/compute/admin/test_servers.py | 2 +- .../servers/test_list_server_filters.py | 2 +- tempest/common/compute.py | 2 +- tempest/common/credentials_factory.py | 2 +- tempest/exceptions.py | 7 ------- tempest/{ => lib}/common/fixed_network.py | 2 +- tempest/{ => lib}/common/preprov_creds.py | 5 ++--- tempest/lib/exceptions.py | 4 ++++ tempest/test.py | 2 +- tempest/tests/common/test_admin_available.py | 2 +- tempest/tests/common/test_alt_available.py | 2 +- .../{ => lib}/common/test_preprov_creds.py | 18 +++++++++--------- tempest/tests/test_base_test.py | 2 +- 15 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 releasenotes/notes/migrate-preprov-creds-ef61a046ee1ec604.yaml rename tempest/{ => lib}/common/fixed_network.py (99%) rename tempest/{ => lib}/common/preprov_creds.py (99%) rename tempest/tests/{ => lib}/common/test_preprov_creds.py (97%) diff --git a/doc/source/library/credential_providers.rst b/doc/source/library/credential_providers.rst index fea20bfb13..6e142966b8 100644 --- a/doc/source/library/credential_providers.rst +++ b/doc/source/library/credential_providers.rst @@ -14,3 +14,10 @@ The dynamic credentials module .. automodule:: tempest.lib.common.dynamic_creds :members: + +-------------------------------------- +The pre-provisioned credentials module +-------------------------------------- + +.. automodule:: tempest.lib.common.preprov_creds + :members: diff --git a/releasenotes/notes/migrate-preprov-creds-ef61a046ee1ec604.yaml b/releasenotes/notes/migrate-preprov-creds-ef61a046ee1ec604.yaml new file mode 100644 index 0000000000..aa5f71a203 --- /dev/null +++ b/releasenotes/notes/migrate-preprov-creds-ef61a046ee1ec604.yaml @@ -0,0 +1,11 @@ +--- +features: + - The tempest module tempest.common.preprov_creds which is used to provide + credentials from a list of preprovisioned resources has been migrated into + tempest lib at tempest.lib.common.preprov_creds. + - The InvalidTestResource exception class from tempest.exceptions has been + migrated into tempest.lib.exceptions + - The tempest module tempest.common.fixed_network which provided utilities for + finding fixed networks by and helpers for picking the network to use when + multiple tenant networks are available has been migrated into tempest lib + at tempest.lib.common.fixed_network. diff --git a/tempest/api/compute/admin/test_servers.py b/tempest/api/compute/admin/test_servers.py index 0521ccaa90..d9a78009c8 100644 --- a/tempest/api/compute/admin/test_servers.py +++ b/tempest/api/compute/admin/test_servers.py @@ -14,8 +14,8 @@ from tempest.api.compute import base from tempest.common import compute -from tempest.common import fixed_network from tempest.common import waiters +from tempest.lib.common import fixed_network from tempest.lib.common.utils import data_utils from tempest.lib import decorators diff --git a/tempest/api/compute/servers/test_list_server_filters.py b/tempest/api/compute/servers/test_list_server_filters.py index 921b7da494..a4ed8e11fc 100644 --- a/tempest/api/compute/servers/test_list_server_filters.py +++ b/tempest/api/compute/servers/test_list_server_filters.py @@ -15,9 +15,9 @@ import testtools from tempest.api.compute import base -from tempest.common import fixed_network from tempest.common import waiters from tempest import config +from tempest.lib.common import fixed_network from tempest.lib.common.utils import data_utils from tempest.lib import decorators diff --git a/tempest/common/compute.py b/tempest/common/compute.py index 9f467fe555..e3fbfb8b35 100644 --- a/tempest/common/compute.py +++ b/tempest/common/compute.py @@ -25,9 +25,9 @@ from six.moves.urllib import parse as urlparse from oslo_log import log as logging from oslo_utils import excutils -from tempest.common import fixed_network from tempest.common import waiters from tempest import config +from tempest.lib.common import fixed_network from tempest.lib.common import rest_client from tempest.lib.common.utils import data_utils diff --git a/tempest/common/credentials_factory.py b/tempest/common/credentials_factory.py index d96338be12..a4cf009adc 100644 --- a/tempest/common/credentials_factory.py +++ b/tempest/common/credentials_factory.py @@ -14,10 +14,10 @@ from oslo_concurrency import lockutils from tempest import clients -from tempest.common import preprov_creds from tempest import config from tempest.lib import auth from tempest.lib.common import dynamic_creds +from tempest.lib.common import preprov_creds from tempest.lib import exceptions CONF = config.CONF diff --git a/tempest/exceptions.py b/tempest/exceptions.py index a437761b3c..b5b2d71cfb 100644 --- a/tempest/exceptions.py +++ b/tempest/exceptions.py @@ -52,12 +52,5 @@ class ServerUnreachable(exceptions.TempestException): "the configured network") -# NOTE(andreaf) This exception is added here to facilitate the migration -# of get_network_from_name and preprov_creds to tempest.lib, and it should -# be migrated along with them -class InvalidTestResource(exceptions.TempestException): - message = "%(name)s is not a valid %(type)s, or the name is ambiguous" - - class RFCViolation(exceptions.RestClientException): message = "RFC Violation" diff --git a/tempest/common/fixed_network.py b/tempest/lib/common/fixed_network.py similarity index 99% rename from tempest/common/fixed_network.py rename to tempest/lib/common/fixed_network.py index 4032c90139..e2054a4d16 100644 --- a/tempest/common/fixed_network.py +++ b/tempest/lib/common/fixed_network.py @@ -14,8 +14,8 @@ import copy from oslo_log import log as logging -from tempest import exceptions from tempest.lib.common.utils import test_utils +from tempest.lib import exceptions LOG = logging.getLogger(__name__) diff --git a/tempest/common/preprov_creds.py b/tempest/lib/common/preprov_creds.py similarity index 99% rename from tempest/common/preprov_creds.py rename to tempest/lib/common/preprov_creds.py index 64cabb766c..cd3a10e4db 100644 --- a/tempest/common/preprov_creds.py +++ b/tempest/lib/common/preprov_creds.py @@ -20,10 +20,9 @@ from oslo_log import log as logging import six import yaml -from tempest.common import fixed_network -from tempest import exceptions from tempest.lib import auth from tempest.lib.common import cred_provider +from tempest.lib.common import fixed_network from tempest.lib import exceptions as lib_exc from tempest.lib.services import clients @@ -350,7 +349,7 @@ class PreProvisionedCredentialProvider(cred_provider.CredentialProvider): try: network = fixed_network.get_network_from_name( net_name, compute_network_client) - except exceptions.InvalidTestResource: + except lib_exc.InvalidTestResource: network = {} net_creds.set_resources(network=network) return net_creds diff --git a/tempest/lib/exceptions.py b/tempest/lib/exceptions.py index 68ce57a6ef..cdb8be9d02 100644 --- a/tempest/lib/exceptions.py +++ b/tempest/lib/exceptions.py @@ -269,3 +269,7 @@ class VolumeBackupException(TempestException): class DeleteErrorException(TempestException): message = ("Resource %(resource_id)s failed to delete " "and is in ERROR status") + + +class InvalidTestResource(TempestException): + message = "%(name)s is not a valid %(type)s, or the name is ambiguous" diff --git a/tempest/test.py b/tempest/test.py index fc846ffabf..317c0a74d7 100644 --- a/tempest/test.py +++ b/tempest/test.py @@ -26,10 +26,10 @@ import testtools from tempest import clients from tempest.common import credentials_factory as credentials -from tempest.common import fixed_network import tempest.common.validation_resources as vresources from tempest import config from tempest.lib.common import cred_client +from tempest.lib.common import fixed_network from tempest.lib import decorators from tempest.lib import exceptions as lib_exc diff --git a/tempest/tests/common/test_admin_available.py b/tempest/tests/common/test_admin_available.py index c3d248cc65..7b3b1b0274 100644 --- a/tempest/tests/common/test_admin_available.py +++ b/tempest/tests/common/test_admin_available.py @@ -53,7 +53,7 @@ class TestAdminAvailable(base.TestCase): 'password': 'p', 'types': ['admin']}) self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=accounts)) cfg.CONF.set_default('test_accounts_file', use_accounts_file, group='auth') diff --git a/tempest/tests/common/test_alt_available.py b/tempest/tests/common/test_alt_available.py index b9a89673d3..a425bb86df 100644 --- a/tempest/tests/common/test_alt_available.py +++ b/tempest/tests/common/test_alt_available.py @@ -40,7 +40,7 @@ class TestAltAvailable(base.TestCase): project_name="t%s" % ii, password="p") for ii in creds] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=accounts)) cfg.CONF.set_default('test_accounts_file', use_accounts_file, group='auth') diff --git a/tempest/tests/common/test_preprov_creds.py b/tempest/tests/lib/common/test_preprov_creds.py similarity index 97% rename from tempest/tests/common/test_preprov_creds.py rename to tempest/tests/lib/common/test_preprov_creds.py index d894c5ed5f..5402e470d8 100644 --- a/tempest/tests/common/test_preprov_creds.py +++ b/tempest/tests/lib/common/test_preprov_creds.py @@ -24,10 +24,10 @@ import fixtures from oslo_concurrency.fixture import lockutils as lockutils_fixtures from oslo_config import cfg -from tempest.common import preprov_creds from tempest import config from tempest.lib import auth from tempest.lib.common import cred_provider +from tempest.lib.common import preprov_creds from tempest.lib import exceptions as lib_exc from tempest.tests import base from tempest.tests import fake_config @@ -88,7 +88,7 @@ class TestPreProvisionedCredentials(base.TestCase): self.useFixture(lockutils_fixtures.ExternalLockFixture()) self.test_accounts = self._fake_accounts(cfg.CONF.identity.admin_role) self.accounts_mock = self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=self.test_accounts)) self.useFixture(fixtures.MockPatch( 'os.path.isfile', return_value=True)) @@ -271,7 +271,7 @@ class TestPreProvisionedCredentials(base.TestCase): def test_is_not_multi_user(self): self.test_accounts = [self.test_accounts[0]] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=self.test_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -335,7 +335,7 @@ class TestPreProvisionedCredentials(base.TestCase): 'password': 'p', 'roles': ['role-7', 'role-11'], 'resources': {'network': 'network-2'}}] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=test_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -363,7 +363,7 @@ class TestPreProvisionedCredentials(base.TestCase): admin_accounts = [x for x in self.test_accounts if 'test_admin' in x['username']] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=admin_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -381,7 +381,7 @@ class TestPreProvisionedCredentials(base.TestCase): admin_accounts = [x for x in self.test_accounts if 'test_admin' in x['username']] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=admin_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -402,7 +402,7 @@ class TestPreProvisionedCredentials(base.TestCase): {'username': 'test_admin1', 'tenant_name': 'test_tenant11', 'password': 'p', 'types': ['admin']}] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=test_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -416,7 +416,7 @@ class TestPreProvisionedCredentials(base.TestCase): {'username': 'test_admin1', 'tenant_name': 'test_tenant11', 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=test_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) @@ -427,7 +427,7 @@ class TestPreProvisionedCredentials(base.TestCase): non_admin_accounts = [x for x in self.test_accounts if 'test_admin' not in x['username']] self.useFixture(fixtures.MockPatch( - 'tempest.common.preprov_creds.read_accounts_yaml', + 'tempest.lib.common.preprov_creds.read_accounts_yaml', return_value=non_admin_accounts)) test_accounts_class = preprov_creds.PreProvisionedCredentialProvider( **self.fixed_params) diff --git a/tempest/tests/test_base_test.py b/tempest/tests/test_base_test.py index 01b8a72fd4..6c6f612e25 100644 --- a/tempest/tests/test_base_test.py +++ b/tempest/tests/test_base_test.py @@ -16,8 +16,8 @@ import mock from tempest import clients from tempest.common import credentials_factory as credentials -from tempest.common import fixed_network from tempest import config +from tempest.lib.common import fixed_network from tempest import test from tempest.tests import base from tempest.tests import fake_config