From 9f87617396cdaada7ab20d81ef76ab766123bbd8 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 13 Apr 2023 14:58:48 -0600 Subject: [PATCH 1/3] Use wait_for_idle in the example/deploy --- examples/deploy.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/deploy.py b/examples/deploy.py index 6fdd863dc..d4f262be6 100644 --- a/examples/deploy.py +++ b/examples/deploy.py @@ -25,10 +25,9 @@ async def main(): channel='stable', ) + print('Waiting for active') - await model.block_until( - lambda: all(unit.workload_status == 'active' - for unit in application.units)) + await model.wait_for_idle(status='active') print('Removing ubuntu') await application.remove() From bab81f2720616d933e261215550d8e5af34bdabf Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 13 Apr 2023 14:59:09 -0600 Subject: [PATCH 2/3] Refactor and improve the _build_facade The main change here is that we no longer raise an exception in the case of an unknown facade. --- juju/client/connection.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index 244c9cdee..871ae8a7e 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -873,9 +873,13 @@ async def _connect_with_redirect(self, endpoints): if not self._pinger_task: self._pinger_task = jasyncio.create_task(self._pinger()) - def _build_facades(self, facades): + # _build_facades takes the facade list that comes from the connection with the controller, + # validates that the client knows about them (client_facades) and builds the facade list + # (into the self.specified facades) with the max versions that both the client and the controller + # can negotiate on + def _build_facades(self, facades_from_connection): self.facades.clear() - for facade in facades: + for facade in facades_from_connection: name = facade['name'] # the following attempts to get the best facade version for the # client. The client knows about the best facade versions it speaks, @@ -884,31 +888,31 @@ def _build_facades(self, facades): if (name not in client_facades) and (name not in self.specified_facades): # if a facade is required but the client doesn't know about # it, then log a warning. - log.warning('unknown facade {}'.format(name)) + log.warning(f'unexpected facade {name} received from the controller') try: - known = [] # allow the ability to specify a set of facade versions, so the - # client can define the non-conservitive facade client pinning. + # client can define the non-conservative facade client pinning. if name in self.specified_facades: - known = self.specified_facades[name]['versions'] + client_versions = self.specified_facades[name]['versions'] elif name in client_facades: - known = client_facades[name]['versions'] - else: - raise errors.JujuConnectionError("unexpected facade {}".format(name)) - discovered = facade['versions'] - version = max(set(known).intersection(set(discovered))) + client_versions = client_facades[name]['versions'] + + controller_versions = facade['versions'] + # select the max version that both the client and the controller know + version = max(set(client_versions).intersection(set(controller_versions))) except ValueError: - # this can occur if known is [1, 2] and discovered is [3, 4] - # there is just no way to know how to communicate with the - # facades we're trying to call. - log.warning("unknown common facade version for {}".format(name)) + # this can occur if client_verisons is [1, 2] and controller_versions is [3, 4] + # there is just no way to know how to communicate with the facades we're trying to call. + log.warning(f'unknown common facade version for {name},\n' + f'versions known to client : {client_versions}\n' + f'versions known to controller : {controller_versions}') except errors.JujuConnectionError: # If the facade isn't with in the local facades then it's not # possible to reason about what version should be used. In this # case we should log the facade was found, but we couldn't # handle it. - log.warning("unexpected facade {} found, unable to decipher version to use".format(name)) + log.warning(f'unexpected facade {name} found, unable to determine which version to use') else: self.facades[name] = version From 0047796f0b219aac70795a36eeb0cf0c65f211fb Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 13 Apr 2023 15:21:52 -0600 Subject: [PATCH 3/3] Fix linter --- examples/deploy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/deploy.py b/examples/deploy.py index d4f262be6..3e553cb87 100644 --- a/examples/deploy.py +++ b/examples/deploy.py @@ -25,7 +25,6 @@ async def main(): channel='stable', ) - print('Waiting for active') await model.wait_for_idle(status='active')