Add keystone.CreateAndListAllRoles
Create a role,then list all roles Change-Id: I3527e7caf8e572da99d212206649bc341fb0a74a
This commit is contained in:
parent
3adeded2ca
commit
b64cd19dcd
@ -1073,3 +1073,17 @@
|
|||||||
sla:
|
sla:
|
||||||
failure_rate:
|
failure_rate:
|
||||||
max: 0
|
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
|
||||||
|
@ -138,6 +138,20 @@
|
|||||||
failure_rate:
|
failure_rate:
|
||||||
max: 0
|
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:
|
KeystoneBasic.create_and_list_users:
|
||||||
-
|
-
|
||||||
args: {}
|
args: {}
|
||||||
|
@ -364,3 +364,27 @@ class CreateAndGetRole(KeystoneBasic):
|
|||||||
"""
|
"""
|
||||||
role = self.admin_keystone.create_role(**kwargs)
|
role = self.admin_keystone.create_role(**kwargs)
|
||||||
self.admin_keystone.get_role(role.id)
|
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)
|
||||||
|
@ -153,7 +153,7 @@ class Identity(service.UnifiedOpenStackService):
|
|||||||
return self._impl.get_service(service_id)
|
return self._impl.get_service(service_id)
|
||||||
|
|
||||||
@service.should_be_overridden
|
@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
|
"""Create role with specific name
|
||||||
|
|
||||||
:param name: role name
|
:param name: role name
|
||||||
|
@ -274,9 +274,12 @@ class UnifiedKeystoneV2Service(keystone_common.UnifiedKeystoneMixin,
|
|||||||
"""List all services."""
|
"""List all services."""
|
||||||
return [self._unify_service(s) for s in self._impl.list_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."""
|
"""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))
|
return self._unify_role(self._impl.create_role(name))
|
||||||
|
|
||||||
def add_role(self, role_id, user_id, project_id):
|
def add_role(self, role_id, user_id, project_id):
|
||||||
|
@ -160,8 +160,10 @@ class KeystoneV3Service(service.Service, keystone_common.KeystoneMixin):
|
|||||||
name, type=service_type, description=description, enabled=enabled)
|
name, type=service_type, description=description, enabled=enabled)
|
||||||
|
|
||||||
@atomic.action_timer("keystone_v3.create_role")
|
@atomic.action_timer("keystone_v3.create_role")
|
||||||
def create_role(self, name=None, domain_name="Default"):
|
def create_role(self, name=None, domain_name=None):
|
||||||
domain_id = self._get_domain_id(domain_name)
|
domain_id = None
|
||||||
|
if domain_name:
|
||||||
|
domain_id = self._get_domain_id(domain_name)
|
||||||
name = name or self.generate_random_name()
|
name = name or self.generate_random_name()
|
||||||
return self._clients.keystone("3").roles.create(name, domain=domain_id)
|
return self._clients.keystone("3").roles.create(name, domain=domain_id)
|
||||||
|
|
||||||
@ -298,7 +300,7 @@ class UnifiedKeystoneV3Service(keystone_common.UnifiedKeystoneMixin,
|
|||||||
"""List all services."""
|
"""List all services."""
|
||||||
return [self._unify_service(s) for s in self._impl.list_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."""
|
"""Add role to user."""
|
||||||
return self._unify_role(self._impl.create_role(
|
return self._unify_role(self._impl.create_role(
|
||||||
name, domain_name=domain_name))
|
name, domain_name=domain_name))
|
||||||
|
26
samples/tasks/scenarios/keystone/create-and-list-roles.json
Normal file
26
samples/tasks/scenarios/keystone/create-and-list-roles.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
17
samples/tasks/scenarios/keystone/create-and-list-roles.yaml
Normal file
17
samples/tasks/scenarios/keystone/create-and-list-roles.yaml
Normal file
@ -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
|
@ -16,6 +16,7 @@
|
|||||||
import ddt
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from rally import exceptions
|
||||||
from rally.plugins.openstack.scenarios.keystone import basic
|
from rally.plugins.openstack.scenarios.keystone import basic
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
@ -187,6 +188,40 @@ class KeystoneBasicTestCase(test.ScenarioTestCase):
|
|||||||
self.mock_identity.return_value.list_roles.assert_called_once_with(
|
self.mock_identity.return_value.list_roles.assert_called_once_with(
|
||||||
user_id=fake_user, project_id=fake_tenant)
|
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")
|
@ddt.data(None, "keystone", "fooservice")
|
||||||
def test_get_entities(self, service_name):
|
def test_get_entities(self, service_name):
|
||||||
identity_service = self.mock_identity.return_value
|
identity_service = self.mock_identity.return_value
|
||||||
|
@ -169,7 +169,7 @@ class IdentityTestCase(test.TestCase):
|
|||||||
name = "name"
|
name = "name"
|
||||||
service.create_role(name)
|
service.create_role(name)
|
||||||
service._impl.create_role.assert_called_once_with(
|
service._impl.create_role.assert_called_once_with(
|
||||||
name=name, domain_name="Default")
|
name=name, domain_name=None)
|
||||||
|
|
||||||
def test_add_role(self):
|
def test_add_role(self):
|
||||||
service = self.get_service_with_fake_impl()
|
service = self.get_service_with_fake_impl()
|
||||||
|
Loading…
Reference in New Issue
Block a user