From 8c13c9d64f303d13a796989bd37305ce183fc493 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Thu, 8 Feb 2018 16:41:55 +0200 Subject: [PATCH] port more things to use envmanager * Port rally.task.engine to use EnvManager instead of Deployment * Rename method `set_deployment` of `rally.common.objects.Verifier` to `set_env`. It can be done in backward incompatible way, since the original method should be called only from rally.api * Extend `rally.common.objects.Verifier` with `env` property * Move OpenStackCredential under dict parenthood. object like style makes things too complicated. The simple dict should give more transparency. As for backward compatibility old-behaviour is kept. * Call `check_helth` method of EnvManager from TaskEngine instead of hardcoded for openstack `verify_connection` method. * Remove methods `get_validation_context` and `verify_connection` from OpenStackCredential. It should not be called anywhere. Change-Id: I76608deaefc68dbd5a99a3339584c9cf70e16ba0 --- .../openstack/context/keystone/users.py | 30 ++-- rally/plugins/openstack/credential.py | 87 +++++------ rally/plugins/openstack/osclients.py | 3 - tests/check_samples/test_task_samples.py | 11 +- tests/unit/fakes.py | 1 + .../openstack/context/keystone/test_users.py | 141 +++++++++--------- .../unit/plugins/openstack/test_credential.py | 21 +-- .../unit/plugins/openstack/test_osclients.py | 62 ++++---- 8 files changed, 167 insertions(+), 189 deletions(-) diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index cde4c6ad..283fd611 100644 --- a/rally/plugins/openstack/context/keystone/users.py +++ b/rally/plugins/openstack/context/keystone/users.py @@ -20,7 +20,6 @@ from oslo_config import cfg from rally.common import broker from rally.common import logging -from rally.common import objects from rally.common import utils as rutils from rally.common import validation from rally import consts @@ -105,19 +104,19 @@ class UserGenerator(context.Context): def __init__(self, context): super(UserGenerator, self).__init__(context) - deployment = objects.Deployment.get(context["task"]["deployment_uuid"]) - creds = deployment.get_credentials_for("openstack") + creds = self.env["platforms"]["openstack"] if creds.get("admin"): - context["admin"] = {"credential": creds["admin"]} + context["admin"] = { + "credential": credential.OpenStackCredential(**creds["admin"])} if creds["users"] and not (set(self.config) - {"user_choice_method"}): self.existing_users = creds["users"] else: self.existing_users = [] self.credential = context["admin"]["credential"] - project_domain = (self.credential.project_domain_name or + project_domain = (self.credential["project_domain_name"] or cfg.CONF.openstack.project_domain) - user_domain = (self.credential.user_domain_name or + user_domain = (self.credential["user_domain_name"] or cfg.CONF.openstack.user_domain) self.DEFAULT_FOR_NEW_USERS["project_domain"] = project_domain self.DEFAULT_FOR_NEW_USERS["user_domain"] = user_domain @@ -207,19 +206,19 @@ class UserGenerator(context.Context): domain_name=user_dom, default_role=default_role) user_credential = credential.OpenStackCredential( - auth_url=self.credential.auth_url, + auth_url=self.credential["auth_url"], username=user.name, password=password, tenant_name=self.context["tenants"][tenant_id]["name"], permission=consts.EndpointPermission.USER, project_domain_name=project_dom, user_domain_name=user_dom, - endpoint_type=self.credential.endpoint_type, - https_insecure=self.credential.https_insecure, - https_cacert=self.credential.https_cacert, - region_name=self.credential.region_name, - profiler_hmac_key=self.credential.profiler_hmac_key, - profiler_conn_str=self.credential.profiler_conn_str) + endpoint_type=self.credential["endpoint_type"], + https_insecure=self.credential["https_insecure"], + https_cacert=self.credential["https_cacert"], + region_name=self.credential["region_name"], + profiler_hmac_key=self.credential["profiler_hmac_key"], + profiler_conn_str=self.credential["profiler_conn_str"]) users.append({"id": user.id, "credential": user_credential, "tenant_id": tenant_id}) @@ -284,9 +283,10 @@ class UserGenerator(context.Context): msg="Failed to create the requested number of users.") def use_existing_users(self): - LOG.debug("Using existing users") + LOG.debug("Using existing users for OpenStack platform.") for user_credential in self.existing_users: - user_clients = user_credential.clients() + user_credential = credential.OpenStackCredential(**user_credential) + user_clients = osclients.Clients(user_credential) user_id = user_clients.keystone.auth_ref.user_id tenant_id = user_clients.keystone.auth_ref.project_id diff --git a/rally/plugins/openstack/credential.py b/rally/plugins/openstack/credential.py index 7ebf0da5..b7cde394 100644 --- a/rally/plugins/openstack/credential.py +++ b/rally/plugins/openstack/credential.py @@ -14,87 +14,82 @@ # under the License. from rally.common import logging -from rally import consts from rally.plugins.openstack import osclients LOG = logging.getLogger(__file__) -class OpenStackCredential(object): +class OpenStackCredential(dict): """Credential for OpenStack.""" def __init__(self, auth_url, username, password, tenant_name=None, project_name=None, - permission=consts.EndpointPermission.USER, + permission=None, region_name=None, endpoint_type=None, domain_name=None, endpoint=None, user_domain_name=None, project_domain_name=None, https_insecure=False, https_cacert=None, - profiler_hmac_key=None, profiler_conn_str=None): - self.auth_url = auth_url - self.username = username - self.password = password - self.tenant_name = tenant_name or project_name - self.permission = permission - self.region_name = region_name - self.endpoint_type = endpoint_type - self.domain_name = domain_name - self.user_domain_name = user_domain_name - self.project_domain_name = project_domain_name - self.endpoint = endpoint - self.https_insecure = https_insecure - self.https_cacert = https_cacert - self.profiler_hmac_key = profiler_hmac_key - self.profiler_conn_str = profiler_conn_str + profiler_hmac_key=None, profiler_conn_str=None, **kwargs): + if kwargs: + raise TypeError("%s" % kwargs) + + # TODO(andreykurilin): deprecate permission and endpoint + + super(OpenStackCredential, self).__init__([ + ("auth_url", auth_url), + ("username", username), + ("password", password), + ("tenant_name", (tenant_name or project_name)), + ("permission", permission), + ("endpoint", endpoint), + ("region_name", region_name), + ("endpoint_type", endpoint_type), + ("domain_name", domain_name), + ("user_domain_name", user_domain_name), + ("project_domain_name", project_domain_name), + ("https_insecure", https_insecure), + ("https_cacert", https_cacert), + ("profiler_hmac_key", profiler_hmac_key), + ("profiler_conn_str", profiler_conn_str) + ]) self._clients_cache = {} + def __getattr__(self, attr, default=None): + # TODO(andreykurilin): print warning to force everyone to use this + # object as raw dict as soon as we clean over code. + return self.get(attr, default) + # backward compatibility @property def insecure(self): LOG.warning("Property 'insecure' is deprecated since Rally 0.10.0. " "Use 'https_insecure' instead.") - return self.https_insecure + return self["https_insecure"] # backward compatibility @property def cacert(self): LOG.warning("Property 'cacert' is deprecated since Rally 0.10.0. " "Use 'https_cacert' instead.") - return self.https_cacert + return self["https_cacert"] def to_dict(self): - return {"auth_url": self.auth_url, - "username": self.username, - "password": self.password, - "tenant_name": self.tenant_name, - "region_name": self.region_name, - "endpoint_type": self.endpoint_type, - "domain_name": self.domain_name, - "endpoint": self.endpoint, - "https_insecure": self.https_insecure, - "https_cacert": self.https_cacert, - "user_domain_name": self.user_domain_name, - "project_domain_name": self.project_domain_name, - "permission": self.permission, - "profiler_hmac_key": self.profiler_hmac_key, - "profiler_conn_str": self.profiler_conn_str} - - def verify_connection(self): - if self.permission == consts.EndpointPermission.ADMIN: - self.clients().verified_keystone() - else: - self.clients().keystone() + return dict(self) def list_services(self): + LOG.warning("Method `list_services` of OpenStackCredentials is " + "deprecated since Rally 0.11.0. Use osclients instead.") return sorted([{"type": stype, "name": sname} for stype, sname in self.clients().services().items()], key=lambda s: s["name"]) - @classmethod - def get_validation_context(cls): - return {"users@openstack": {}} - + # this method is mostly used by validation step. let's refactor it and + # deprecated this def clients(self, api_info=None): return osclients.Clients(self, api_info=api_info, cache=self._clients_cache) + + def __deepcopy__(self, memodict=None): + import copy + return self.__class__(**copy.deepcopy(self.to_dict())) diff --git a/rally/plugins/openstack/osclients.py b/rally/plugins/openstack/osclients.py index 179d4885..a6851031 100644 --- a/rally/plugins/openstack/osclients.py +++ b/rally/plugins/openstack/osclients.py @@ -427,14 +427,11 @@ class Heat(OSClient): # when heatclient no longer uses it. kw_args = {} if self.credential.endpoint_type: - kw_args["endpoint_type"] = self.credential.endpoint_type kw_args["interface"] = self.credential.endpoint_type client = heat.Client( self.choose_version(version), session=self.keystone.get_session()[0], - # Remove endpoint once requirement is python-heatclient>=1.6 - endpoint=self._get_endpoint(service_type), endpoint_override=self._get_endpoint(service_type), **kw_args) return client diff --git a/tests/check_samples/test_task_samples.py b/tests/check_samples/test_task_samples.py index 9444fba2..6e13bf63 100644 --- a/tests/check_samples/test_task_samples.py +++ b/tests/check_samples/test_task_samples.py @@ -63,9 +63,14 @@ class TestTaskSamples(unittest.TestCase): deployment = rapi.deployment._get("MAIN") admin_cred = deployment.get_credentials_for("openstack")["admin"] - ctx = {"admin": {"credential": admin_cred}, - "task": {"uuid": self.__class__.__name__, - "deployment_uuid": deployment["uuid"]}} + ctx = { + "env": { + "platforms": { + "openstack": { + "admin": admin_cred.to_dict(), + "users": []}}}, + "task": {"uuid": self.__class__.__name__, + "deployment_uuid": deployment["uuid"]}} user_ctx = users.UserGenerator(ctx) user_ctx.setup() self.addCleanup(user_ctx.cleanup) diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index 50ed3fb6..f1dd70ae 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -1851,6 +1851,7 @@ class FakeDeployment(dict): "default": [{"admin": None, "users": []}]} dict.__init__(self, **kwargs) self.update_status = mock.Mock() + self.env_obj = mock.Mock() def get_platforms(self): return [platform for platform in self["credentials"]] diff --git a/tests/unit/plugins/openstack/context/keystone/test_users.py b/tests/unit/plugins/openstack/context/keystone/test_users.py index 6f147515..eb21dbfb 100644 --- a/tests/unit/plugins/openstack/context/keystone/test_users.py +++ b/tests/unit/plugins/openstack/context/keystone/test_users.py @@ -31,24 +31,29 @@ class UserGeneratorBaseTestCase(test.ScenarioTestCase): self.osclients = self.osclients_patcher.start() self.addCleanup(self.osclients_patcher.stop) - self.deployment_patcher = mock.patch("%s.objects.Deployment.get" % CTX) - self.deployment_get = self.deployment_patcher.start() - self.addCleanup(self.deployment_patcher.stop) - self.deployment_uuid = "deployment_id" - self.admin_cred = mock.MagicMock() + + self.admin_cred = { + "username": "root", "password": "qwerty", + "auth_url": "https://example.com", + "project_domain_name": "foo", + "user_domain_name": "bar"} + + self.platforms = { + "openstack": { + "admin": self.admin_cred, + "users": [] + } + } self.context.update({ "config": {"users": {}}, - "admin": {"credential": self.admin_cred}, - "users": [], + "env": {"platforms": self.platforms}, "task": {"uuid": "task_id", "deployment_uuid": self.deployment_uuid} }) def test___init__for_new_users(self): - deployment = self.deployment_get.return_value - deployment.get_credentials_for.return_value = {"users": []} self.context["config"]["users"] = { "tenants": 1, "users_per_tenant": 1, "resource_management_workers": 1} @@ -56,36 +61,27 @@ class UserGeneratorBaseTestCase(test.ScenarioTestCase): user_generator = users.UserGenerator(self.context) self.assertEqual([], user_generator.existing_users) - self.assertEqual(self.admin_cred.project_domain_name, + self.assertEqual(self.admin_cred["project_domain_name"], user_generator.config["project_domain"]) - self.assertEqual(self.admin_cred.user_domain_name, + self.assertEqual(self.admin_cred["user_domain_name"], user_generator.config["user_domain"]) - self.deployment_get.assert_called_once_with(self.deployment_uuid) - deployment.get_credentials_for.assert_called_once_with("openstack") - - self.deployment_get.reset_mock() - deployment.get_credentials_for.reset_mock() - # the case #2 - existing users are presented in deployment but # the user forces to create new ones - deployment.get_credentials_for.return_value = {"users": [mock.Mock()]} + self.platforms["openstack"]["users"] = [mock.Mock()] user_generator = users.UserGenerator(self.context) self.assertEqual([], user_generator.existing_users) - self.assertEqual(self.admin_cred.project_domain_name, + self.assertEqual(self.admin_cred["project_domain_name"], user_generator.config["project_domain"]) - self.assertEqual(self.admin_cred.user_domain_name, + self.assertEqual(self.admin_cred["user_domain_name"], user_generator.config["user_domain"]) - self.deployment_get.assert_called_once_with(self.deployment_uuid) - deployment.get_credentials_for.assert_called_once_with("openstack") - def test___init__for_existing_users(self): - deployment = self.deployment_get.return_value foo_user = mock.Mock() - deployment.get_credentials_for.return_value = {"users": [foo_user]} + + self.platforms["openstack"]["users"] = [foo_user] user_generator = users.UserGenerator(self.context) @@ -93,12 +89,6 @@ class UserGeneratorBaseTestCase(test.ScenarioTestCase): self.assertEqual({"user_choice_method": "random"}, user_generator.config) - self.deployment_get.assert_called_once_with(self.deployment_uuid) - deployment.get_credentials_for.assert_called_once_with("openstack") - - self.deployment_get.reset_mock() - deployment.get_credentials_for.reset_mock() - # the case #2: the config with `user_choice_method` option self.context["config"]["users"] = {"user_choice_method": "foo"} @@ -107,9 +97,6 @@ class UserGeneratorBaseTestCase(test.ScenarioTestCase): self.assertEqual([foo_user], user_generator.existing_users) self.assertEqual({"user_choice_method": "foo"}, user_generator.config) - self.deployment_get.assert_called_once_with(self.deployment_uuid) - deployment.get_credentials_for.assert_called_once_with("openstack") - def test_setup(self): user_generator = users.UserGenerator(self.context) user_generator.use_existing_users = mock.Mock() @@ -167,26 +154,34 @@ class UserGeneratorForExistingUsersTestCase(test.ScenarioTestCase): self.osclients = self.osclients_patcher.start() self.addCleanup(self.osclients_patcher.stop) - self.deployment_patcher = mock.patch("%s.objects.Deployment.get" % CTX) - self.deployment_get = self.deployment_patcher.start() - self.addCleanup(self.deployment_patcher.stop) - self.deployment_uuid = "deployment_id" + self.platforms = { + "openstack": { + "admin": {"username": "root", + "password": "qwerty", + "auth_url": "https://example.com"}, + "users": [] + } + } self.context.update({ "config": {"users": {}}, "users": [], + "env": {"platforms": self.platforms}, "task": {"uuid": "task_id", "deployment_uuid": self.deployment_uuid} }) - def test_use_existing_users(self): - user1 = mock.MagicMock(tenant_id="1", user_id="1", - tenant_name="proj", username="usr") - user2 = mock.MagicMock(tenant_id="1", user_id="2", - tenant_name="proj", username="usr") - user3 = mock.MagicMock(tenant_id="2", user_id="3", - tenant_name="proj", username="usr") + @mock.patch("%s.credential.OpenStackCredential" % CTX) + @mock.patch("%s.osclients.Clients" % CTX) + def test_use_existing_users(self, mock_clients, + mock_open_stack_credential): + user1 = {"tenant_name": "proj", "username": "usr", + "password": "pswd", "auth_url": "https://example.com"} + user2 = {"tenant_name": "proj", "username": "usr", + "password": "pswd", "auth_url": "https://example.com"} + user3 = {"tenant_name": "proj", "username": "usr", + "password": "pswd", "auth_url": "https://example.com"} user_list = [user1, user2, user3] @@ -197,21 +192,18 @@ class UserGeneratorForExistingUsersTestCase(test.ScenarioTestCase): @property def user_id(self): self.USER_ID_COUNT += 1 - return user_list[self.USER_ID_COUNT - 1].user_id + return "u%s" % self.USER_ID_COUNT @property def project_id(self): self.PROJECT_ID_COUNT += 1 - return user_list[self.PROJECT_ID_COUNT - 1].tenant_id + return "p%s" % (self.PROJECT_ID_COUNT % 2) auth_ref = AuthRef() - user1.clients.return_value.keystone.auth_ref = auth_ref - user2.clients.return_value.keystone.auth_ref = auth_ref - user3.clients.return_value.keystone.auth_ref = auth_ref + mock_clients.return_value.keystone.auth_ref = auth_ref - deployment = self.deployment_get.return_value - deployment.get_credentials_for.return_value = {"users": user_list} + self.platforms["openstack"]["users"] = user_list user_generator = users.UserGenerator(self.context) user_generator.setup() @@ -220,16 +212,16 @@ class UserGeneratorForExistingUsersTestCase(test.ScenarioTestCase): self.assertIn("tenants", self.context) self.assertIn("user_choice_method", self.context) self.assertEqual("random", self.context["user_choice_method"]) + + creds = mock_open_stack_credential.return_value self.assertEqual( - [{"id": user1.user_id, "credential": user1, - "tenant_id": user1.tenant_id}, - {"id": user2.user_id, "credential": user2, - "tenant_id": user2.tenant_id}, - {"id": user3.user_id, "credential": user3, - "tenant_id": user3.tenant_id}], self.context["users"] + [{"id": "u1", "credential": creds, "tenant_id": "p1"}, + {"id": "u2", "credential": creds, "tenant_id": "p0"}, + {"id": "u3", "credential": creds, "tenant_id": "p1"}], + self.context["users"] ) - self.assertEqual({"1": {"id": "1", "name": user1.tenant_name}, - "2": {"id": "2", "name": user3.tenant_name}}, + self.assertEqual({"p0": {"id": "p0", "name": creds.tenant_name}, + "p1": {"id": "p1", "name": creds.tenant_name}}, self.context["tenants"]) @@ -246,13 +238,15 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): self.osclients = self.osclients_patcher.start() self.addCleanup(self.osclients_patcher.stop) - self.deployment_patcher = mock.patch("%s.objects.Deployment.get" % CTX) - self.deployment_get = self.deployment_patcher.start() - self.addCleanup(self.deployment_patcher.stop) - # Force the case of creating new users - deployment = self.deployment_get.return_value - deployment.get_credentials_for.return_value = {"users": []} + self.platforms = { + "openstack": { + "admin": {"username": "root", + "password": "qwerty", + "auth_url": "https://example.com"}, + "users": [] + } + } self.context.update({ "config": { @@ -262,7 +256,7 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): "resource_management_workers": self.threads, } }, - "admin": {"credential": mock.MagicMock()}, + "env": {"platforms": self.platforms}, "users": [], "task": {"uuid": "task_id", "deployment_uuid": "dep_uuid"} }) @@ -451,7 +445,7 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): tmp_context["config"]["users"] = {"tenants": 1, "users_per_tenant": 2, "resource_management_workers": 1} - tmp_context["admin"]["credential"] = credential + tmp_context["env"]["platforms"]["openstack"]["admin"] = credential credential_dict = credential.to_dict() user_list = [mock.MagicMock(id="id_%d" % i) @@ -477,10 +471,11 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): excluded_keys = ["auth_url", "username", "password", "tenant_name", "region_name", "project_domain_name", - "user_domain_name"] + "user_domain_name", "permission"] for key in (set(credential_dict.keys()) - set(excluded_keys)): self.assertEqual(credential_dict[key], - user_credential_dict[key]) + user_credential_dict[key], + "The key '%s' differs." % key) tenants_ids = [] for t in ctx.context["tenants"].keys(): @@ -504,7 +499,8 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): "resource_management_workers": 1 } }, - "admin": {"credential": credential}, + "env": {"platforms": {"openstack": {"admin": credential, + "users": []}}}, "task": {"uuid": "task_id", "deployment_uuid": "deployment_id"} } @@ -526,7 +522,8 @@ class UserGeneratorForNewUsersTestCase(test.ScenarioTestCase): "resource_management_workers": 1 } }, - "admin": {"credential": credential}, + "env": {"platforms": {"openstack": {"admin": credential, + "users": []}}}, "task": {"uuid": "task_id", "deployment_uuid": "deployment_id"} } diff --git a/tests/unit/plugins/openstack/test_credential.py b/tests/unit/plugins/openstack/test_credential.py index c69f6c82..01c6433a 100644 --- a/tests/unit/plugins/openstack/test_credential.py +++ b/tests/unit/plugins/openstack/test_credential.py @@ -15,7 +15,6 @@ import mock -from rally import consts from rally.plugins.openstack import credential from tests.unit import test @@ -26,8 +25,7 @@ class OpenStackCredentialTestCase(test.TestCase): super(OpenStackCredentialTestCase, self).setUp() self.credential = credential.OpenStackCredential( "foo_url", "foo_user", "foo_password", - tenant_name="foo_tenant", - permission=consts.EndpointPermission.ADMIN) + tenant_name="foo_tenant") def test_to_dict(self): self.assertEqual({"auth_url": "foo_url", @@ -36,8 +34,8 @@ class OpenStackCredentialTestCase(test.TestCase): "tenant_name": "foo_tenant", "region_name": None, "domain_name": None, + "permission": None, "endpoint": None, - "permission": consts.EndpointPermission.ADMIN, "endpoint_type": None, "https_insecure": False, "https_cacert": None, @@ -47,21 +45,6 @@ class OpenStackCredentialTestCase(test.TestCase): "profiler_conn_str": None}, self.credential.to_dict()) - @mock.patch("rally.plugins.openstack.osclients.Clients") - def test_verify_connection_admin(self, mock_clients): - self.credential.verify_connection() - mock_clients.assert_called_once_with( - self.credential, api_info=None, cache={}) - mock_clients.return_value.verified_keystone.assert_called_once_with() - - @mock.patch("rally.plugins.openstack.osclients.Clients") - def test_verify_connection_user(self, mock_clients): - self.credential.permission = consts.EndpointPermission.USER - self.credential.verify_connection() - mock_clients.assert_called_once_with( - self.credential, api_info=None, cache={}) - mock_clients.return_value.keystone.assert_called_once_with() - @mock.patch("rally.plugins.openstack.osclients.Clients") def test_list_services(self, mock_clients): mock_clients.return_value.services.return_value = {"compute": "nova", diff --git a/tests/unit/plugins/openstack/test_osclients.py b/tests/unit/plugins/openstack/test_osclients.py index eaf42939..27b71749 100644 --- a/tests/unit/plugins/openstack/test_osclients.py +++ b/tests/unit/plugins/openstack/test_osclients.py @@ -19,12 +19,16 @@ from oslo_config import cfg from rally import consts from rally import exceptions +from rally import osclients as deprecated_osclients # noqa from rally.plugins.openstack import credential as oscredential from rally.plugins.openstack import osclients from tests.unit import fakes from tests.unit import test +PATH = "rally.plugins.openstack.osclients" + + @osclients.configure("dummy", supported_versions=("0.1", "1"), default_service_type="bar") class DummyClient(osclients.OSClient): @@ -93,7 +97,7 @@ class OSClientTestCase(test.TestCase, OSClientTestCaseUtils): self.assertEqual("foo", fake_client.choose_service_type("foo")) - @mock.patch("rally.osclients.Keystone.service_catalog") + @mock.patch("%s.Keystone.service_catalog" % PATH) @ddt.data( {"endpoint_type": None, "service_type": None, "region_name": None}, {"endpoint_type": "et", "service_type": "st", "region_name": "rn"} @@ -119,7 +123,7 @@ class OSClientTestCase(test.TestCase, OSClientTestCaseUtils): mock_url_for.assert_called_once_with(**call_args) mock_choose_service_type.assert_called_once_with(service_type) - @mock.patch("rally.osclients.Keystone.get_session") + @mock.patch("%s.Keystone.get_session" % PATH) def test__get_session(self, mock_keystone_get_session): osclient = osclients.OSClient(None, None, None) auth_url = "auth_url" @@ -263,7 +267,7 @@ class TestCreateKeystoneClient(test.TestCase, OSClientTestCaseUtils): keystone = osclients.Keystone(None, None, None) self.assertRaises(exceptions.RallyException, lambda: keystone.keystone) - @mock.patch("rally.osclients.Keystone.get_session") + @mock.patch("%s.Keystone.get_session" % PATH) def test_auth_ref(self, mock_keystone_get_session): session = mock.MagicMock() auth_plugin = mock.MagicMock() @@ -293,8 +297,8 @@ class TestCreateKeystoneClient(test.TestCase, OSClientTestCaseUtils): self.fail("keystone.auth_ref didn't raise" " exceptions.AuthenticationFailed") - @mock.patch("rally.osclients.LOG.exception") - @mock.patch("rally.osclients.logging.is_debug") + @mock.patch("%s.LOG.exception" % PATH) + @mock.patch("%s.logging.is_debug" % PATH) @mock.patch("keystoneauth1.identity.base.BaseIdentityPlugin.get_access") def test_auth_ref_debug(self, mock_get_access, mock_is_debug, mock_log_exception): @@ -326,11 +330,11 @@ class OSClientsTestCase(test.TestCase): self.fake_keystone = fakes.FakeKeystoneClient() keystone_patcher = mock.patch( - "rally.osclients.Keystone.create_client", + "%s.Keystone.create_client" % PATH, return_value=self.fake_keystone) self.mock_create_keystone_client = keystone_patcher.start() - self.auth_ref_patcher = mock.patch("rally.osclients.Keystone.auth_ref") + self.auth_ref_patcher = mock.patch("%s.Keystone.auth_ref" % PATH) self.auth_ref = self.auth_ref_patcher.start() self.service_catalog = self.auth_ref.service_catalog @@ -380,7 +384,7 @@ class OSClientsTestCase(test.TestCase): self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone) - @mock.patch("rally.osclients.Keystone.get_session") + @mock.patch("%s.Keystone.get_session" % PATH) def test_verified_keystone_authentication_fails(self, mock_keystone_get_session): self.auth_ref_patcher.stop() @@ -395,7 +399,7 @@ class OSClientsTestCase(test.TestCase): self.assertRaises(exceptions.AuthenticationFailed, self.clients.verified_keystone) - @mock.patch("rally.osclients.Nova._get_endpoint") + @mock.patch("%s.Nova._get_endpoint" % PATH) def test_nova(self, mock_nova__get_endpoint): fake_nova = fakes.FakeNovaClient() mock_nova__get_endpoint.return_value = "http://fake.to:2/fake" @@ -427,7 +431,7 @@ class OSClientsTestCase(test.TestCase): def test_nova_service_type(self): self.clients.nova.is_service_type_configurable() - @mock.patch("rally.osclients.Neutron._get_endpoint") + @mock.patch("%s.Neutron._get_endpoint" % PATH) def test_neutron(self, mock_neutron__get_endpoint): fake_neutron = fakes.FakeNeutronClient() mock_neutron__get_endpoint.return_value = "http://fake.to:2/fake" @@ -446,7 +450,7 @@ class OSClientsTestCase(test.TestCase): mock_neutron.client.Client.assert_called_once_with("2.0", **kw) self.assertEqual(fake_neutron, self.clients.cache["neutron"]) - @mock.patch("rally.osclients.Neutron._get_endpoint") + @mock.patch("%s.Neutron._get_endpoint" % PATH) def test_neutron_endpoint_type(self, mock_neutron__get_endpoint): fake_neutron = fakes.FakeNeutronClient() mock_neutron__get_endpoint.return_value = "http://fake.to:2/fake" @@ -454,7 +458,7 @@ class OSClientsTestCase(test.TestCase): mock_keystoneauth1 = mock.MagicMock() mock_neutron.client.Client.return_value = fake_neutron self.assertNotIn("neutron", self.clients.cache) - self.credential.endpoint_type = "internal" + self.credential["endpoint_type"] = "internal" with mock.patch.dict("sys.modules", {"neutronclient.neutron": mock_neutron, "keystoneauth1": mock_keystoneauth1}): @@ -467,7 +471,7 @@ class OSClientsTestCase(test.TestCase): mock_neutron.client.Client.assert_called_once_with("2.0", **kw) self.assertEqual(fake_neutron, self.clients.cache["neutron"]) - @mock.patch("rally.osclients.Heat._get_endpoint") + @mock.patch("%s.Heat._get_endpoint" % PATH) def test_heat(self, mock_heat__get_endpoint): fake_heat = fakes.FakeHeatClient() mock_heat__get_endpoint.return_value = "http://fake.to:2/fake" @@ -482,12 +486,11 @@ class OSClientsTestCase(test.TestCase): self.assertEqual(fake_heat, client) kw = { "session": mock_keystoneauth1.session.Session(), - "endpoint": mock_heat__get_endpoint.return_value, "endpoint_override": mock_heat__get_endpoint.return_value} mock_heat.client.Client.assert_called_once_with("1", **kw) self.assertEqual(fake_heat, self.clients.cache["heat"]) - @mock.patch("rally.osclients.Heat._get_endpoint") + @mock.patch("%s.Heat._get_endpoint" % PATH) def test_heat_endpoint_type_interface(self, mock_heat__get_endpoint): fake_heat = fakes.FakeHeatClient() mock_heat__get_endpoint.return_value = "http://fake.to:2/fake" @@ -495,8 +498,7 @@ class OSClientsTestCase(test.TestCase): mock_keystoneauth1 = mock.MagicMock() mock_heat.client.Client.return_value = fake_heat self.assertNotIn("heat", self.clients.cache) - self.credential.endpoint_type = "internal" - self.credential.interface = "internal" + self.credential["endpoint_type"] = "internal" with mock.patch.dict("sys.modules", {"heatclient": mock_heat, "keystoneauth1": mock_keystoneauth1}): @@ -504,14 +506,12 @@ class OSClientsTestCase(test.TestCase): self.assertEqual(fake_heat, client) kw = { "session": mock_keystoneauth1.session.Session(), - "endpoint": mock_heat__get_endpoint.return_value, "endpoint_override": mock_heat__get_endpoint.return_value, - "endpoint_type": "internal", "interface": "internal"} mock_heat.client.Client.assert_called_once_with("1", **kw) self.assertEqual(fake_heat, self.clients.cache["heat"]) - @mock.patch("rally.osclients.Glance._get_endpoint") + @mock.patch("%s.Glance._get_endpoint" % PATH) def test_glance(self, mock_glance__get_endpoint): fake_glance = fakes.FakeGlanceClient() mock_glance = mock.MagicMock() @@ -531,7 +531,7 @@ class OSClientsTestCase(test.TestCase): mock_glance.Client.assert_called_once_with(**kw) self.assertEqual(fake_glance, self.clients.cache["glance"]) - @mock.patch("rally.osclients.Cinder._get_endpoint") + @mock.patch("%s.Cinder._get_endpoint" % PATH) def test_cinder(self, mock_cinder__get_endpoint): fake_cinder = mock.MagicMock(client=fakes.FakeCinderClient()) mock_cinder = mock.MagicMock() @@ -551,7 +551,7 @@ class OSClientsTestCase(test.TestCase): "2", **kw) self.assertEqual(fake_cinder, self.clients.cache["cinder"]) - @mock.patch("rally.osclients.Manila._get_endpoint") + @mock.patch("%s.Manila._get_endpoint" % PATH) def test_manila(self, mock_manila__get_endpoint): mock_manila = mock.MagicMock() mock_manila__get_endpoint.return_value = "http://fake.to:2/fake" @@ -577,7 +577,7 @@ class OSClientsTestCase(test.TestCase): self.assertRaises(exceptions.RallyException, osclients.Manila.validate_version, "foo") - @mock.patch("rally.osclients.Ceilometer._get_endpoint") + @mock.patch("%s.Ceilometer._get_endpoint" % PATH) def test_ceilometer(self, mock_ceilometer__get_endpoint): fake_ceilometer = fakes.FakeCeilometerClient() mock_ceilometer = mock.MagicMock() @@ -649,7 +649,7 @@ class OSClientsTestCase(test.TestCase): self.assertEqual(mock_monasca.client.Client.return_value, self.clients.cache["monasca"]) - @mock.patch("rally.osclients.Ironic._get_endpoint") + @mock.patch("%s.Ironic._get_endpoint" % PATH) def test_ironic(self, mock_ironic__get_endpoint): fake_ironic = fakes.FakeIronicClient() mock_ironic = mock.MagicMock() @@ -669,7 +669,7 @@ class OSClientsTestCase(test.TestCase): mock_ironic.client.get_client.assert_called_once_with("1", **kw) self.assertEqual(fake_ironic, self.clients.cache["ironic"]) - @mock.patch("rally.osclients.Sahara._get_endpoint") + @mock.patch("%s.Sahara._get_endpoint" % PATH) def test_sahara(self, mock_sahara__get_endpoint): fake_sahara = fakes.FakeSaharaClient() mock_sahara = mock.MagicMock() @@ -710,7 +710,7 @@ class OSClientsTestCase(test.TestCase): self.assertEqual(fake_zaqar, self.clients.cache["zaqar"], mock_keystoneauth1.session.Session()) - @mock.patch("rally.osclients.Trove._get_endpoint") + @mock.patch("%s.Trove._get_endpoint" % PATH) def test_trove(self, mock_trove__get_endpoint): fake_trove = fakes.FakeTroveClient() mock_trove = mock.MagicMock() @@ -774,7 +774,7 @@ class OSClientsTestCase(test.TestCase): mock_swift.client.Connection.assert_called_once_with(**kw) self.assertEqual(fake_swift, self.clients.cache["swift"]) - @mock.patch("rally.osclients.EC2._get_endpoint") + @mock.patch("%s.EC2._get_endpoint" % PATH) def test_ec2(self, mock_ec2__get_endpoint): mock_boto = mock.Mock() self.fake_keystone.ec2 = mock.Mock() @@ -798,7 +798,7 @@ class OSClientsTestCase(test.TestCase): mock_boto.connect_ec2_endpoint.assert_called_once_with(**kw) self.assertEqual(fake_ec2, self.clients.cache["ec2"]) - @mock.patch("rally.osclients.Keystone.service_catalog") + @mock.patch("%s.Keystone.service_catalog" % PATH) def test_services(self, mock_keystone_service_catalog): available_services = {consts.ServiceType.IDENTITY: {}, consts.ServiceType.COMPUTE: {}, @@ -830,7 +830,7 @@ class OSClientsTestCase(test.TestCase): mock_murano.client.Client.assert_called_once_with("1", **kw) self.assertEqual(fake_murano, self.clients.cache["murano"]) - @mock.patch("rally.osclients.Keystone.get_session") + @mock.patch("%s.Keystone.get_session" % PATH) @ddt.data( {}, {"version": "2"}, @@ -900,7 +900,7 @@ class OSClientsTestCase(test.TestCase): mock_senlin.client.Client.return_value, self.clients.cache["senlin"]) - @mock.patch("rally.osclients.Magnum._get_endpoint") + @mock.patch("%s.Magnum._get_endpoint" % PATH) def test_magnum(self, mock_magnum__get_endpoint): fake_magnum = fakes.FakeMagnumClient() mock_magnum = mock.MagicMock() @@ -924,7 +924,7 @@ class OSClientsTestCase(test.TestCase): mock_magnum.client.Client.assert_called_once_with(**kw) self.assertEqual(fake_magnum, self.clients.cache["magnum"]) - @mock.patch("rally.osclients.Watcher._get_endpoint") + @mock.patch("%s.Watcher._get_endpoint" % PATH) def test_watcher(self, mock_watcher__get_endpoint): fake_watcher = fakes.FakeWatcherClient() mock_watcher = mock.MagicMock()