From ae5d356e7ab563f761a38704742f3b9a57d5435e Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 12 Oct 2015 10:56:01 +0000 Subject: [PATCH] Fix lint and add unit test to test inconsistent auths --- hooks/ceph_radosgw_context.py | 4 ++-- hooks/utils.py | 3 ++- unit_tests/test_ceph_radosgw_context.py | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hooks/ceph_radosgw_context.py b/hooks/ceph_radosgw_context.py index fc8e6cc7..1e079904 100644 --- a/hooks/ceph_radosgw_context.py +++ b/hooks/ceph_radosgw_context.py @@ -85,8 +85,8 @@ class MonContext(context.OSContextGenerator): if _auth: auths.append(_auth) if len(set(auths)) != 1: - e=("Inconsistent or absent auth returned by mon units. Setting " - "auth_supported to 'none'") + e = ("Inconsistent or absent auth returned by mon units. Setting " + "auth_supported to 'none'") log(e, level=WARNING) auth = 'none' else: diff --git a/hooks/utils.py b/hooks/utils.py index 7ecae7a8..d14c6ecb 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -124,7 +124,8 @@ def check_optional_relations(configs): return ('blocked', 'hacluster missing configuration: ' 'vip, vip_iface, vip_cidr') - if cmp_pkgrevno(pkg, '0.55') >= 0 and relation_ids('identity-service'): + if cmp_pkgrevno('radosgw', '0.55') >= 0 and \ + relation_ids('identity-service'): required_interfaces['identity'] = ['identity-service'] if required_interfaces: set_os_workload_status(configs, required_interfaces) diff --git a/unit_tests/test_ceph_radosgw_context.py b/unit_tests/test_ceph_radosgw_context.py index efad4d5e..5bd801d7 100644 --- a/unit_tests/test_ceph_radosgw_context.py +++ b/unit_tests/test_ceph_radosgw_context.py @@ -7,6 +7,7 @@ import charmhelpers TO_PATCH = [ 'config', + 'log', 'relation_get', 'relation_ids', 'related_units', @@ -175,3 +176,27 @@ class MonContextTest(CharmTestCase): self.relation_ids.return_value = ['mon:6'] self.related_units.return_value = ['ceph/0', 'ceph/1', 'ceph/2'] self.assertEqual({}, mon_ctxt()) + + def test_ctxt_inconsistent_auths(self): + self.socket.gethostname.return_value = '10.0.0.10' + mon_ctxt = context.MonContext() + addresses = ['10.5.4.1', '10.5.4.2', '10.5.4.3'] + auths = ['cephx', 'cephy', 'cephz'] + + def _relation_get(attr, unit, rid): + if attr == 'ceph-public-address': + return addresses.pop() + elif attr == 'auth': + return auths.pop() + self.relation_get.side_effect = _relation_get + self.relation_ids.return_value = ['mon:6'] + self.related_units.return_value = ['ceph/0', 'ceph/1', 'ceph/2'] + expect = { + 'auth_supported': 'none', + 'embedded_webserver': False, + 'hostname': '10.0.0.10', + 'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789', + 'old_auth': False, + 'use_syslog': 'false' + } + self.assertEqual(expect, mon_ctxt())