diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index 881a55dd..8ac8e296 100644 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -200,6 +200,34 @@ failure_rate: max: 0 + KeystoneBasic.create_and_list_ec2credentials: + - + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + + KeystoneBasic.create_and_delete_ec2credential: + - + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + CeilometerAlarms.create_alarm: - args: diff --git a/rally/plugins/openstack/scenarios/keystone/basic.py b/rally/plugins/openstack/scenarios/keystone/basic.py index 2b276fad..e7e7d419 100644 --- a/rally/plugins/openstack/scenarios/keystone/basic.py +++ b/rally/plugins/openstack/scenarios/keystone/basic.py @@ -206,3 +206,19 @@ class KeystoneBasic(kutils.KeystoneScenario): """ self._service_create(name, service_type, description) self._list_services() + + @validation.required_openstack(users=True) + @base.scenario(context={"admin_cleanup": ["keystone"]}) + def create_and_list_ec2credentials(self): + """Create and List all keystone ec2-credentials.""" + self._create_ec2credentials(self.context["user"]["id"], + self.context["tenant"]["id"]) + self._list_ec2credentials(self.context["user"]["id"]) + + @validation.required_openstack(users=True) + @base.scenario(context={"admin_cleanup": ["keystone"]}) + def create_and_delete_ec2credential(self): + """Create and delete keystone ec2-credential.""" + creds = self._create_ec2credentials(self.context["user"]["id"], + self.context["tenant"]["id"]) + self._delete_ec2credential(self.context["user"]["id"], creds.access) diff --git a/rally/plugins/openstack/scenarios/keystone/utils.py b/rally/plugins/openstack/scenarios/keystone/utils.py index ab650687..2f01799c 100644 --- a/rally/plugins/openstack/scenarios/keystone/utils.py +++ b/rally/plugins/openstack/scenarios/keystone/utils.py @@ -218,3 +218,33 @@ class KeystoneScenario(base.Scenario): """ self.admin_clients("keystone").users.update_password(user_id, password) + + @base.atomic_action_timer("keystone.create_ec2creds") + def _create_ec2credentials(self, user_id, tenant_id): + """Create ec2credentials. + + :param user_id: User ID for which to create credentials + :param tenant_id: Tenant ID for which to create credentials + + :returns: Created ec2-credentials object + """ + return self.clients("keystone").ec2.create(user_id, tenant_id) + + @base.atomic_action_timer("keystone.list_ec2creds") + def _list_ec2credentials(self, user_id): + """List of access/secret pairs for a user_id. + + :param user_id: List all ec2-credentials for User ID + + :returns: Return ec2-credentials list + """ + return self.clients("keystone").ec2.list(user_id) + + @base.atomic_action_timer("keystone.delete_ec2creds") + def _delete_ec2credential(self, user_id, access): + """Delete ec2credential. + + :param user_id: User ID for which to delete credential + :param access: access key for ec2credential to delete + """ + self.clients("keystone").ec2.delete(user_id, access) diff --git a/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.json b/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.json new file mode 100644 index 00000000..1c4ba742 --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.json @@ -0,0 +1,17 @@ +{ + "KeystoneBasic.create_and_delete_ec2credential": [ + { + "runner": { + "type": "constant", + "times": 10, + "concurrency": 5 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.yaml b/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.yaml new file mode 100644 index 00000000..2bf29658 --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-delete-ec2credential.yaml @@ -0,0 +1,12 @@ +--- + KeystoneBasic.create_and_delete_ec2credential: + + - + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + users: + tenants: 2 + users_per_tenant: 2 diff --git a/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.json b/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.json new file mode 100644 index 00000000..930466ea --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.json @@ -0,0 +1,17 @@ +{ + "KeystoneBasic.create_and_list_ec2credentials": [ + { + "runner": { + "type": "constant", + "times": 10, + "concurrency": 5 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.yaml b/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.yaml new file mode 100644 index 00000000..f61e20f4 --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-list-ec2credentials.yaml @@ -0,0 +1,12 @@ +--- + KeystoneBasic.create_and_list_ec2credentials: + + - + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + users: + tenants: 2 + users_per_tenant: 2 diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py index ab17127b..5d65273f 100644 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py @@ -27,8 +27,8 @@ class KeystoneBasicTestCase(test.TestCase): @staticmethod def _get_context(): return { - "user": {"id": "fake"}, - "tenant": {"id": "fake"} + "user": {"id": "fake_user_id"}, + "tenant": {"id": "fake_tenant_id"} } @mock.patch("rally.common.utils.generate_random_name") @@ -248,3 +248,26 @@ class KeystoneBasicTestCase(test.TestCase): service_type, description) scenario._list_services.assert_called_once_with() + + def test_create_and_list_ec2credentials(self): + context = self._get_context() + scenario = basic.KeystoneBasic(context) + scenario._create_ec2credentials = mock.MagicMock() + scenario._list_ec2credentials = mock.MagicMock() + scenario.create_and_list_ec2credentials() + scenario._create_ec2credentials.assert_called_once_with( + "fake_user_id", "fake_tenant_id") + scenario._list_ec2credentials.assert_called_with("fake_user_id") + + def test_create_and_delete_ec2credential(self): + fake_creds = mock.MagicMock() + context = self._get_context() + scenario = basic.KeystoneBasic(context) + scenario._create_ec2credentials = mock.MagicMock( + return_value=fake_creds) + scenario._delete_ec2credential = mock.MagicMock() + scenario.create_and_delete_ec2credential() + scenario._create_ec2credentials.assert_called_once_with( + "fake_user_id", "fake_tenant_id") + scenario._delete_ec2credential.assert_called_once_with( + "fake_user_id", fake_creds.access) diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py b/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py index 3f80e9f2..92e74c98 100644 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_utils.py @@ -278,3 +278,37 @@ class KeystoneScenarioTestCase(test.ClientsTestCase): scenario._list_services = mock.Mock(return_value=[svc_foo, svc_bar]) self.assertEqual(scenario._get_service_by_name(svc_bar.name), svc_bar) self.assertIsNone(scenario._get_service_by_name("spam")) + + @mock.patch(UTILS + "KeystoneScenario.clients") + def test_create_ec2credentials(self, mock_clients): + scenario = utils.KeystoneScenario() + creds = mock.Mock() + mock_clients("keystone").ec2.create.return_value = creds + create_creds = scenario._create_ec2credentials("user_id", + "tenant_id") + self.assertEqual(create_creds, creds) + mock_clients("keystone").ec2.create.assert_called_once_with( + "user_id", "tenant_id") + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.create_ec2creds") + + @mock.patch(UTILS + "KeystoneScenario.clients") + def test_list_ec2credentials(self, mock_clients): + scenario = utils.KeystoneScenario() + creds_list = mock.Mock() + mock_clients("keystone").ec2.list.return_value = creds_list + list_creds = scenario._list_ec2credentials("user_id") + self.assertEqual(list_creds, creds_list) + mock_clients("keystone").ec2.list.assert_called_once_with("user_id") + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.list_ec2creds") + + @mock.patch(UTILS + "KeystoneScenario.clients") + def test_delete_ec2credentials(self, mock_clients): + scenario = utils.KeystoneScenario() + mock_clients("keystone").ec2.delete = mock.MagicMock() + scenario._delete_ec2credential("user_id", "access") + mock_clients("keystone").ec2.delete.assert_called_once_with("user_id", + "access") + self._test_atomic_action_timer(scenario.atomic_actions(), + "keystone.delete_ec2creds")