|
4 | 4 | import copy |
5 | 5 | import logging |
6 | 6 |
|
| 7 | +from packaging import version |
| 8 | + |
7 | 9 | import macaroonbakery.httpbakery as httpbakery |
8 | 10 |
|
9 | 11 | from juju.client import client |
10 | 12 | from juju.client.connection import Connection |
11 | 13 | from juju.client.gocookies import GoCookieJar, go_to_py_cookie |
12 | 14 | from juju.client.jujudata import API_ENDPOINTS_KEY, FileJujuData |
13 | 15 | from juju.client.proxy.factory import proxy_from_config |
14 | | -from juju.errors import JujuConnectionError, JujuError |
15 | | -from juju.version import SUPPORTED_MAJOR_VERSION, TARGET_JUJU_VERSION |
| 16 | +from juju.errors import JujuConnectionError, JujuError, JujuUnknownVersion |
| 17 | +from juju.version import CLIENT_VERSION |
16 | 18 |
|
17 | 19 | log = logging.getLogger("connector") |
18 | 20 |
|
@@ -86,16 +88,20 @@ async def connect(self, **kwargs): |
86 | 88 | self._connection = await Connection.connect(**kwargs) |
87 | 89 |
|
88 | 90 | # Check if we support the target controller |
89 | | - juju_server_version = self._connection.info["server-version"] |
90 | | - if not juju_server_version.startswith(TARGET_JUJU_VERSION): |
91 | | - log.debug( |
92 | | - "This version was tested using {} juju version {} may have compatibility issues".format( |
93 | | - TARGET_JUJU_VERSION, juju_server_version |
94 | | - ) |
95 | | - ) |
96 | | - if not self._connection.info["server-version"].startswith( |
97 | | - SUPPORTED_MAJOR_VERSION |
98 | | - ): |
| 91 | + server_version = self._connection.info["server-version"] |
| 92 | + try: |
| 93 | + juju_server_version = version.parse(server_version) |
| 94 | + except version.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 |
| 102 | + client_version = version.parse(CLIENT_VERSION) |
| 103 | + |
| 104 | + if juju_server_version.major != client_version.major: |
99 | 105 | raise JujuConnectionError( |
100 | 106 | "juju server-version %s not supported" % juju_server_version |
101 | 107 | ) |
|
0 commit comments