Sync charm libraries

Change-Id: Ie6ae6fa1369db537fa606fa04df538f9a5587a0c
This commit is contained in:
Luciano Lo Giudice 2023-09-12 19:23:43 -03:00
parent c7e8b113f6
commit e97890043c
6 changed files with 77 additions and 21 deletions

View File

@ -414,18 +414,27 @@ def get_requests_for_local_unit(relation_name=None):
is_legacy_request = set(sent).intersection(legacy_keys) is_legacy_request = set(sent).intersection(legacy_keys)
for unit in related_units(rid): for unit in related_units(rid):
data = relation_get(rid=rid, unit=unit) data = relation_get(rid=rid, unit=unit)
# Note: Bug#2028683 - data may not be available if the certificates
# relation hasn't been populated by the providing charm. If no 'ca'
# in the data then don't attempt the bundle at all.
if data.get('ca'):
if data.get(raw_certs_key): if data.get(raw_certs_key):
bundles.append({ bundles.append({
'ca': data['ca'], 'ca': data['ca'],
'chain': data.get('chain'), 'chain': data.get('chain'),
'certs': json.loads(data[raw_certs_key])}) 'certs': json.loads(data[raw_certs_key])
})
elif is_legacy_request: elif is_legacy_request:
bundles.append({ bundles.append({
'ca': data['ca'], 'ca': data['ca'],
'chain': data.get('chain'), 'chain': data.get('chain'),
'certs': {sent['common_name']: 'certs': {
{'cert': data.get(local_name + '.server.cert'), sent['common_name']: {
'key': data.get(local_name + '.server.key')}}}) 'cert': data.get(local_name + '.server.cert'),
'key': data.get(local_name + '.server.key')
}
}
})
return bundles return bundles

View File

@ -1748,9 +1748,9 @@ class WSGIWorkerConfigContext(WorkerConfigContext):
def __call__(self): def __call__(self):
total_processes = _calculate_workers() total_processes = _calculate_workers()
enable_wsgi_rotation = config('wsgi-rotation') enable_wsgi_socket_rotation = config('wsgi-socket-rotation')
if enable_wsgi_rotation is None: if enable_wsgi_socket_rotation is None:
enable_wsgi_rotation = True enable_wsgi_socket_rotation = True
ctxt = { ctxt = {
"service_name": self.service_name, "service_name": self.service_name,
"user": self.user, "user": self.user,
@ -1764,7 +1764,7 @@ class WSGIWorkerConfigContext(WorkerConfigContext):
"public_processes": int(math.ceil(self.public_process_weight * "public_processes": int(math.ceil(self.public_process_weight *
total_processes)), total_processes)),
"threads": 1, "threads": 1,
"wsgi_rotation": enable_wsgi_rotation, "wsgi_socket_rotation": enable_wsgi_socket_rotation,
} }
return ctxt return ctxt

View File

@ -158,15 +158,19 @@ def get_osd_settings(relation_name):
return _order_dict_by_key(osd_settings) 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. """Send the application name down the relation.
:param relid: Relation id to set application name in. :param relid: Relation id to set application name in.
:type relid: str :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_set(
relation_id=relid, relation_id=relid,
relation_settings={'application-name': application_name()}) relation_settings={'application-name': app_name})
def send_osd_settings(): def send_osd_settings():

View File

@ -151,6 +151,7 @@ import contextlib
import datetime import datetime
import itertools import itertools
import json import json
import logging
import os import os
import pprint import pprint
import sqlite3 import sqlite3
@ -521,6 +522,42 @@ _KV = None
def kv(): def kv():
global _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: if _KV is None:
if in_memory_db:
_KV = Storage(":memory:")
else:
_KV = Storage() _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 return _KV

View File

@ -52,7 +52,7 @@ def _snap_exec(commands):
:param commands: List commands :param commands: List commands
:return: Integer exit code :return: Integer exit code
""" """
assert type(commands) == list assert isinstance(commands, list)
retry_count = 0 retry_count = 0
return_code = None return_code = None

View File

@ -1223,6 +1223,11 @@ def get_upgrade_key():
return get_named_key('upgrade-osd', _upgrade_caps) 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): def get_named_key(name, caps=None, pool_list=None):
"""Retrieve a specific named cephx key. """Retrieve a specific named cephx key.
@ -1236,6 +1241,7 @@ def get_named_key(name, caps=None, pool_list=None):
key = ceph_auth_get(key_name) key = ceph_auth_get(key_name)
if key: if key:
if is_internal_client(name):
upgrade_key_caps(key_name, caps) upgrade_key_caps(key_name, caps)
return key return key