From 0fe52cc48444e11aca0a1abeb5e714532a5c3c15 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Tue, 16 Jan 2024 12:30:25 -0700 Subject: [PATCH] Use only client version to check the server connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- juju/client/connector.py | 23 ++++++++++++----------- juju/version.py | 18 ++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/juju/client/connector.py b/juju/client/connector.py index 69840620..c57ca9ed 100644 --- a/juju/client/connector.py +++ b/juju/client/connector.py @@ -4,6 +4,8 @@ import copy import logging +from packaging import version + import macaroonbakery.httpbakery as httpbakery from juju.client import client @@ -12,7 +14,7 @@ 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.version import SUPPORTED_MAJOR_VERSION, TARGET_JUJU_VERSION +from juju.version import CLIENT_VERSION log = logging.getLogger("connector") @@ -86,20 +88,19 @@ async def connect(self, **kwargs): self._connection = await Connection.connect(**kwargs) # Check if we support the target controller - juju_server_version = self._connection.info["server-version"] - if not juju_server_version.startswith(TARGET_JUJU_VERSION): - log.debug( - "This version was tested using {} juju version {} may have compatibility issues".format( - TARGET_JUJU_VERSION, juju_server_version - ) - ) - if not self._connection.info["server-version"].startswith( - SUPPORTED_MAJOR_VERSION - ): + juju_server_version = version.parse(self._connection.info["server-version"]) + client_version = version.parse(CLIENT_VERSION) + + if juju_server_version.major != client_version.major: raise JujuConnectionError( "juju server-version %s not supported" % juju_server_version ) + if juju_server_version > client_version: + log.warning( + 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}." + ) + async def disconnect(self, entity): """Shut down the watcher task and close websockets.""" if self._connection: diff --git a/juju/version.py b/juju/version.py index 36b3157a..6e007a4c 100644 --- a/juju/version.py +++ b/juju/version.py @@ -7,14 +7,12 @@ DEFAULT_ARCHITECTURE = 'amd64' -VERSION_FILE_PATH = '../VERSION' +# CLIENT_VERSION (that's read from the VERSION file) is the highest Juju server +# version that this client supports. +# Note that this is a ceiling. CLIENT_VERSION <= juju-controller-version works. +# For CLIENT_VERSION < juju-controller-version (strictly smaller), we emit a warning +# to update the client to the latest. +# However, for any CLIENT_VERSION > juju-controller-version, a "client incompatible +# with server" will be returned by the juju controller. +VERSION_FILE_PATH = './VERSION' CLIENT_VERSION = re.search(r'\d+\.\d+\.\d+', open(VERSION_FILE_PATH).read().strip()).group() - -# Juju server version we target. Depending on this value, the Juju server -# may stop the connecting considering us not compatible. -TARGET_JUJU_VERSION = '3.2.0' - -# Used by connector to determine if we are compatible with the juju server -SUPPORTED_MAJOR_VERSION = '3' - -SUPPORTED_MAJOR_MINOR_VERSION = '3.2'