Make trustee role configurable

Allow the charm to configure the trustee role and request the role be
created by Keystone.

Closes-Bug: #1928137
Change-Id: Iddb50bcfb1d109fb4709b8e962d821a2fe4c608c
This commit is contained in:
David Ames 2021-05-11 13:30:47 -07:00
parent e0b6693254
commit b8946a42e1
4 changed files with 47 additions and 9 deletions

View File

@ -62,3 +62,8 @@ options:
type: string
default:
description: S3 endpoint URL
trustee-role:
type: string
default: member
description: |
Workload manager trustee role.

View File

@ -22,7 +22,6 @@ charm.use_defaults(
"charm.installed",
"amqp.connected",
"shared-db.connected",
"identity-service.connected",
"identity-service.available", # enables SSL support
"config.changed",
"update-status",
@ -60,10 +59,22 @@ def cluster_connected(hacluster):
@reactive.when("identity-service.connected")
def request_endpoint_notification(identity_service):
"""Request notification about endpoint changes"""
with charm.provide_charm_instance() as charm_class:
identity_service.request_notification(charm_class.required_services)
def register_endpoints_and_request_notification(identity_service):
"""Register endpoints and request notification.
Note: In order to pass the requested role(s), we must override the default
openstack-api layer setup_endpoint_connection version of this handler.
"""
with charm.provide_charm_instance() as instance:
identity_service.request_notification(instance.required_services)
identity_service.register_endpoints(
instance.service_type,
instance.region,
instance.public_url,
instance.internal_url,
instance.admin_url,
requested_roles=[instance.options.trustee_role])
instance.assess_status()
@reactive.when_any("config.changed.triliovault-pkg-source",

View File

@ -37,7 +37,7 @@ cinder_production_endpoint_template = {{ identity_service.cinder_url }}
nova_production_endpoint_template = {{ identity_service.nova_url }}
neutron_production_url = {{ identity_service.neutron_url }}
trustee_role = Member
trustee_role = {{ options.trustee_role }}
global_job_scheduler_override = False

View File

@ -106,7 +106,8 @@ class TestDmapiHandlers(test_utils.PatchHelper):
),
"init_db": ("config.rendered",),
"cluster_connected": ("ha.connected",),
"request_endpoint_notification": ("identity-service.connected",),
"register_endpoints_and_request_notification": (
"identity-service.connected",),
}
when_not_patterns = {}
# check the when hooks are attached to the expected functions
@ -140,8 +141,20 @@ class TestDmapiHandlers(test_utils.PatchHelper):
wlm_charm.render_with_interfaces.assert_called_once_with((args,))
wlm_charm.assess_status.assert_called_once_with()
def test_register_endpoint_notification(self):
def test_register_endpoints_and_request_notification(self):
wlm_charm = mock.MagicMock()
_service_type = "workloadmgr"
_region = "RegionOne"
_public_url = "http://trilio-wlm-public"
_internal_url = "http://trilio-wlm-internal"
_admin_url = "http://trilio-wlm-admin"
_trustee_role = "_trustee_role_"
wlm_charm.service_type = _service_type
wlm_charm.region = _region
wlm_charm.public_url = _public_url
wlm_charm.internal_url = _internal_url
wlm_charm.admin_url = _admin_url
wlm_charm.options.trustee_role = _trustee_role
self.patch_object(
handlers.charm, "provide_charm_instance", new=mock.MagicMock()
)
@ -149,7 +162,16 @@ class TestDmapiHandlers(test_utils.PatchHelper):
self.provide_charm_instance().__exit__.return_value = None
wlm_charm.required_services = ["foo", "bar"]
identity_service = mock.MagicMock()
handlers.request_endpoint_notification(identity_service)
handlers.register_endpoints_and_request_notification(
identity_service)
identity_service.request_notification.assert_called_once_with(
["foo", "bar"]
)
identity_service.register_endpoints.assert_called_once_with(
_service_type,
_region,
_public_url,
_internal_url,
_admin_url,
requested_roles=[_trustee_role]
)