From 7e3d74c6b0cba6f66cb96f5ea25cf96c49d304a7 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Fri, 11 Oct 2019 15:45:28 +0200 Subject: [PATCH] Parse the leader_get output Because laeder_get only deals with stringy types, it is unsound to evaluate them as booleans to toggle something on or off. Change-Id: I18c3763dce53d1d652185f9fba73523a5c5a65a6 Closes-Bug: #1847769 --- hooks/ceph_radosgw_context.py | 2 +- hooks/hooks.py | 4 ++-- unit_tests/test_ceph_radosgw_context.py | 4 ++-- unit_tests/test_hooks.py | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hooks/ceph_radosgw_context.py b/hooks/ceph_radosgw_context.py index 9cf29a1c..958d7eeb 100644 --- a/hooks/ceph_radosgw_context.py +++ b/hooks/ceph_radosgw_context.py @@ -105,7 +105,7 @@ class IdentityServiceContext(context.IdentityServiceContext): if config('admin-roles'): ctxt['user_roles'] += (',' + config('admin-roles')) ctxt['cache_size'] = config('cache-size') - ctxt['namespace_tenants'] = leader_get('namespace_tenants') + ctxt['namespace_tenants'] = leader_get('namespace_tenants') == 'True' if self.context_complete(ctxt): return ctxt return {} diff --git a/hooks/hooks.py b/hooks/hooks.py index 8a8a2760..3d81941c 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -176,7 +176,7 @@ def install(): @hooks.hook('upgrade-charm.real') def upgrade_charm(): - if is_leader() and not leader_get('namespace_tenants'): + if is_leader() and not leader_get('namespace_tenants') == 'True': leader_set(namespace_tenants=False) @@ -302,7 +302,7 @@ def identity_joined(relid=None): port = config('port') admin_url = '%s:%i/swift' % (canonical_url(CONFIGS, ADMIN), port) - if leader_get('namespace_tenants'): + if leader_get('namespace_tenants') == 'True': internal_url = '%s:%s/swift/v1/AUTH_$(project_id)s' % \ (canonical_url(CONFIGS, INTERNAL), port) public_url = '%s:%s/swift/v1/AUTH_$(project_id)s' % \ diff --git a/unit_tests/test_ceph_radosgw_context.py b/unit_tests/test_ceph_radosgw_context.py index d0f1c24c..8c0d79a3 100644 --- a/unit_tests/test_ceph_radosgw_context.py +++ b/unit_tests/test_ceph_radosgw_context.py @@ -75,7 +75,7 @@ class IdentityServiceContextTest(CharmTestCase): self.config.side_effect = self.test_config.get self.maxDiff = None self.cmp_pkgrevno.return_value = 1 - self.leader_get.return_value = False + self.leader_get.return_value = 'False' @patch.object(charmhelpers.contrib.openstack.context, 'filter_installed_packages', return_value=['absent-pkg']) @@ -167,7 +167,7 @@ class IdentityServiceContextTest(CharmTestCase): _rids.return_value = 'rid1' _runits.return_value = 'runit' _ctxt_comp.return_value = True - self.leader_get.return_value = True + self.leader_get.return_value = 'True' id_data = { 'service_port': 9876, 'service_host': '127.0.0.4', diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 66576aaf..eda79f64 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -254,7 +254,7 @@ class CephRadosGWTests(CharmTestCase): @patch('charmhelpers.contrib.openstack.ip.config') def test_identity_joined_early_version(self, _config, _leader_get): self.cmp_pkgrevno.return_value = -1 - _leader_get.return_value = False + _leader_get.return_value = 'False' ceph_hooks.identity_joined() self.sys.exit.assert_called_with(1) @@ -271,7 +271,7 @@ class CephRadosGWTests(CharmTestCase): _resolve_address.return_value = 'myserv' _config.side_effect = self.test_config.get self.test_config.set('region', 'region1') - _leader_get.return_value = False + _leader_get.return_value = 'False' ceph_hooks.identity_joined(relid='rid') self.relation_set.assert_called_with( service='swift', @@ -306,7 +306,7 @@ class CephRadosGWTests(CharmTestCase): _resolve_address.return_value = 'myserv' _config.side_effect = self.test_config.get self.test_config.set('region', 'region1') - _leader_get.return_value = True + _leader_get.return_value = 'True' ceph_hooks.identity_joined(relid='rid') self.relation_set.assert_called_with( service='swift', @@ -339,7 +339,7 @@ class CephRadosGWTests(CharmTestCase): self.test_config.set('os-public-hostname', 'files.example.com') _unit_get.return_value = 'myserv' _is_clustered.return_value = False - _leader_get.return_value = False + _leader_get.return_value = 'False' ceph_hooks.identity_joined(relid='rid') self.relation_set.assert_called_with( service='swift',