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

current_os_release also consider OpenStack release set in configuration #400

Merged
merged 9 commits into from
May 7, 2024
24 changes: 16 additions & 8 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,18 @@ def __repr__(self) -> str:
def apt_source_codename(self) -> OpenStackRelease:
"""Identify the OpenStack release set on "openstack-origin" or "source" config.

:raises ApplicationError: When origin setting is not valid.
:raises ApplicationError: When origin setting or series are not valid.
:return: OpenStackRelease object.
:rtype: OpenStackRelease
"""
# means that the charm doesn't have origin setting config or is using empty string.
if not self.o7k_origin:
return self.o7k_release

if self.o7k_origin.startswith("cloud"):
return self._extract_from_uca_source()

if self.o7k_origin == "distro":
# consider as "distro" if the application does not have source or is empty
if self.o7k_origin in {"distro", ""}:
# find the OpenStack release based on ubuntu series
if self.series not in DISTRO_TO_OPENSTACK_MAPPING:
raise ApplicationError(f"Series '{self.series}' is not supported by COU.")
aieri marked this conversation as resolved.
Show resolved Hide resolved
return OpenStackRelease(DISTRO_TO_OPENSTACK_MAPPING[self.series])

# probably because user set a ppa or a url
Expand Down Expand Up @@ -213,9 +212,16 @@ def _get_o7k_release_from_channel(self, channel: str) -> OpenStackRelease:
def o7k_release(self) -> OpenStackRelease:
"""Current OpenStack Release of the application.

Applications that are colocated in a same machine will upgrade all the packages in the
rgildein marked this conversation as resolved.
Show resolved Hide resolved
machine during an upgrade. This means that when upgrading a application X, the application
Y colocated with it also upgrades its packages. To ensure to change the 'source' or
'openstack-origin' and run all the upgrade steps necessary, it's necessary to include the
OpenStack release set in the application configuration.
:return: OpenStackRelease object
:rtype: OpenStackRelease
"""
if self.o7k_origin:
return min(list(self.o7k_release_units.keys()) + [self.apt_source_codename])
return min(self.o7k_release_units.keys())

@property
Expand Down Expand Up @@ -861,16 +867,18 @@ def _check_application_target(self, target: OpenStackRelease) -> None:
:raises HaltUpgradePlanGeneration: When the application halt the upgrade plan generation.
"""
logger.debug(
"%s application current o7k_release is %s and apt source is %s",
"%s current os_release is '%s' with origin setting '%s' and apt source '%s'",
self.name,
self.o7k_release,
self.o7k_origin,
self.apt_source_codename,
)

if (
self.o7k_release >= target
and not self.can_upgrade_to
and self.apt_source_codename >= target
# consider apt_source_codename just when exist or not empty
and (self.apt_source_codename >= target if self.o7k_origin else True)
):
raise HaltUpgradePlanGeneration(
f"Application '{self.name}' already configured for release equal to or greater "
Expand Down
19 changes: 0 additions & 19 deletions cou/apps/subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from cou.apps.base import OpenStackApplication
from cou.apps.factory import AppFactory
from cou.exceptions import HaltUpgradePlanGeneration
from cou.steps import PostUpgradeStep, PreUpgradeStep, UpgradeStep
from cou.utils.juju_utils import Unit
from cou.utils.openstack import SUBORDINATES, OpenStackRelease
Expand All @@ -44,24 +43,6 @@ def o7k_release(self) -> OpenStackRelease:
"""
return self.channel_o7k_release

def _check_application_target(self, target: OpenStackRelease) -> None:
"""Check if the application is already upgraded.

Subordinate applications use the apt source of the related principal and don't have an
origin/openstack-origin config option.

:param target: OpenStack release as target to upgrade.
:type target: OpenStackRelease
:raises HaltUpgradePlanGeneration: When the application halt the upgrade plan generation.
"""
logger.debug("%s application current o7k_release is %s", self.name, self.o7k_release)

if self.o7k_release >= target and not self.can_upgrade_to:
raise HaltUpgradePlanGeneration(
f"Application '{self.name}' already configured for release equal to or greater "
f"than {target}. Ignoring."
)

