diff --git a/rally-jobs/rally-keystone-api-v2.yaml b/rally-jobs/rally-keystone-api-v2.yaml index e59e8bf1..88b25a02 100644 --- a/rally-jobs/rally-keystone-api-v2.yaml +++ b/rally-jobs/rally-keystone-api-v2.yaml @@ -1073,3 +1073,17 @@ sla: failure_rate: max: 0 + + KeystoneBasic.create_and_list_roles: + - + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index d188ecb0..d96f41b4 100644 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -138,6 +138,20 @@ failure_rate: max: 0 + KeystoneBasic.create_and_list_roles: + - + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + KeystoneBasic.create_and_list_users: - args: {} diff --git a/rally/plugins/openstack/scenarios/keystone/basic.py b/rally/plugins/openstack/scenarios/keystone/basic.py index 7587b4cb..eaa3f419 100755 --- a/rally/plugins/openstack/scenarios/keystone/basic.py +++ b/rally/plugins/openstack/scenarios/keystone/basic.py @@ -364,3 +364,27 @@ class CreateAndGetRole(KeystoneBasic): """ role = self.admin_keystone.create_role(**kwargs) self.admin_keystone.get_role(role.id) + + +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["keystone"]}, + name="KeystoneBasic.create_and_list_roles") +class CreateAddListRoles(KeystoneBasic): + + def run(self, create_role_kwargs=None, list_role_kwargs=None): + """Create a role, then list all roles. + + :param create_role_kwargs: Optional additional arguments for + roles create + :param list_role_kwargs: Optional additional arguments for roles list + """ + create_role_kwargs = create_role_kwargs or {} + list_role_kwargs = list_role_kwargs or {} + + role = self.admin_keystone.create_role(**create_role_kwargs) + msg = "Role isn't created" + self.assertTrue(role, err_msg=msg) + all_roles = self.admin_keystone.list_roles(**list_role_kwargs) + msg = ("Created role is not in the" + " list of all available roles") + self.assertIn(role, all_roles, err_msg=msg) diff --git a/rally/plugins/openstack/services/identity/identity.py b/rally/plugins/openstack/services/identity/identity.py index b6820624..7b31f73e 100644 --- a/rally/plugins/openstack/services/identity/identity.py +++ b/rally/plugins/openstack/services/identity/identity.py @@ -153,7 +153,7 @@ class Identity(service.UnifiedOpenStackService): return self._impl.get_service(service_id) @service.should_be_overridden - def create_role(self, name=None, domain_name="Default"): + def create_role(self, name=None, domain_name=None): """Create role with specific name :param name: role name diff --git a/rally/plugins/openstack/services/identity/keystone_v2.py b/rally/plugins/openstack/services/identity/keystone_v2.py index 0c653015..6212560e 100644 --- a/rally/plugins/openstack/services/identity/keystone_v2.py +++ b/rally/plugins/openstack/services/identity/keystone_v2.py @@ -274,9 +274,12 @@ class UnifiedKeystoneV2Service(keystone_common.UnifiedKeystoneMixin, """List all services.""" return [self._unify_service(s) for s in self._impl.list_services()] - def create_role(self, name=None, domain_name="Default"): + def create_role(self, name=None, domain_name=None): """Add role to user.""" - self._check_domain(domain_name) + if domain_name is not None: + raise NotImplementedError("Domain functionality not implemented " + "in Keystone v2") + return self._unify_role(self._impl.create_role(name)) def add_role(self, role_id, user_id, project_id): diff --git a/rally/plugins/openstack/services/identity/keystone_v3.py b/rally/plugins/openstack/services/identity/keystone_v3.py index 07382338..05edbbec 100644 --- a/rally/plugins/openstack/services/identity/keystone_v3.py +++ b/rally/plugins/openstack/services/identity/keystone_v3.py @@ -160,8 +160,10 @@ class KeystoneV3Service(service.Service, keystone_common.KeystoneMixin): name, type=service_type, description=description, enabled=enabled) @atomic.action_timer("keystone_v3.create_role") - def create_role(self, name=None, domain_name="Default"): - domain_id = self._get_domain_id(domain_name) + def create_role(self, name=None, domain_name=None): + domain_id = None + if domain_name: + domain_id = self._get_domain_id(domain_name) name = name or self.generate_random_name() return self._clients.keystone("3").roles.create(name, domain=domain_id) @@ -298,7 +300,7 @@ class UnifiedKeystoneV3Service(keystone_common.UnifiedKeystoneMixin, """List all services.""" return [self._unify_service(s) for s in self._impl.list_services()] - def create_role(self, name=None, domain_name="Default"): + def create_role(self, name=None, domain_name=None): """Add role to user.""" return self._unify_role(self._impl.create_role( name, domain_name=domain_name)) diff --git a/samples/tasks/scenarios/keystone/create-and-list-roles.json b/samples/tasks/scenarios/keystone/create-and-list-roles.json new file mode 100644 index 00000000..6633a3ac --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-list-roles.json @@ -0,0 +1,26 @@ +{ + "KeystoneBasic.create_and_list_roles": [ + { + "args": { + "create_role_kwargs": {}, + "list_role_kwargs": {} + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/keystone/create-and-list-roles.yaml b/samples/tasks/scenarios/keystone/create-and-list-roles.yaml new file mode 100644 index 00000000..09dce1f8 --- /dev/null +++ b/samples/tasks/scenarios/keystone/create-and-list-roles.yaml @@ -0,0 +1,17 @@ +--- + KeystoneBasic.create_and_list_roles: + - + args: + create_role_kwargs: {} + list_role_kwargs: {} + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py index bfcc369e..b1f6d764 100755 --- a/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py +++ b/tests/unit/plugins/openstack/scenarios/keystone/test_basic.py @@ -16,6 +16,7 @@ import ddt import mock +from rally import exceptions from rally.plugins.openstack.scenarios.keystone import basic from tests.unit import test @@ -187,6 +188,40 @@ class KeystoneBasicTestCase(test.ScenarioTestCase): self.mock_identity.return_value.list_roles.assert_called_once_with( user_id=fake_user, project_id=fake_tenant) + def test_create_and_list_roles(self): + # Positive case + scenario = basic.CreateAddListRoles(self.context) + create_kwargs = {"fakewargs": "name"} + list_kwargs = {"fakewargs": "f"} + self.mock_identity.return_value.create_role = mock.Mock( + return_value="role1") + self.mock_identity.return_value.list_roles = mock.Mock( + return_value=("role1", "role2")) + scenario.run(create_role_kwargs=create_kwargs, + list_role_kwargs=list_kwargs) + self.mock_identity.return_value.create_role.assert_called_once_with( + **create_kwargs) + self.mock_identity.return_value.list_roles.assert_called_once_with( + **list_kwargs) + + # Negative case 1: role isn't created + self.mock_identity.return_value.create_role.return_value = None + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, create_role_kwargs=create_kwargs, + list_role_kwargs=list_kwargs) + self.mock_identity.return_value.create_role.assert_called_with( + **create_kwargs) + + # Negative case 2: role was created but included into list + self.mock_identity.return_value.create_role.return_value = "role3" + self.assertRaises(exceptions.RallyAssertionError, + scenario.run, create_role_kwargs=create_kwargs, + list_role_kwargs=list_kwargs) + self.mock_identity.return_value.create_role.assert_called_with( + **create_kwargs) + self.mock_identity.return_value.list_roles.assert_called_with( + **list_kwargs) + @ddt.data(None, "keystone", "fooservice") def test_get_entities(self, service_name): identity_service = self.mock_identity.return_value diff --git a/tests/unit/plugins/openstack/services/identity/test_identity.py b/tests/unit/plugins/openstack/services/identity/test_identity.py index a6cf088d..86fac128 100644 --- a/tests/unit/plugins/openstack/services/identity/test_identity.py +++ b/tests/unit/plugins/openstack/services/identity/test_identity.py @@ -169,7 +169,7 @@ class IdentityTestCase(test.TestCase): name = "name" service.create_role(name) service._impl.create_role.assert_called_once_with( - name=name, domain_name="Default") + name=name, domain_name=None) def test_add_role(self): service = self.get_service_with_fake_impl()