Skip to content

Commit

Permalink
Handle non-standard version strings coming from api
Browse files Browse the repository at this point in the history
  • Loading branch information
cderici committed Jan 23, 2024
1 parent 2d725fa commit b9f6089
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions juju/client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import copy
import logging

from packaging import version
from packaging import version, InvalidVersion

import macaroonbakery.httpbakery as httpbakery

Expand All @@ -13,7 +13,7 @@
from juju.client.gocookies import GoCookieJar, go_to_py_cookie
from juju.client.jujudata import API_ENDPOINTS_KEY, FileJujuData
from juju.client.proxy.factory import proxy_from_config
from juju.errors import JujuConnectionError, JujuError
from juju.errors import JujuConnectionError, JujuError, JujuUnknownVersion
from juju.version import CLIENT_VERSION

log = logging.getLogger("connector")
Expand Down Expand Up @@ -88,7 +88,17 @@ async def connect(self, **kwargs):
self._connection = await Connection.connect(**kwargs)

# Check if we support the target controller
juju_server_version = version.parse(self._connection.info["server-version"])
server_version = self._connection.info["server-version"]
try:
juju_server_version = version.parse(server_version)
except 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:
Expand Down
4 changes: 4 additions & 0 deletions juju/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ class AbstractMethodError(Exception):

class PylibjujuError(JujuError):
pass


class JujuUnknownVersion(PylibjujuError):
pass

0 comments on commit b9f6089

Please sign in to comment.