def _get_upgrade_current_release_packages_step(
self, units: Optional[list[Unit]]
) -> PreUpgradeStep:
Expand Down
8 changes: 6 additions & 2 deletions cou/steps/plan.py
aieri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _get_post_upgrade_steps(analysis_result: Analysis, args: CLIargs) -> list[Po
"""
steps = []
if args.upgrade_group in {DATA_PLANE, None}:
steps.extend(_get_ceph_mon_post_upgrade_steps(analysis_result.apps_data_plane))
steps.extend(_get_ceph_mon_post_upgrade_steps(analysis_result.apps_control_plane))

return steps

Expand All @@ -415,7 +415,11 @@ def _get_ceph_mon_post_upgrade_steps(apps: list[OpenStackApplication]) -> list[P
"""
ceph_mons_apps = [app for app in apps if isinstance(app, CephMon)]

steps = []
steps: list[PostUpgradeStep] = []
if not ceph_mons_apps:
logger.warning("There is no ceph-mon application. Is this a valid OpenStack cloud?")
return steps

for app in ceph_mons_apps:
unit = list(app.units.values())[0] # getting the first unit, since we don't care which one
steps.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ plan: |
Upgrade 'cinder-lvm-slow' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrade plan for 'cinder-volume-mysql-router' to 'victoria'
Refresh 'cinder-volume-mysql-router' to the latest revision of '8.0/stable'
Ensure that the 'require-osd-release' option in 'ceph-mon' matches the 'ceph-osd' version


applications:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ plan: |
Upgrade 'ceilometer-agent' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrade plan for 'ovn-chassis' to 'victoria'
WARNING: Changing 'ovn-chassis' channel from latest/stable to 22.03/stable. This may be a charm downgrade, which is generally not supported.
Ensure that the 'require-osd-release' option in 'ceph-mon' matches the 'ceph-osd' version

applications:
rabbitmq-server:
Expand Down
20 changes: 11 additions & 9 deletions tests/unit/apps/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def test_auxiliary_app(model):
assert app.apt_source_codename == "ussuri"
assert app.channel_o7k_release == "yoga"
assert app.is_subordinate is False
assert app.o7k_release == "yoga"

# the workload version of units are considered as yoga
assert min(app.o7k_release_units.keys()) == "yoga"
# application is considered as ussuri because the source is pointing to it
assert app.o7k_release == "ussuri"


def test_auxiliary_app_cs(model):
Expand Down Expand Up @@ -103,8 +107,11 @@ def test_auxiliary_app_cs(model):
assert app.is_valid_track(app.channel) is False
assert app.o7k_origin == "distro"
assert app.apt_source_codename == "ussuri"
# the workload version of units are considered as yoga
assert min(app.o7k_release_units.keys()) == "yoga"
# application is considered as ussuri because the source is pointing to it
assert app.channel_o7k_release == "ussuri"
assert app.o7k_release == "yoga"
assert app.o7k_release == "ussuri"


def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(model):
Expand Down Expand Up @@ -392,12 +399,7 @@ def test_auxiliary_raise_error_unknown_series(model):
"""Test auxiliary application with unknown series."""
series = "foo"
channel = "3.8/stable"
exp_msg = (
f"Channel: {channel} for charm 'rabbitmq-server' on series '{series}' is not supported by "
"COU. Please take a look at the documentation: "
"https://docs.openstack.org/charm-guide/latest/project/charm-delivery.html "
"to see if you are using the right track."
)
exp_msg = "Series 'foo' is not supported by COU."
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
Expand Down Expand Up @@ -810,7 +812,7 @@ def test_ovn_principal(model):
assert app.o7k_origin == "distro"
assert app.apt_source_codename == "ussuri"
assert app.channel_o7k_release == "yoga"
assert app.o7k_release == "yoga"
assert app.o7k_release == "ussuri"
assert app.is_subordinate is False


Expand Down
6 changes: 4 additions & 2 deletions tests/unit/apps/test_auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def test_auxiliary_subordinate(model):
assert app.channel == "8.0/stable"
assert app.origin == "ch"
assert app.o7k_origin == ""
assert app.apt_source_codename == "yoga"
# when don't have os_origin is considered as "distro" which points to ussuri in this case
assert app.apt_source_codename == "ussuri"
assert app.channel_o7k_release == "yoga"
assert app.o7k_release == "yoga"
assert app.is_subordinate is True
Expand Down Expand Up @@ -105,7 +106,8 @@ def test_ovn_subordinate(model):

assert app.channel == "22.03/stable"
assert app.o7k_origin == ""
assert app.apt_source_codename == "yoga"
# when don't have os_origin is considered as "distro" which points to ussuri in this case
assert app.apt_source_codename == "ussuri"
assert app.channel_o7k_release == "yoga"
assert app.o7k_release == "yoga"
assert app.is_subordinate is True
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/steps/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ async def test_analysis_detect_current_cloud_series_different_series(model):
can_upgrade_to="ussuri/stable",
charm="cinder",
channel="ussuri/stable",
config={"source": {"value": "distro"}},
config={"source": {"value": "cloud:bionic-ussuri"}},
machines=machines,
model=model,
origin="ch",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/steps/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ def test_get_post_upgrade_steps_ceph_mon(mock_get_ceph_mon_post_upgrade_steps, u
pre_upgrade_steps = cou_plan._get_post_upgrade_steps(analysis_result, args)

assert pre_upgrade_steps == mock_get_ceph_mon_post_upgrade_steps.return_value
mock_get_ceph_mon_post_upgrade_steps.assert_called_with(analysis_result.apps_data_plane)
mock_get_ceph_mon_post_upgrade_steps.assert_called_with(analysis_result.apps_control_plane)


def test_get_ceph_mon_post_upgrade_steps_zero(model):
Expand Down
Loading