[wallaby] Ensure get_requests_for_local_unit doesn't fail on incomplete relation
This is a rebuild/make sync for charms to pickup the fix in charmhelpers to fix any inadvertant accesses of ['ca'] in the relation data before it is available from vault in the certificates relation. Fix in charmhelpers is in [1]. [1] https://github.com/juju/charm-helpers/pull/829 Closes-Bug: #2028683 Change-Id: Icf929c3c623ef1011f29a7c20ea2c9ac6df706f1
This commit is contained in:
parent
4fc5070d5c
commit
789f6b9287
@ -414,18 +414,27 @@ def get_requests_for_local_unit(relation_name=None):
|
||||
is_legacy_request = set(sent).intersection(legacy_keys)
|
||||
for unit in related_units(rid):
|
||||
data = relation_get(rid=rid, unit=unit)
|
||||
if data.get(raw_certs_key):
|
||||
bundles.append({
|
||||
'ca': data['ca'],
|
||||
'chain': data.get('chain'),
|
||||
'certs': json.loads(data[raw_certs_key])})
|
||||
elif is_legacy_request:
|
||||
bundles.append({
|
||||
'ca': data['ca'],
|
||||
'chain': data.get('chain'),
|
||||
'certs': {sent['common_name']:
|
||||
{'cert': data.get(local_name + '.server.cert'),
|
||||
'key': data.get(local_name + '.server.key')}}})
|
||||
# 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):
|
||||
bundles.append({
|
||||
'ca': data['ca'],
|
||||
'chain': data.get('chain'),
|
||||
'certs': json.loads(data[raw_certs_key])
|
||||
})
|
||||
elif is_legacy_request:
|
||||
bundles.append({
|
||||
'ca': data['ca'],
|
||||
'chain': data.get('chain'),
|
||||
'certs': {
|
||||
sent['common_name']: {
|
||||
'cert': data.get(local_name + '.server.cert'),
|
||||
'key': data.get(local_name + '.server.key')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return bundles
|
||||
|
||||
|
@ -2604,6 +2604,23 @@ def get_subordinate_release_packages(os_release, package_type='deb'):
|
||||
return SubordinatePackages(install, purge)
|
||||
|
||||
|
||||
def get_subordinate_services():
|
||||
"""Iterate over subordinate relations and get service information.
|
||||
|
||||
In a similar fashion as with get_subordinate_release_packages(),
|
||||
principle charms can retrieve a list of services advertised by their
|
||||
subordinate charms. This is useful to know about subordinate services when
|
||||
pausing, resuming or upgrading a principle unit.
|
||||
|
||||
:returns: Name of all services advertised by all subordinates
|
||||
:rtype: Set[str]
|
||||
"""
|
||||
services = set()
|
||||
for rdata in container_scoped_relation_get('services'):
|
||||
services |= set(json.loads(rdata or '[]'))
|
||||
return services
|
||||
|
||||
|
||||
os_restart_on_change = partial(
|
||||
pausable_restart_on_change,
|
||||
can_restart_now_f=deferred_events.check_and_record_restart_request,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user