Skip to content

Commit 0fe52cc

Browse files
committed
Use only client version to check the server connection
Currently we spam debug output for any use of pylibjuju where the "target" != juju controller version. It should be turned into a ceiling, as it’s pretty normal to use the latest pylibjuju (currently 3.3.0.0) against any 3.x controller (e.g. 3.1). The only time we emit a warning should be when we think the client should be upgraded to a more recent version (e.g. running pylibjuju 3.3.0.0 against juju controller 3.6).
1 parent 8501b23 commit 0fe52cc

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

juju/client/connector.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
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
@@ -12,7 +14,7 @@
1214
from juju.client.jujudata import API_ENDPOINTS_KEY, FileJujuData
1315
from juju.client.proxy.factory import proxy_from_config
1416
from juju.errors import JujuConnectionError, JujuError
15-
from juju.version import SUPPORTED_MAJOR_VERSION, TARGET_JUJU_VERSION
17+
from juju.version import CLIENT_VERSION
1618

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

@@ -86,20 +88,19 @@ 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+
juju_server_version = version.parse(self._connection.info["server-version"])
92+
client_version = version.parse(CLIENT_VERSION)
93+
94+
if juju_server_version.major != client_version.major:
9995
raise JujuConnectionError(
10096
"juju server-version %s not supported" % juju_server_version
10197
)
10298

99+
if juju_server_version > client_version:
100+
log.warning(
101+
f"This client is tested up to the version {client_version} Juju controller. Detected a Juju controller version {juju_server_version} that's higher than the {client_version}. Some functionalities that the Juju {juju_server_version} offers may not be available. Please consider upgrading to pylibjuju {juju_server_version}."
102+
)
103+
103104
async def disconnect(self, entity):
104105
"""Shut down the watcher task and close websockets."""
105106
if self._connection:

juju/version.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
DEFAULT_ARCHITECTURE = 'amd64'
99

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

0 commit comments

Comments
 (0)