Skip to content

Commit

Permalink
Merge branch 'main' into channel-downgrade-BSENG-2350
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcocenza committed May 6, 2024
2 parents 2e9d313 + 8d93d0d commit 6fd38c3
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 136 deletions.
11 changes: 9 additions & 2 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __str__(self) -> str:
"machines": {
machine.machine_id: {
"id": machine.machine_id,
"apps": machine.apps,
"apps_charms": machine.apps_charms,
"az": machine.az,
}
for machine in self.machines.values()
Expand Down Expand Up @@ -888,7 +888,14 @@ def _check_mismatched_versions(self, units: Optional[list[Unit]]) -> None:
:raises MismatchedOpenStackVersions: When the units of the app are running
different OpenStack versions.
"""
if units:
# NOTE (gabrielcocenza) nova-compute is upgraded using paused-single-unit,
# so it's possible to have mismatched version in applications units that are
# nova-compute or colocated with it.
if any(
"nova-compute" in app_charm
for machine in self.machines.values()
for app_charm in machine.apps_charms
):
return

o7k_versions = self.o7k_release_units
Expand Down
22 changes: 16 additions & 6 deletions cou/utils/juju_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Machine:
"""Representation of a juju machine."""

machine_id: str
apps: tuple[str]
apps_charms: tuple[tuple[str, str], ...]
az: Optional[str] = None # simple deployments may not have azs


Expand Down Expand Up @@ -285,16 +285,26 @@ async def _get_machines(self) -> dict[str, Machine]:
return {
machine.id: Machine(
machine_id=machine.id,
apps=tuple(
unit.application
for unit in self._model.units.values()
if unit.machine.id == machine.id
),
apps_charms=self._get_machine_apps_and_charms(machine.id),
az=machine.hardware_characteristics.get("availability-zone"),
)
for machine in model.machines.values()
}

def _get_machine_apps_and_charms(self, machine_id: int) -> tuple[tuple[str, str], ...]:
"""Get machine apps amd charm names.
:param machine_id: Machine id.
:type machine_id: int
:return: Tuple of tuple contains app name and charm name.
:rtype: tuple[tuple[str, str], ...]
"""
return tuple(
(str(unit.application), str(self._model.applications[unit.application].charm_name))
for unit in self._model.units.values()
if unit.machine.id == machine_id
)

async def _get_model(self) -> JujuModel:
"""Get juju.model.Model and make sure that it is connected.
Expand Down
60 changes: 26 additions & 34 deletions tests/unit/apps/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
UpgradeStep,
)
from cou.utils import app_utils
from cou.utils.juju_utils import Machine, Unit
from cou.utils.juju_utils import Unit
from cou.utils.openstack import OpenStackRelease
from tests.unit.utils import assert_steps, dedent_plan, generate_cou_machine

Expand All @@ -45,7 +45,7 @@ def test_auxiliary_app(model):
The version 3.8 on rabbitmq can be from ussuri to yoga. In that case it will be
set as yoga.
"""
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="",
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_auxiliary_app(model):

def test_auxiliary_app_cs(model):
"""Test auxiliary application from charm store."""
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="",
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_auxiliary_app_cs(model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(model):
"""Test auxiliary upgrade plan from Ussuri to Victoria with change of channel."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="3.9/stable",
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria(model):
"""Test auxiliary upgrade plan from Ussuri to Victoria."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="3.9/stable",
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria(model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria_ch_migration(model):
"""Test auxiliary upgrade plan from Ussuri to Victoria with migration to charmhub."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="cs:rabbitmq-server",
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_auxiliary_upgrade_plan_unknown_track(model):
"https://docs.openstack.org/charm-guide/latest/project/charm-delivery.html "
"to see if you are using the right track."
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="3.9/stable",
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_auxiliary_app_unknown_version_raise_ApplicationError(model):
charm = "rabbitmq-server"
exp_msg = f"'{charm}' with workload version {version} has no compatible OpenStack release."

machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
unit = Unit(name=f"{charm}/0", workload_version=version, machine=machines["0"])
app = RabbitMQServer(
name=charm,
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_auxiliary_raise_error_unknown_series(model):
"https://docs.openstack.org/charm-guide/latest/project/charm-delivery.html "
"to see if you are using the right track."
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="3.9/stable",
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_auxiliary_raise_error_o7k_not_on_lookup(o7k_release, model):
"https://docs.openstack.org/charm-guide/latest/project/charm-delivery.html to see if you "
"are using the right track."
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name="rabbitmq-server",
can_upgrade_to="",
Expand Down Expand Up @@ -473,7 +473,7 @@ def test_auxiliary_raise_halt_upgrade(model):
f"Application '{charm}' already configured for release equal to or greater than {target}. "
"Ignoring."
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name=charm,
can_upgrade_to="",
Expand Down Expand Up @@ -507,11 +507,7 @@ def test_auxiliary_no_origin_setting_raise_halt_upgrade(model):
f"Application '{charm}' already configured for release equal to or greater than {target}. "
"Ignoring."
)
machines = {
"0": MagicMock(spec_set=Machine),
"1": MagicMock(spec_set=Machine),
"2": MagicMock(spec_set=Machine),
}
machines = {f"{i}": generate_cou_machine(f"{i}", f"az-{i}") for i in range(3)}
app = AuxiliaryApplication(
name=charm,
# no channel to refresh
Expand Down Expand Up @@ -564,7 +560,7 @@ def test_auxiliary_no_suitable_channel(model):
"Please take a look at the documentation: "
"https://docs.openstack.org/charm-guide/latest/project/charm-delivery.html"
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = RabbitMQServer(
name=charm,
can_upgrade_to="",
Expand Down Expand Up @@ -593,7 +589,7 @@ def test_auxiliary_no_suitable_channel(model):
def test_ceph_mon_app(model):
"""Test the correctness of instantiating CephMon."""
charm = "ceph-mon"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = CephMon(
name=charm,
can_upgrade_to="",
Expand Down Expand Up @@ -627,7 +623,7 @@ def test_ceph_mon_upgrade_plan_xena_to_yoga(model):
"""Test when ceph version changes between os releases."""
target = OpenStackRelease("yoga")
charm = "ceph-mon"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = CephMon(
name=charm,
can_upgrade_to="quincy/stable",
Expand Down Expand Up @@ -712,7 +708,7 @@ def test_ceph_mon_upgrade_plan_ussuri_to_victoria(model):
"""Test when ceph version remains the same between os releases."""
target = OpenStackRelease("victoria")
charm = "ceph-mon"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = CephMon(
name=charm,
can_upgrade_to="quincy/stable",
Expand Down Expand Up @@ -789,7 +785,7 @@ def test_ceph_mon_upgrade_plan_ussuri_to_victoria(model):
def test_ovn_principal(model):
"""Test the correctness of instantiating OVNPrincipal."""
charm = "ovn-central"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name=charm,
can_upgrade_to="22.06/stable",
Expand Down Expand Up @@ -828,7 +824,7 @@ def test_ovn_workload_ver_lower_than_22_principal(model):
"https://docs.openstack.org/charm-guide/latest/project/procedures/"
"ovn-upgrade-2203.html"
)
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name=charm,
can_upgrade_to="22.03/stable",
Expand Down Expand Up @@ -859,7 +855,7 @@ def test_ovn_version_pinning_principal(model):
target = OpenStackRelease("victoria")
charm = "ovn-dedicated-chassis"
exp_msg = f"Cannot upgrade '{charm}'. 'enable-version-pinning' must be set to 'false'."
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name=charm,
can_upgrade_to="22.03/stable",
Expand Down Expand Up @@ -889,7 +885,7 @@ def test_ovn_version_pinning_principal(model):
def test_ovn_no_compatible_o7k_release(channel, model):
"""Test the OVNPrincipal with not compatible os release."""
charm = "ovn-central"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
exp_msg = (
f"Channel: {channel} for charm '{charm}' on series 'focal' is not supported by COU. "
"Please take a look at the documentation: "
Expand Down Expand Up @@ -933,7 +929,7 @@ def test_ovn_no_compatible_o7k_release(channel, model):
],
)
def test_ovn_check_version_pinning_version_pinning_config_False(app, config, model):
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name=app,
can_upgrade_to="",
Expand All @@ -958,7 +954,7 @@ def test_ovn_check_version_pinning_version_pinning_config_False(app, config, mod


def test_ovn_check_version_pinning_version_pinning_config_True(model):
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name="ovn-dedicated-chassis",
can_upgrade_to="",
Expand Down Expand Up @@ -988,7 +984,7 @@ def test_ovn_principal_upgrade_plan(model):
"""Test generating plan for OVNPrincipal."""
target = OpenStackRelease("victoria")
charm = "ovn-dedicated-chassis"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNPrincipal(
name=charm,
can_upgrade_to="22.06/stable",
Expand Down Expand Up @@ -1064,7 +1060,7 @@ def test_mysql_innodb_cluster_upgrade(model):
"""Test generating plan for MysqlInnodbCluster."""
target = OpenStackRelease("victoria")
charm = "mysql-innodb-cluster"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = MysqlInnodbCluster(
name=charm,
can_upgrade_to="9.0",
Expand Down Expand Up @@ -1210,11 +1206,7 @@ def test_auxiliary_upgrade_by_unit(mock_super, model):
"""Test generating plan with units doesn't create unit Upgrade steps."""
target = OpenStackRelease("victoria")
charm = "my-app"
machines = {
"0": MagicMock(spec_set=Machine),
"1": MagicMock(spec_set=Machine),
"2": MagicMock(spec_set=Machine),
}
machines = {f"{i}": generate_cou_machine(f"{i}", f"az-{i}") for i in range(3)}
app = AuxiliaryApplication(
name=charm,
can_upgrade_to="1.7/stable",
Expand Down Expand Up @@ -1449,7 +1441,7 @@ def test_auxiliary_wrong_channel(model):
"""Test when an auxiliary charm is with a channel that doesn't match the workload version."""
target = OpenStackRelease("victoria")
charm = "ceph-mon"
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = CephMon(
name=charm,
can_upgrade_to="",
Expand Down
Loading

0 comments on commit 6fd38c3

Please sign in to comment.