Skip to content

Commit

Permalink
Don't check for mismatched versions if colocated with nova-compute
Browse files Browse the repository at this point in the history
- nova-compute is expected to upgrade unit by unit. So it's
  expected to have different versions among nova-compute units or
  apps colocated with it.
- _check_mismatched_versions now check if a machine of an app is
  colocated with nova-compute.

Closes: canonical#395
  • Loading branch information
gabrielcocenza committed May 1, 2024
1 parent 1d25afc commit 21336ec
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 87 deletions.
5 changes: 4 additions & 1 deletion cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,10 @@ 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 machine.apps for machine in self.machines.values()):
return

os_versions = self.os_release_units
Expand Down
44 changes: 22 additions & 22 deletions tests/unit/apps/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="3.9/stable",
Expand Down Expand Up @@ -340,7 +340,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 @@ -372,7 +372,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 @@ -403,7 +403,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 @@ -441,7 +441,7 @@ def test_auxiliary_raise_error_os_not_on_lookup(current_os_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 @@ -478,7 +478,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 @@ -569,7 +569,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 @@ -598,7 +598,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 @@ -632,7 +632,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 @@ -716,7 +716,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 @@ -793,7 +793,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 @@ -832,7 +832,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 @@ -863,7 +863,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 @@ -893,7 +893,7 @@ def test_ovn_version_pinning_principal(model):
def test_ovn_no_compatible_os_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 @@ -937,7 +937,7 @@ def test_ovn_no_compatible_os_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 @@ -962,7 +962,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 @@ -992,7 +992,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 @@ -1068,7 +1068,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
27 changes: 12 additions & 15 deletions tests/unit/apps/test_auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Tests of the Auxiliary Subordinate application class."""

from unittest.mock import MagicMock

import pytest

from cou.apps.auxiliary_subordinate import (
Expand All @@ -23,14 +21,13 @@
)
from cou.exceptions import ApplicationError, HaltUpgradePlanGeneration
from cou.steps import ApplicationUpgradePlan, PreUpgradeStep, UpgradeStep
from cou.utils.juju_utils import Machine
from cou.utils.openstack import OpenStackRelease
from tests.unit.utils import assert_steps, dedent_plan
from tests.unit.utils import assert_steps, dedent_plan, generate_cou_machine


def test_auxiliary_subordinate(model):
"""Test auxiliary subordinate application."""
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = AuxiliarySubordinateApplication(
name="keystone-mysql-router",
can_upgrade_to="",
Expand Down Expand Up @@ -58,7 +55,7 @@ def test_auxiliary_subordinate(model):
def test_auxiliary_subordinate_upgrade_plan_to_victoria(model):
"""Test auxiliary subordinate application upgrade plan to victoria."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = AuxiliarySubordinateApplication(
name="keystone-mysql-router",
can_upgrade_to="8.0/stable",
Expand Down Expand Up @@ -90,7 +87,7 @@ def test_auxiliary_subordinate_upgrade_plan_to_victoria(model):

def test_ovn_subordinate(model):
"""Test the correctness of instantiating OVNSubordinate."""
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNSubordinate(
name="ovn-chassis",
can_upgrade_to="22.03/stable",
Expand All @@ -117,7 +114,7 @@ def test_ovn_subordinate(model):
def test_ovn_workload_ver_lower_than_22_subordinate(model):
"""Test the OVNSubordinate with lower version than 22."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
exp_msg = (
"OVN versions lower than 22.03 are not supported. It's necessary to upgrade "
"OVN to 22.03 before upgrading the cloud. Follow the instructions at: "
Expand Down Expand Up @@ -147,7 +144,7 @@ def test_ovn_version_pinning_subordinate(model):
"""Test the OVNSubordinate when enable-version-pinning is set to True."""
charm = "ovn-chassis"
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
exp_msg = f"Cannot upgrade '{charm}'. 'enable-version-pinning' must be set to 'false'."
app = OVNSubordinate(
name=charm,
Expand All @@ -171,7 +168,7 @@ def test_ovn_version_pinning_subordinate(model):
def test_ovn_subordinate_upgrade_plan(model):
"""Test generating plan for OVNSubordinate."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNSubordinate(
name="ovn-chassis",
can_upgrade_to="22.03/stable",
Expand Down Expand Up @@ -215,7 +212,7 @@ def test_ovn_subordinate_upgrade_plan_cant_upgrade_charm(model):
"victoria. Ignoring."
)
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = OVNSubordinate(
name="ovn-chassis",
can_upgrade_to="",
Expand All @@ -238,7 +235,7 @@ def test_ovn_subordinate_upgrade_plan_cant_upgrade_charm(model):
def test_ceph_dashboard_upgrade_plan_ussuri_to_victoria(model):
"""Test when ceph version remains the same between os releases."""
target = OpenStackRelease("victoria")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = AuxiliarySubordinateApplication(
name="ceph-dashboard",
can_upgrade_to="octopus/stable",
Expand Down Expand Up @@ -275,7 +272,7 @@ def test_ceph_dashboard_upgrade_plan_ussuri_to_victoria(model):
def test_ceph_dashboard_upgrade_plan_xena_to_yoga(model):
"""Test when ceph version changes between os releases."""
target = OpenStackRelease("yoga")
machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}
app = AuxiliarySubordinateApplication(
name="ceph-dashboard",
can_upgrade_to="pacific/stable",
Expand Down Expand Up @@ -326,7 +323,7 @@ def test_auxiliary_subordinate_latest_stable(model):
"""
)

machines = {"0": MagicMock(spec_set=Machine)}
machines = {"0": generate_cou_machine("0", "az-0")}

app = AuxiliarySubordinateApplication(
name="keystone-hacluster",
Expand All @@ -353,7 +350,7 @@ def test_auxiliary_subordinate_channel_codename_raise(model):
charm="ceph-dashboard",
channel="luminous/stable",
config={},
machines={"0": MagicMock(spec_set=Machine)},
machines={"0": generate_cou_machine("0", "az-0")},
model=model,
origin="ch",
series="focal",
Expand Down
Loading

0 comments on commit 21336ec

Please sign in to comment.