Skip to content

Commit 831f388

Browse files
authored
[JUJU-3517] Revisit _build_facades in connection (#826)
The main change here is that we no longer raise an exception in the case of an unknown facade.
1 parent 5c4910b commit 831f388

2 files changed

Lines changed: 21 additions & 19 deletions

File tree

examples/deploy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ async def main():
2626
)
2727

2828
print('Waiting for active')
29-
await model.block_until(
30-
lambda: all(unit.workload_status == 'active'
31-
for unit in application.units))
29+
await model.wait_for_idle(status='active')
3230

3331
print('Removing ubuntu')
3432
await application.remove()

juju/client/connection.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,13 @@ async def _connect_with_redirect(self, endpoints):
873873
if not self._pinger_task:
874874
self._pinger_task = jasyncio.create_task(self._pinger())
875875

876-
def _build_facades(self, facades):
876+
# _build_facades takes the facade list that comes from the connection with the controller,
877+
# validates that the client knows about them (client_facades) and builds the facade list
878+
# (into the self.specified facades) with the max versions that both the client and the controller
879+
# can negotiate on
880+
def _build_facades(self, facades_from_connection):
877881
self.facades.clear()
878-
for facade in facades:
882+
for facade in facades_from_connection:
879883
name = facade['name']
880884
# the following attempts to get the best facade version for the
881885
# client. The client knows about the best facade versions it speaks,
@@ -884,31 +888,31 @@ def _build_facades(self, facades):
884888
if (name not in client_facades) and (name not in self.specified_facades):
885889
# if a facade is required but the client doesn't know about
886890
# it, then log a warning.
887-
log.warning('unknown facade {}'.format(name))
891+
log.warning(f'unexpected facade {name} received from the controller')
888892

889893
try:
890-
known = []
891894
# allow the ability to specify a set of facade versions, so the
892-
# client can define the non-conservitive facade client pinning.
895+
# client can define the non-conservative facade client pinning.
893896
if name in self.specified_facades:
894-
known = self.specified_facades[name]['versions']
897+
client_versions = self.specified_facades[name]['versions']
895898
elif name in client_facades:
896-
known = client_facades[name]['versions']
897-
else:
898-
raise errors.JujuConnectionError("unexpected facade {}".format(name))
899-
discovered = facade['versions']
900-
version = max(set(known).intersection(set(discovered)))
899+
client_versions = client_facades[name]['versions']
900+
901+
controller_versions = facade['versions']
902+
# select the max version that both the client and the controller know
903+
version = max(set(client_versions).intersection(set(controller_versions)))
901904
except ValueError:
902-
# this can occur if known is [1, 2] and discovered is [3, 4]
903-
# there is just no way to know how to communicate with the
904-
# facades we're trying to call.
905-
log.warning("unknown common facade version for {}".format(name))
905+
# this can occur if client_verisons is [1, 2] and controller_versions is [3, 4]
906+
# there is just no way to know how to communicate with the facades we're trying to call.
907+
log.warning(f'unknown common facade version for {name},\n'
908+
f'versions known to client : {client_versions}\n'
909+
f'versions known to controller : {controller_versions}')
906910
except errors.JujuConnectionError:
907911
# If the facade isn't with in the local facades then it's not
908912
# possible to reason about what version should be used. In this
909913
# case we should log the facade was found, but we couldn't
910914
# handle it.
911-
log.warning("unexpected facade {} found, unable to decipher version to use".format(name))
915+
log.warning(f'unexpected facade {name} found, unable to determine which version to use')
912916
else:
913917
self.facades[name] = version
914918

0 commit comments

Comments
 (0)