From 0962f230a11d425487df84fbb6c0c40f7319e3fa Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Tue, 12 Sep 2023 19:28:19 -0300 Subject: [PATCH] Sync charm libraries Change-Id: Ic2916be468271eb3ff37b305429f3e4133e734c5 --- charmhelpers/contrib/storage/linux/ceph.py | 8 +++-- charmhelpers/core/unitdata.py | 39 +++++++++++++++++++++- charmhelpers/fetch/snap.py | 2 +- lib/charms_ceph/broker.py | 2 +- lib/charms_ceph/utils.py | 11 ++++-- 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/charmhelpers/contrib/storage/linux/ceph.py b/charmhelpers/contrib/storage/linux/ceph.py index 2e1fc1b..6ec67cb 100644 --- a/charmhelpers/contrib/storage/linux/ceph.py +++ b/charmhelpers/contrib/storage/linux/ceph.py @@ -158,15 +158,19 @@ def get_osd_settings(relation_name): return _order_dict_by_key(osd_settings) -def send_application_name(relid=None): +def send_application_name(relid=None, app_name=None): """Send the application name down the relation. :param relid: Relation id to set application name in. :type relid: str + :param app_name: Application name to send in the relation. + :type app_name: str """ + if app_name is None: + app_name = application_name() relation_set( relation_id=relid, - relation_settings={'application-name': application_name()}) + relation_settings={'application-name': app_name}) def send_osd_settings(): diff --git a/charmhelpers/core/unitdata.py b/charmhelpers/core/unitdata.py index 8f4bbc6..65153f1 100644 --- a/charmhelpers/core/unitdata.py +++ b/charmhelpers/core/unitdata.py @@ -151,6 +151,7 @@ import contextlib import datetime import itertools import json +import logging import os import pprint import sqlite3 @@ -521,6 +522,42 @@ _KV = None def kv(): global _KV + + # If we are running unit tests, it is useful to go into memory-backed KV store to + # avoid concurrency issues when running multiple tests. This is not a + # problem when juju is running normally. + + env_var = os.environ.get("CHARM_HELPERS_TESTMODE", "auto").lower() + if env_var not in ["auto", "no", "yes"]: + logging.warning("Unknown value for CHARM_HELPERS_TESTMODE '%s'" + ", assuming 'no'", env_var) + env_var = "no" + + if env_var == "no": + in_memory_db = False + elif env_var == "yes": + in_memory_db = True + elif env_var == "auto": + # If UNIT_STATE_DB is set, respect this request + if "UNIT_STATE_DB" in os.environ: + in_memory_db = False + # Autodetect normal juju execution by looking for juju variables + elif "JUJU_CHARM_DIR" in os.environ or "JUJU_UNIT_NAME" in os.environ: + in_memory_db = False + else: + # We are probably running in unit test mode + logging.warning("Auto-detected unit test environment for KV store.") + in_memory_db = True + else: + # Help the linter realise that in_memory_db is always set + raise Exception("Cannot reach this line") + if _KV is None: - _KV = Storage() + if in_memory_db: + _KV = Storage(":memory:") + else: + _KV = Storage() + else: + if in_memory_db and _KV.db_path != ":memory:": + logging.warning("Running with in_memory_db and KV is not set to :memory:") return _KV diff --git a/charmhelpers/fetch/snap.py b/charmhelpers/fetch/snap.py index 36d6bce..7ab7ce3 100644 --- a/charmhelpers/fetch/snap.py +++ b/charmhelpers/fetch/snap.py @@ -52,7 +52,7 @@ def _snap_exec(commands): :param commands: List commands :return: Integer exit code """ - assert type(commands) == list + assert isinstance(commands, list) retry_count = 0 return_code = None diff --git a/lib/charms_ceph/broker.py b/lib/charms_ceph/broker.py index 90b536f..71f85f4 100644 --- a/lib/charms_ceph/broker.py +++ b/lib/charms_ceph/broker.py @@ -907,7 +907,7 @@ def process_requests_v1(reqs): log(msg, level=ERROR) return {'exit-code': 1, 'stderr': msg} - if type(ret) == dict and 'exit-code' in ret: + if isinstance(ret, dict) and 'exit-code' in ret: return ret return {'exit-code': 0} diff --git a/lib/charms_ceph/utils.py b/lib/charms_ceph/utils.py index 01fb9ac..94bfb9e 100644 --- a/lib/charms_ceph/utils.py +++ b/lib/charms_ceph/utils.py @@ -1223,6 +1223,11 @@ def get_upgrade_key(): return get_named_key('upgrade-osd', _upgrade_caps) +def is_internal_client(name): + keys = ('osd-upgrade', 'osd-removal', 'admin', 'rbd-mirror', 'mds') + return any(name.startswith(key) for key in keys) + + def get_named_key(name, caps=None, pool_list=None): """Retrieve a specific named cephx key. @@ -1236,7 +1241,8 @@ def get_named_key(name, caps=None, pool_list=None): key = ceph_auth_get(key_name) if key: - upgrade_key_caps(key_name, caps) + if is_internal_client(name): + upgrade_key_caps(key_name, caps) return key log("Creating new key for {}".format(name), level=DEBUG) @@ -3225,6 +3231,7 @@ UPGRADE_PATHS = collections.OrderedDict([ ('nautilus', 'octopus'), ('octopus', 'pacific'), ('pacific', 'quincy'), + ('quincy', 'reef'), ]) # Map UCA codenames to Ceph codenames @@ -3248,7 +3255,7 @@ UCA_CODENAME_MAP = { 'yoga': 'quincy', 'zed': 'quincy', 'antelope': 'quincy', - 'bobcat': 'quincy', + 'bobcat': 'reef', }