diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index c603d22b..98596c94 100644 --- a/rally/plugins/openstack/context/keystone/users.py +++ b/rally/plugins/openstack/context/keystone/users.py @@ -55,7 +55,7 @@ CONF.register_opts(USER_CONTEXT_OPTS, title="benchmark context options")) -@context.configure(name="users", order=100) +@context.configure(name="users", namespace="openstack", order=100) class UserGenerator(context.Context): """Context class for generating temporary users/tenants for benchmarks.""" diff --git a/rally/plugins/openstack/scenario.py b/rally/plugins/openstack/scenario.py index 86707c35..3f54aae2 100644 --- a/rally/plugins/openstack/scenario.py +++ b/rally/plugins/openstack/scenario.py @@ -13,14 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import functools import random from rally import osclients from rally.task import scenario -# NOTE(boris-42): Shortcut to remove import of both rally.task.scenario and -# rally.plugins.openstack.scenario -configure = scenario.configure +configure = functools.partial(scenario.configure, namespace="openstack") class OpenStackScenario(scenario.Scenario): @@ -105,3 +104,13 @@ class OpenStackScenario(scenario.Scenario): client = getattr(self._admin_clients, client_type) return client(version) if version is not None else client() + + @classmethod + def validate(cls, name, config, admin=None, users=None, deployment=None): + if admin: + admin = osclients.Clients(admin) + if users: + users = [osclients.Clients(user["credential"]) for user in users] + super(OpenStackScenario, cls).validate( + name=name, config=config, admin=admin, users=users, + deployment=deployment) diff --git a/tests/unit/doc/test_task_samples.py b/tests/unit/doc/test_task_samples.py index 5e315f61..65422ec8 100644 --- a/tests/unit/doc/test_task_samples.py +++ b/tests/unit/doc/test_task_samples.py @@ -58,7 +58,7 @@ class TaskSampleTestCase(test.TestCase): task_config = yaml.safe_load(api._Task.render_template (task_file.read())) eng = engine.TaskEngine(task_config, - mock.MagicMock()) + mock.MagicMock(), mock.Mock()) eng.validate() except Exception: print(traceback.format_exc()) diff --git a/tests/unit/plugins/openstack/test_scenario.py b/tests/unit/plugins/openstack/test_scenario.py index 68741701..aae42e82 100644 --- a/tests/unit/plugins/openstack/test_scenario.py +++ b/tests/unit/plugins/openstack/test_scenario.py @@ -127,3 +127,30 @@ class OpenStackScenarioTestCase(test.TestCase): self.assertEqual(self.context["tenants"][tenant_id], self.context["tenant"]) self.assertEqual(expected_tenant_id, tenant_id) + + @mock.patch("rally.task.scenario.Scenario.validate") + def test_validate(self, mock_scenario_validate): + cred1 = mock.Mock() + cred2 = mock.Mock() + cred3 = mock.Mock() + self.osclients.mock.side_effect = [cred1, cred2, cred3] + + base_scenario.OpenStackScenario.validate( + name="foo_name", + config="foo_config", + admin="foo_admin", + users=[{"credential": "foo_user1"}, + {"credential": "foo_user2"}], + deployment=None) + + mock_scenario_validate.assert_called_once_with( + name="foo_name", + config="foo_config", + admin=cred1, + users=[cred2, cred3], + deployment=None) + self.osclients.mock.assert_has_calls([ + mock.call("foo_admin"), + mock.call("foo_user1"), + mock.call("foo_user2"), + ]) diff --git a/tests/unit/rally_jobs/test_jobs.py b/tests/unit/rally_jobs/test_jobs.py index a7ccaab7..6a17846c 100644 --- a/tests/unit/rally_jobs/test_jobs.py +++ b/tests/unit/rally_jobs/test_jobs.py @@ -62,7 +62,8 @@ class RallyJobsTestCase(test.TestCase): task = api._Task.render_template(task_file.read(), **args) task = yaml.safe_load(task) - eng = engine.TaskEngine(task, mock.MagicMock()) + eng = engine.TaskEngine(task, mock.MagicMock(), + mock.Mock()) eng.validate() except Exception: print(traceback.format_exc())