Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target ceiling version #1008

Merged
merged 8 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions juju/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from juju import errors, tag, utils, jasyncio
from juju.client import client
from juju.utils import IdQueue
from juju.version import TARGET_JUJU_VERSION
from juju.version import CLIENT_VERSION

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

Expand Down Expand Up @@ -963,7 +963,7 @@ def _build_facades(self, facades_from_connection):
async def login(self):
params = {}
# Set the client version
params['client-version'] = TARGET_JUJU_VERSION
params['client-version'] = CLIENT_VERSION
params['auth-tag'] = self.usertag
if self.password:
params['credentials'] = self.password
Expand Down
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}."
cderici marked this conversation as resolved.
Show resolved Hide resolved
)

async def disconnect(self, entity):
"""Shut down the watcher task and close websockets."""
if self._connection:
Expand Down
19 changes: 11 additions & 8 deletions juju/version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.

import pathlib
import re

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

DEFAULT_ARCHITECTURE = 'amd64'

# 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'
# 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 = pathlib.Path(__file__).parent.parent / 'VERSION'
CLIENT_VERSION = re.search(r'\d+\.\d+\.\d+', open(VERSION_FILE_PATH).read().strip()).group()
Loading