From f4bf629c63b636671fe28409a40279356a61b722 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Fri, 12 Jul 2019 15:05:39 +0200 Subject: [PATCH] Sync charm-helpers Change-Id: I9029777c7cad92ffb5edba3f8acacac015efd663 --- .../charmhelpers/contrib/charmsupport/nrpe.py | 35 +++++++++++++++++-- .../contrib/openstack/amulet/deployment.py | 17 +++++++++ .../charmhelpers/contrib/openstack/context.py | 8 +++-- .../contrib/storage/linux/ceph.py | 15 ++++++++ tests/basic_deployment.py | 2 +- tox.ini | 2 +- 6 files changed, 72 insertions(+), 7 deletions(-) diff --git a/hooks/charmhelpers/contrib/charmsupport/nrpe.py b/hooks/charmhelpers/contrib/charmsupport/nrpe.py index 0626b328..a3d89936 100644 --- a/hooks/charmhelpers/contrib/charmsupport/nrpe.py +++ b/hooks/charmhelpers/contrib/charmsupport/nrpe.py @@ -33,6 +33,7 @@ from charmhelpers.core.hookenv import ( hook_name, local_unit, log, + relation_get, relation_ids, relation_set, relations_of_type, @@ -260,11 +261,23 @@ class NRPE(object): relation = relation_ids('nrpe-external-master') if relation: log("Setting charm primary status {}".format(primary)) - for rid in relation_ids('nrpe-external-master'): + for rid in relation: relation_set(relation_id=rid, relation_settings={'primary': self.primary}) + self.remove_check_queue = set() def add_check(self, *args, **kwargs): + shortname = None + if kwargs.get('shortname') is None: + if len(args) > 0: + shortname = args[0] + else: + shortname = kwargs['shortname'] + self.checks.append(Check(*args, **kwargs)) + try: + self.remove_check_queue.remove(shortname) + except KeyError: + pass def remove_check(self, *args, **kwargs): if kwargs.get('shortname') is None: @@ -281,6 +294,7 @@ class NRPE(object): check = Check(*args, **kwargs) check.remove(self.hostname) + self.remove_check_queue.add(kwargs['shortname']) def write(self): try: @@ -313,7 +327,24 @@ class NRPE(object): monitor_ids = relation_ids("local-monitors") + \ relation_ids("nrpe-external-master") for rid in monitor_ids: - relation_set(relation_id=rid, monitors=yaml.dump(monitors)) + reldata = relation_get(unit=local_unit(), rid=rid) + if 'monitors' in reldata: + # update the existing set of monitors with the new data + old_monitors = yaml.safe_load(reldata['monitors']) + old_nrpe_monitors = old_monitors['monitors']['remote']['nrpe'] + # remove keys that are in the remove_check_queue + old_nrpe_monitors = {k: v for k, v in old_nrpe_monitors.items() + if k not in self.remove_check_queue} + # update/add nrpe_monitors + old_nrpe_monitors.update(nrpe_monitors) + old_monitors['monitors']['remote']['nrpe'] = old_nrpe_monitors + # write back to the relation + relation_set(relation_id=rid, monitors=yaml.dump(old_monitors)) + else: + # write a brand new set of monitors, as no existing ones. + relation_set(relation_id=rid, monitors=yaml.dump(monitors)) + + self.remove_check_queue.clear() def get_nagios_hostcontext(relation_name='nrpe-external-master'): diff --git a/hooks/charmhelpers/contrib/openstack/amulet/deployment.py b/hooks/charmhelpers/contrib/openstack/amulet/deployment.py index e6d5de63..77925cc2 100644 --- a/hooks/charmhelpers/contrib/openstack/amulet/deployment.py +++ b/hooks/charmhelpers/contrib/openstack/amulet/deployment.py @@ -323,6 +323,23 @@ class OpenStackAmuletDeployment(AmuletDeployment): else: return releases[self.series] + def get_percona_service_entry(self, memory_constraint=None): + """Return a amulet service entry for percona cluster. + + :param memory_constraint: Override the default memory constraint + in the service entry. + :type memory_constraint: str + :returns: Amulet service entry. + :rtype: dict + """ + memory_constraint = memory_constraint or '3072M' + svc_entry = { + 'name': 'percona-cluster', + 'constraints': {'mem': memory_constraint}} + if self._get_openstack_release() <= self.trusty_mitaka: + svc_entry['location'] = 'cs:trusty/percona-cluster' + return svc_entry + def get_ceph_expected_pools(self, radosgw=False): """Return a list of expected ceph pools in a ceph + cinder + glance test scenario, based on OpenStack release and whether ceph radosgw diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 5df59efc..a6545e12 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -258,7 +258,7 @@ class SharedDBContext(OSContextGenerator): 'database_password': rdata.get(password_setting), 'database_type': 'mysql+pymysql' } - if CompareOpenStackReleases(rel) < 'stein': + if CompareOpenStackReleases(rel) < 'queens': ctxt['database_type'] = 'mysql' if self.context_complete(ctxt): db_ssl(rdata, ctxt, self.ssl_dir) @@ -443,8 +443,10 @@ class IdentityServiceContext(OSContextGenerator): 'api_version': api_version}) if float(api_version) > 2: - ctxt.update({'admin_domain_name': - rdata.get('service_domain')}) + ctxt.update({ + 'admin_domain_name': rdata.get('service_domain'), + 'service_project_id': rdata.get('service_tenant_id'), + 'service_domain_id': rdata.get('service_domain_id')}) # we keep all veriables in ctxt for compatibility and # add nested dictionary for keystone_authtoken generic diff --git a/hooks/charmhelpers/contrib/storage/linux/ceph.py b/hooks/charmhelpers/contrib/storage/linux/ceph.py index bbfe1933..a9864467 100644 --- a/hooks/charmhelpers/contrib/storage/linux/ceph.py +++ b/hooks/charmhelpers/contrib/storage/linux/ceph.py @@ -1482,6 +1482,21 @@ def send_request_if_needed(request, relation='ceph'): relation_set(relation_id=rid, broker_req=request.request) +def has_broker_rsp(rid=None, unit=None): + """Return True if the broker_rsp key is 'truthy' (i.e. set to something) in the relation data. + + :param rid: The relation to check (default of None means current relation) + :type rid: Union[str, None] + :param unit: The remote unit to check (default of None means current unit) + :type unit: Union[str, None] + :returns: True if broker key exists and is set to something 'truthy' + :rtype: bool + """ + rdata = relation_get(rid=rid, unit=unit) or {} + broker_rsp = rdata.get(get_broker_rsp_key()) + return True if broker_rsp else False + + def is_broker_action_done(action, rid=None, unit=None): """Check whether broker action has completed yet. diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index d3a30449..7658c8fa 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -51,7 +51,7 @@ class NeutronGatewayBasicDeployment(OpenStackAmuletDeployment): """ this_service = {'name': 'neutron-gateway'} other_services = [ - {'name': 'percona-cluster', 'constraints': {'mem': '3072M'}}, + self.get_percona_service_entry(), {'name': 'rabbitmq-server'}, {'name': 'keystone'}, {'name': 'glance'}, # satisfy workload status diff --git a/tox.ini b/tox.ini index 63460ab6..acc30a09 100644 --- a/tox.ini +++ b/tox.ini @@ -95,7 +95,7 @@ basepython = python2.7 deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = - bundletester -vl DEBUG -r json -o func-results.json gate-basic-bionic-rocky --no-destroy + bundletester -vl DEBUG -r json -o func-results.json gate-basic-bionic-stein --no-destroy [testenv:func27-dfs] # Charm Functional Test