diff --git a/requires.py b/requires.py index b687ec8..876e075 100644 --- a/requires.py +++ b/requires.py @@ -119,7 +119,7 @@ class KeystoneRequires(RelationBase): return True def register_endpoints(self, service, region, public_url, internal_url, - admin_url): + admin_url, requested_roles=None): """ Register this service with keystone """ @@ -130,6 +130,9 @@ class KeystoneRequires(RelationBase): 'admin_url': admin_url, 'region': region, } + if requested_roles: + relation_info.update( + {'requested_roles': ','.join(requested_roles)}) self.set_local(**relation_info) self.set_remote(**relation_info) diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index 7fb63d5..76d14f7 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -224,6 +224,22 @@ class TestKeystoneRequires(unittest.TestCase): self.set_local.assert_called_once_with(**result) self.set_remote.assert_called_once_with(**result) + def test_register_endpoints_requested_roles(self): + self.patch_kr('set_local') + self.patch_kr('set_remote') + self.kr.register_endpoints('s', 'r', 'p_url', 'i_url', 'a_url', + requested_roles=['role1', 'role2']) + result = { + 'service': 's', + 'public_url': 'p_url', + 'internal_url': 'i_url', + 'admin_url': 'a_url', + 'region': 'r', + 'requested_roles': 'role1,role2', + } + self.set_local.assert_called_once_with(**result) + self.set_remote.assert_called_once_with(**result) + def test_request_keystone_endpoint_information(self): self.patch_kr('set_local') self.patch_kr('set_remote')