From 9fff167af36edd86d7399990cae1231bf1ddaca5 Mon Sep 17 00:00:00 2001 From: Aurelien Lourot Date: Fri, 1 Oct 2021 16:29:52 +0200 Subject: [PATCH 1/2] Add function for retrieving subordinate services (#643) https://bugs.launchpad.net/charm-ceilometer-agent/+bug/1927277 (cherry picked from commit 5ed3500dc9797523c77aa57fa18ba81d091878f4) --- charmhelpers/contrib/openstack/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/charmhelpers/contrib/openstack/utils.py b/charmhelpers/contrib/openstack/utils.py index f994a3a19..b6171fc03 100644 --- a/charmhelpers/contrib/openstack/utils.py +++ b/charmhelpers/contrib/openstack/utils.py @@ -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, From 984808b3af69753df4f38844da69abe5f6a1a698 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Wed, 9 Aug 2023 10:42:21 -0400 Subject: [PATCH 2/2] pep8: use isinstance() --- charmhelpers/fetch/snap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charmhelpers/fetch/snap.py b/charmhelpers/fetch/snap.py index 36d6bce9a..7ab7ce3e2 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