diff --git a/rally/plugins/openstack/verification/tempest/config.py b/rally/plugins/openstack/verification/tempest/config.py index 762d68d1..dc861378 100644 --- a/rally/plugins/openstack/verification/tempest/config.py +++ b/rally/plugins/openstack/verification/tempest/config.py @@ -87,7 +87,7 @@ class TempestConfigfileManager(object): """Class to create a Tempest config file.""" def __init__(self, deployment): - self.credential = deployment["admin"] + self.credential = deployment.get_credentials_for("openstack")["admin"] self.clients = osclients.Clients(objects.Credential(**self.credential)) self.available_services = self.clients.services().values() diff --git a/rally/plugins/openstack/verification/tempest/context.py b/rally/plugins/openstack/verification/tempest/context.py index f3912f93..c8a1022c 100644 --- a/rally/plugins/openstack/verification/tempest/context.py +++ b/rally/plugins/openstack/verification/tempest/context.py @@ -44,8 +44,8 @@ class TempestContext(context.VerifierContext): def __init__(self, ctx): super(TempestContext, self).__init__(ctx) - credential = self.verifier.deployment["admin"] - self.clients = osclients.Clients(objects.Credential(**credential)) + creds = self.verifier.deployment.get_credentials_for("openstack") + self.clients = osclients.Clients(objects.Credential(**creds["admin"])) self.available_services = self.clients.services().values() self.conf = configparser.ConfigParser() diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index b9a3715e..569d8113 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -1827,6 +1827,16 @@ class FakeUserContext(FakeContext): class FakeDeployment(dict): update_status = mock.Mock() + def __init__(self, **kwargs): + namespace = kwargs.pop("namespace", "openstack") + kwargs["credentials"] = { + namespace: [{"admin": kwargs.pop("admin", None), + "users": kwargs.pop("users", [])}]} + dict.__init__(self, **kwargs) + + def get_credentials_for(self, namespace): + return self["credentials"][namespace][0] + class FakeTask(dict): diff --git a/tests/unit/plugins/openstack/verification/tempest/test_config.py b/tests/unit/plugins/openstack/verification/tempest/test_config.py index 0d220630..cdf64137 100644 --- a/tests/unit/plugins/openstack/verification/tempest/test_config.py +++ b/tests/unit/plugins/openstack/verification/tempest/test_config.py @@ -18,6 +18,7 @@ import mock from oslo_config import cfg from rally.plugins.openstack.verification.tempest import config +from tests.unit import fakes from tests.unit import test @@ -51,7 +52,8 @@ class TempestConfigfileManagerTestCase(test.TestCase): mock.patch("rally.osclients.Clients").start() - self.tempest = config.TempestConfigfileManager(CREDS) + deployment = fakes.FakeDeployment(**CREDS) + self.tempest = config.TempestConfigfileManager(deployment) def test__configure_auth(self): self.tempest.conf.add_section("auth") diff --git a/tests/unit/plugins/openstack/verification/tempest/test_context.py b/tests/unit/plugins/openstack/verification/tempest/test_context.py index abfd6a9f..1aad9ac2 100644 --- a/tests/unit/plugins/openstack/verification/tempest/test_context.py +++ b/tests/unit/plugins/openstack/verification/tempest/test_context.py @@ -59,7 +59,8 @@ class TempestContextTestCase(test.TestCase): self.mock_isfile = mock.patch("os.path.isfile", return_value=True).start() - cfg = {"verifier": mock.Mock(deployment=CREDS), + self.deployment = fakes.FakeDeployment(**CREDS) + cfg = {"verifier": mock.Mock(deployment=self.deployment), "verification": {"uuid": "uuid"}} cfg["verifier"].manager.home_dir = "/p/a/t/h" cfg["verifier"].manager.configfile = "/fake/path/to/config" @@ -336,11 +337,13 @@ class TempestContextTestCase(test.TestCase): def test_setup(self, mock_clients, mock_create_dir, mock__create_tempest_roles, mock__configure_option, mock_open): - verifier = mock.MagicMock(deployment=CREDS) + self.deployment = fakes.FakeDeployment(**CREDS) + verifier = mock.Mock(deployment=self.deployment) verifier.manager.home_dir = "/p/a/t/h" # case #1: no neutron and heat mock_clients.return_value.services.return_value = {} + ctx = context.TempestContext({"verifier": verifier}) ctx.conf = mock.Mock() ctx.setup() @@ -376,6 +379,7 @@ class TempestContextTestCase(test.TestCase): # case #2: neutron and heat are presented mock_clients.return_value.services.return_value = { "network": "neutron", "orchestration": "heat"} + ctx = context.TempestContext({"verifier": verifier}) ctx.conf = mock.Mock() ctx.setup()