Support roles 'name' in list_roles call

Change-Id: Ia615288da30426c2f689daa3e5f88376aead1d3f
This commit is contained in:
Sagi Shnaidman 2021-01-05 16:17:49 +02:00
parent eefd1609ac
commit 658b5805be
2 changed files with 17 additions and 1 deletions

View File

@ -1061,7 +1061,7 @@ class IdentityCloudMixin(_normalize.Normalizer):
self.list_groups.invalidate(self) self.list_groups.invalidate(self)
return True return True
@_utils.valid_kwargs('domain_id') @_utils.valid_kwargs('domain_id', 'name')
def list_roles(self, **kwargs): def list_roles(self, **kwargs):
"""List Keystone roles. """List Keystone roles.

View File

@ -54,6 +54,22 @@ class TestIdentityRoles(base.TestCase):
self.cloud.list_roles() self.cloud.list_roles()
self.assert_calls() self.assert_calls()
def test_list_role_by_name(self):
role_data = self._get_role_data()
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
qs_elements=['name={0}'.format(role_data.role_name)]),
status_code=200,
json={'roles': [role_data.json_response['role']]})
])
role = self.cloud.list_roles(name=role_data.role_name)[0]
self.assertIsNotNone(role)
self.assertThat(role.id, matchers.Equals(role_data.role_id))
self.assertThat(role.name, matchers.Equals(role_data.role_name))
self.assert_calls()
def test_get_role_by_name(self): def test_get_role_by_name(self):
role_data = self._get_role_data() role_data = self._get_role_data()
self.register_uris([ self.register_uris([