Skip to content

Commit 252dc15

Browse files
authored
Merge pull request #427 from thedac/issue/426
#427 Try each endpoint for the controller until success, only throw an exception if all endpoints have been attempted and failed. Without this change, the client will throw an OSError exception when for example trying to access the fan network from a host that is not on that fan network. Closes Issue: #426
2 parents 2157a1c + 20ac3d7 commit 252dc15

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

juju/client/connection.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,17 @@ async def connect(
302302
if max_frame_size is None:
303303
max_frame_size = self.MAX_FRAME_SIZE
304304
self.max_frame_size = max_frame_size
305-
await self._connect_with_redirect(
306-
[(endpoint, cacert)]
307-
if isinstance(endpoint, str)
308-
else [(e, cacert) for e in endpoint]
309-
)
310-
return self
305+
306+
_endpoints = [(endpoint, cacert)] if isinstance(endpoint, str) else [(e, cacert) for e in endpoint]
307+
for _ep in _endpoints:
308+
try:
309+
await self._connect_with_redirect([_ep])
310+
return self
311+
except OSError as e:
312+
logging.debug(
313+
"Cannot access endpoint {}: {}".format(_ep, e.strerror))
314+
continue
315+
raise Exception("Unable to connect to websocket")
311316

312317
@property
313318
def username(self):

0 commit comments

Comments
 (0)