Skip to content

Commit ea70f49

Browse files
authored
Merge branch 'master' into makefile-tests-quality-of-life
2 parents 2dad234 + 1cc3c58 commit ea70f49

4 files changed

Lines changed: 35 additions & 22 deletions

File tree

juju/client/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from juju import errors, tag, utils, jasyncio
1818
from juju.client import client
1919
from juju.utils import IdQueue
20-
from juju.version import TARGET_JUJU_VERSION
20+
from juju.version import CLIENT_VERSION
2121

2222
log = logging.getLogger('juju.client.connection')
2323

@@ -963,7 +963,7 @@ def _build_facades(self, facades_from_connection):
963963
async def login(self):
964964
params = {}
965965
# Set the client version
966-
params['client-version'] = TARGET_JUJU_VERSION
966+
params['client-version'] = CLIENT_VERSION
967967
params['auth-tag'] = self.usertag
968968
if self.password:
969969
params['credentials'] = self.password

juju/client/connector.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
import copy
55
import logging
66

7+
from packaging import version
8+
79
import macaroonbakery.httpbakery as httpbakery
810

911
from juju.client import client
1012
from juju.client.connection import Connection
1113
from juju.client.gocookies import GoCookieJar, go_to_py_cookie
1214
from juju.client.jujudata import API_ENDPOINTS_KEY, FileJujuData
1315
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
1618

1719
log = logging.getLogger("connector")
1820

@@ -86,16 +88,20 @@ async def connect(self, **kwargs):
8688
self._connection = await Connection.connect(**kwargs)
8789

8890
# 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:
99105
raise JujuConnectionError(
100106
"juju server-version %s not supported" % juju_server_version
101107
)

juju/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,7 @@ class AbstractMethodError(Exception):
137137

138138
class PylibjujuError(JujuError):
139139
pass
140+
141+
142+
class JujuUnknownVersion(PylibjujuError):
143+
pass

juju/version.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
33

4+
import pathlib
5+
import re
46

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

79
DEFAULT_ARCHITECTURE = 'amd64'
810

9-
# Juju server version we target. Depending on this value, the Juju server
10-
# may stop the connecting considering us not compatible.
11-
TARGET_JUJU_VERSION = '3.2.0'
12-
13-
# Used by connector to determine if we are compatible with the juju server
14-
SUPPORTED_MAJOR_VERSION = '3'
15-
16-
SUPPORTED_MAJOR_MINOR_VERSION = '3.2'
11+
# CLIENT_VERSION (that's read from the VERSION file) is the highest Juju server
12+
# version that this client supports.
13+
# Note that this is a ceiling. CLIENT_VERSION <= juju-controller-version works.
14+
# For CLIENT_VERSION < juju-controller-version (strictly smaller), we emit a warning
15+
# to update the client to the latest.
16+
# However, for any CLIENT_VERSION > juju-controller-version, a "client incompatible
17+
# with server" will be returned by the juju controller.
18+
VERSION_FILE_PATH = pathlib.Path(__file__).parent.parent / 'VERSION'
19+
CLIENT_VERSION = re.search(r'\d+\.\d+\.\d+', open(VERSION_FILE_PATH).read().strip()).group()

0 commit comments

Comments
 (0)