Sync charm libraries

Change-Id: Ic2916be468271eb3ff37b305429f3e4133e734c5
This commit is contained in:
Luciano Lo Giudice 2023-09-12 19:28:19 -03:00
parent 213d1055b0
commit 0962f230a1
5 changed files with 55 additions and 7 deletions

View File

@ -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():

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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',
}