Skip to content

Commit

Permalink
Use only client version to check the server connection
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
cderici committed Jan 16, 2024
1 parent 8501b23 commit 0fe52cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
23 changes: 12 additions & 11 deletions juju/client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import copy
import logging

from packaging import version

import macaroonbakery.httpbakery as httpbakery

from juju.client import client
Expand All @@ -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")

Expand Down Expand Up @@ -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:
Expand Down
18 changes: 8 additions & 10 deletions juju/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 0fe52cc

Please sign in to comment.