From 89ee87de891c20ef3077c6160eb7162a63bcca71 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 8 Apr 2015 11:10:25 -0500 Subject: [PATCH] Keystone: Add scenarios to benchmark user disable/enable Adds a new scenario to create a user and toggle the enabled flag. Change-Id: I0b8d8e57c95cced72b6615f8120ec41879c414be --- rally-jobs/rally.yaml | 22 +++++++++++++++++ .../openstack/scenarios/keystone/basic.py | 14 +++++++++++ .../openstack/scenarios/keystone/utils.py | 10 ++++++++ .../create-user-set-enabled-and-delete.json | 24 +++++++++++++++++++ .../create-user-set-enabled-and-delete.yaml | 16 +++++++++++++ .../scenarios/keystone/test_basic.py | 15 ++++++++++++ .../scenarios/keystone/test_utils.py | 13 ++++++++++ 7 files changed, 114 insertions(+) create mode 100644 samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.json create mode 100644 samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.yaml diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index 881a55dd..28dd75b1 100644 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -23,6 +23,28 @@ failure_rate: max: 0 + KeystoneBasic.create_user_set_enabled_and_delete: + - + args: + enabled: true + runner: + type: "constant" + times: 10 + concurrency: 10 + sla: + failure_rate: + max: 0 + - + args: + enabled: false + runner: + type: "constant" + times: 10 + concurrency: 10 + sla: + failure_rate: + max: 0 + KeystoneBasic.create_and_list_tenants: - args: diff --git a/rally/plugins/openstack/scenarios/keystone/basic.py b/rally/plugins/openstack/scenarios/keystone/basic.py index 3256e8a8..67a7b989 100644 --- a/rally/plugins/openstack/scenarios/keystone/basic.py +++ b/rally/plugins/openstack/scenarios/keystone/basic.py @@ -46,6 +46,20 @@ class KeystoneBasic(kutils.KeystoneScenario): user = self._user_create(name_length=name_length, **kwargs) self._resource_delete(user) + @validation.required_openstack(admin=True) + @base.scenario(context={"admin_cleanup": ["keystone"]}) + def create_user_set_enabled_and_delete(self, enabled=True, **kwargs): + """Create a keystone user, enable or disable it, and delete it. + + :param enabled: Initial state of user 'enabled' flag. The user + will be created with 'enabled' set to this + value, and then it will be toggled. + :param kwargs: Other optional parameters to create user. + """ + user = self._user_create(enabled=enabled, **kwargs) + self._update_user_enabled(user, not enabled) + self._resource_delete(user) + @validation.number("name_length", minval=10) @validation.required_openstack(admin=True) @base.scenario(context={"admin_cleanup": ["keystone"]}) diff --git a/rally/plugins/openstack/scenarios/keystone/utils.py b/rally/plugins/openstack/scenarios/keystone/utils.py index 2953c519..6263a101 100644 --- a/rally/plugins/openstack/scenarios/keystone/utils.py +++ b/rally/plugins/openstack/scenarios/keystone/utils.py @@ -45,6 +45,16 @@ class KeystoneScenario(base.Scenario): return self.admin_clients("keystone").users.create( name, password=password, email=email, **kwargs) + @base.atomic_action_timer("keystone.update_user_enabled") + def _update_user_enabled(self, user, enabled): + """Enable or disable a user. + + :param user: The user to enable or disable + :param enabled: Boolean indicating if the user should be + enabled (True) or disabled (False) + """ + self.admin_clients("keystone").users.update_enabled(user, enabled) + def _resource_delete(self, resource): """"Delete keystone resource.""" r = "keystone.delete_%s" % resource.__class__.__name__.lower() diff --git a/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.json b/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.json new file mode 100644 index 00000000..cda0bd7c --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.json @@ -0,0 +1,24 @@ +{ + "KeystoneBasic.create_user_set_enabled_and_delete": [ + { + "args": { + "enabled": true + }, + "runner": { + "type": "constant", + "concurrency": 10, + "times": 100 + } + }, + { + "args": { + "enabled": false + }, + "runner": { + "type": "constant", + "concurrency": 10, + "times": 100 + } + } + ] +} diff --git a/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.yaml b/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.yaml new file mode 100644 index 00000000..127957ec --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-user-set-enabled-and-delete.yaml @@ -0,0 +1,16 @@ +--- + KeystoneBasic.create_user_set_enabled_and_delete: + - + args: + enabled: true + runner: + type: "constant" + times: 100 + concurrency: 10 + - + args: + enabled: false + runner: + type: "constant" + times: 100 + concurrency: 10 diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py index ab17127b..e59096ce 100644 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py @@ -55,6 +55,21 @@ class KeystoneBasicTestCase(test.TestCase): enabled=True) scenario._resource_delete.assert_called_once_with(create_result) + def test_create_user_set_enabled_and_delete(self): + scenario = basic.KeystoneBasic() + scenario._user_create = mock.Mock() + scenario._update_user_enabled = mock.Mock() + scenario._resource_delete = mock.Mock() + + scenario.create_user_set_enabled_and_delete(enabled=True, + email="abcd") + scenario._user_create.assert_called_once_with(email="abcd", + enabled=True) + scenario._update_user_enabled.assert_called_once_with( + scenario._user_create.return_value, False) + scenario._resource_delete.assert_called_once_with( + scenario._user_create.return_value) + @mock.patch("rally.common.utils.generate_random_name") def test_create_tenant(self, mock_generate_random_name): scenario = basic.KeystoneBasic() diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py b/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py index 3f80e9f2..ad28bb4d 100644 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py @@ -64,6 +64,19 @@ class KeystoneScenarioTestCase(test.ClientsTestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_user") + def test_update_user_enabled(self): + user = mock.Mock() + enabled = mock.Mock() + scenario = utils.KeystoneScenario() + + scenario._update_user_enabled(user, enabled) + self.admin_clients( + "keystone").users.update_enabled.assert_called_once_with(user, + enabled) + + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.update_user_enabled") + @mock.patch("rally.common.utils.generate_random_name") def test_role_create(self, mock_generate_random_name): scenario = utils.KeystoneScenario()