|
4 | 4 | import copy |
5 | 5 | import logging |
6 | 6 |
|
7 | | -from packaging import version |
| 7 | +from packaging import version, InvalidVersion |
8 | 8 |
|
9 | 9 | import macaroonbakery.httpbakery as httpbakery |
10 | 10 |
|
|
13 | 13 | from juju.client.gocookies import GoCookieJar, go_to_py_cookie |
14 | 14 | from juju.client.jujudata import API_ENDPOINTS_KEY, FileJujuData |
15 | 15 | from juju.client.proxy.factory import proxy_from_config |
16 | | -from juju.errors import JujuConnectionError, JujuError |
| 16 | +from juju.errors import JujuConnectionError, JujuError, JujuUnknownVersion |
17 | 17 | from juju.version import CLIENT_VERSION |
18 | 18 |
|
19 | 19 | log = logging.getLogger("connector") |
@@ -88,7 +88,17 @@ async def connect(self, **kwargs): |
88 | 88 | self._connection = await Connection.connect(**kwargs) |
89 | 89 |
|
90 | 90 | # Check if we support the target controller |
91 | | - juju_server_version = version.parse(self._connection.info["server-version"]) |
| 91 | + server_version = self._connection.info["server-version"] |
| 92 | + try: |
| 93 | + juju_server_version = version.parse(server_version) |
| 94 | + except InvalidVersion as err: |
| 95 | + # We're only interested in the major version, so |
| 96 | + # we attempt to clean up versions such as 3.4-rc1.2 as just 3.4 |
| 97 | + if '-' not in server_version: |
| 98 | + raise JujuUnknownVersion(err) |
| 99 | + juju_server_version = version.parse(server_version.split('-')[0]) |
| 100 | + |
| 101 | + # CLIENT_VERSION statically comes from the VERSION file in the repo |
92 | 102 | client_version = version.parse(CLIENT_VERSION) |
93 | 103 |
|
94 | 104 | if juju_server_version.major != client_version.major: |
|
0 commit comments