Skip to content

Commit

Permalink
added multiple_channels flag to support corner case when rabbitmq
Browse files Browse the repository at this point in the history
or hacluster that supports more than one channel for an Openstack
release.
  • Loading branch information
gabrielcocenza committed May 7, 2024
1 parent 2d7888a commit fde60e7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cou/apps/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class RabbitMQServer(AuxiliaryApplication):

wait_timeout = LONG_IDLE_TIMEOUT
wait_for_model = True
# rabbitmq-server can use channels 3.8 or 3.9 on focal.
# COU changes to 3.9 if the channel is set to 3.8
multiple_channels = True


@AppFactory.register_application(["ceph-mon"])
Expand Down
12 changes: 10 additions & 2 deletions cou/apps/auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
from cou.apps.auxiliary import OVN, AuxiliaryApplication
from cou.apps.factory import AppFactory
from cou.apps.subordinate import SubordinateApplication
from cou.utils.openstack import AUXILIARY_SUBORDINATES


@AppFactory.register_application(AUXILIARY_SUBORDINATES)
@AppFactory.register_application(["mysql-router", "ceph-dashboard"])
class AuxiliarySubordinateApplication(SubordinateApplication, AuxiliaryApplication):
"""Auxiliary subordinate application class."""

Expand All @@ -33,3 +32,12 @@ def _check_ovn_support(self) -> None:
:raises ApplicationError: When workload version is lower than 22.03.0.
"""
OVNSubordinate._validate_ovn_support(self.workload_version)


@AppFactory.register_application(["hacluster"])
class HACluster(AuxiliarySubordinateApplication):
"""HACluster application class."""

# hacluster can use channels 2.0.3 or 2.4 on focal.
# COU changes to 2.4 if the channel is set to 2.0.3
multiple_channels = True
5 changes: 4 additions & 1 deletion cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class OpenStackApplication(Application):
# OpenStack apps rely on the workload version of the packages to evaluate current OpenStack
# release
based_on_channel = False
# multiple_channels set to False means that the charm supports only one channel for
# an OpenStack release
multiple_channels = False

def __hash__(self) -> int:
"""Hash magic method for Application.
Expand Down Expand Up @@ -663,7 +666,7 @@ def _get_upgrade_charm_step(self, target: OpenStackRelease) -> UpgradeStep:
# Normally, prior the upgrade the channel is equal to the application release.
# However, when colocated with other app, the channel can be in a release lesser than the
# workload version of the application.
if self.channel_o7k_release <= self.o7k_release:
if self.channel_o7k_release <= self.o7k_release or self.multiple_channels:
return UpgradeStep(
description=f"Upgrade '{self.name}' from '{channel}' to the new channel: "
f"'{self.target_channel(target)}'",
Expand Down
1 change: 1 addition & 0 deletions cou/steps/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
from cou.apps.auxiliary_subordinate import ( # noqa: F401
AuxiliarySubordinateApplication,
HACluster,
OVNSubordinate,
)
from cou.apps.base import OpenStackApplication
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/apps/test_auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from cou.apps.auxiliary_subordinate import (
AuxiliarySubordinateApplication,
HACluster,
OVNSubordinate,
)
from cou.exceptions import ApplicationError, HaltUpgradePlanGeneration
Expand Down Expand Up @@ -373,3 +374,33 @@ def test_auxiliary_subordinate_channel_o7k_release_raise(model):

with pytest.raises(ApplicationError, match=exp_msg):
app.o7k_release


def test_hacluster_change_channel(model):
"""Test that HACluster changes the channel to 2.4 when 2.0.3 is set."""
target = OpenStackRelease("victoria")
app = HACluster(
name="keystone-hacluster",
can_upgrade_to="ch:hacluster",
charm="hacluster",
channel="2.0.3/stable",
config={},
machines={"0": generate_cou_machine("0", "az-0")},
model=model,
origin="ch",
series="focal",
subordinate_to=["keystone"],
units={},
workload_version="2.0.3",
)

exp_plan = dedent_plan(
"""\
Upgrade plan for 'keystone-hacluster' to 'victoria'
Refresh 'keystone-hacluster' to the latest revision of '2.0.3/stable'
Upgrade 'keystone-hacluster' from '2.0.3/stable' to the new channel: '2.4/stable'
"""
)

plan = app.generate_upgrade_plan(target, force=False)
assert str(plan) == exp_plan

0 comments on commit fde60e7

Please sign in to comment.