Skip to content

Commit

Permalink
Rip off the version sniffing on the connection
Browse files Browse the repository at this point in the history
Adapted from juju#1008 on the 2.9 track
  • Loading branch information
cderici committed Jan 26, 2024
1 parent 32ce250 commit 7afeb2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 2 additions & 9 deletions juju/client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
self._log_connection = None
self.controller_uuid = None
self.model_name = None
self.server_version = None
self.jujudata = jujudata or FileJujuData()

def is_connected(self):
Expand Down Expand Up @@ -87,24 +88,16 @@ async def connect(self, **kwargs):
await self._connection.close()
self._connection = await Connection.connect(**kwargs)

# Check if we support the target controller
server_version = self._connection.info["server-version"]
try:
juju_server_version = version.parse(server_version)
except version.InvalidVersion as err:
# We're only interested in the major version, so
# we attempt to clean up versions such as 3.4-rc1.2 as just 3.4
if '-' not in server_version:
raise JujuUnknownVersion(err)
juju_server_version = version.parse(server_version.split('-')[0])

# CLIENT_VERSION statically comes from the VERSION file in the repo
client_version = version.parse(CLIENT_VERSION)

if juju_server_version.major != client_version.major:
raise JujuConnectionError(
"juju server-version %s not supported" % juju_server_version
)
self.server_version = juju_server_version

async def disconnect(self, entity):
"""Shut down the watcher task and close websockets."""
Expand Down
3 changes: 3 additions & 0 deletions juju/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import pathlib
import re

import pathlib
import re

LTS_RELEASES = ["jammy", "focal", "bionic", "xenial", "trusty", "precise"]

DEFAULT_ARCHITECTURE = 'amd64'
Expand Down

0 comments on commit 7afeb2d

Please sign in to comment.