From 8a4940bbb108124246ad3ae830964cf58dfc9ec3 Mon Sep 17 00:00:00 2001 From: Tiago Pasqualini Date: Sat, 29 Oct 2022 21:53:15 -0300 Subject: [PATCH] Add check to expose internal endpoints Currently, the charm ignores the use-internal-endpoints config option that is being inherited from the Openstack Layer. This patch adds a check to ensure that the internal endpoint is exposed if this is set to True. Closes-bug: #1995188 Change-Id: I48a04ac619204ba109d87ca05de7cbe308592486 --- src/reactive/designate_handlers.py | 5 ++++- unit_tests/test_designate_handlers.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/reactive/designate_handlers.py b/src/reactive/designate_handlers.py index efb5ef2..15e5006 100644 --- a/src/reactive/designate_handlers.py +++ b/src/reactive/designate_handlers.py @@ -242,7 +242,10 @@ def cluster_connected(hacluster): @reactive.when('dnsaas.connected') def expose_endpoint(endpoint): with charm.provide_charm_instance() as instance: - endpoint.expose_endpoint(instance.public_url) + if hookenv.config('use-internal-endpoints'): + endpoint.expose_endpoint(instance.internal_url) + else: + endpoint.expose_endpoint(instance.public_url) @reactive.when_not('dont-set-assess-status') diff --git a/unit_tests/test_designate_handlers.py b/unit_tests/test_designate_handlers.py index 282a2d9..ba66f04 100644 --- a/unit_tests/test_designate_handlers.py +++ b/unit_tests/test_designate_handlers.py @@ -147,8 +147,14 @@ class TestHandlers(test_utils.PatchHelper): self.is_data_changed().__exit__.return_value = None keystone = mock.MagicMock() handlers.maybe_setup_endpoint(keystone) - self.is_data_changed.called_once_with(mock.ANY, args) keystone.register_endpoints.assert_called_once_with(*args) + endpoint = mock.MagicMock() + handlers.expose_endpoint(endpoint) + endpoint.expose_endpoint.assert_called_once_with('i1') + endpoint = mock.MagicMock() + self.patch_object(handlers.hookenv, 'config', return_value=False) + handlers.expose_endpoint(endpoint) + endpoint.expose_endpoint.assert_called_once_with('p1') def test_configure_designate_basic(self): the_charm = self._patch_provide_charm_instance()