Skip to content

Commit

Permalink
- fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcocenza committed Jan 24, 2024
1 parent 755d87f commit 646d3c8
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 467 deletions.
2 changes: 1 addition & 1 deletion cou/apps/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def pre_upgrade_plan(self, target: OpenStackRelease) -> list[PreUpgradeStep]:
return super().pre_upgrade_plan(target)


@AppFactory.register_application(["mysql-innodb-cluster"])
@AppFactory.register_application(["mysql_innodb_cluster"])
class MysqlInnodbClusterApplication(OpenStackAuxiliaryApplication):
"""Application for mysql-innodb-cluster charm."""

Expand Down
88 changes: 55 additions & 33 deletions tests/unit/apps/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
from tests.unit.apps.utils import add_steps


def test_auxiliary_app(status, config, model):
def test_auxiliary_app(status, config, model, apps_machines):
# version 3.8 on rabbitmq can be from ussuri to yoga. In that case it will be set as yoga.
expected_units = [
ApplicationUnit(
name="rabbitmq-server/0",
os_version=OpenStackRelease("yoga"),
workload_version="3.8",
machine="0/lxd/19",
machine=apps_machines["rmq"]["0/lxd/19"],
)
]

Expand All @@ -50,6 +50,7 @@ def test_auxiliary_app(status, config, model):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
assert app.channel == "3.8/stable"
assert app.is_valid_track(app.channel) is True
Expand All @@ -61,13 +62,13 @@ def test_auxiliary_app(status, config, model):
assert app.current_os_release == "yoga"


def test_auxiliary_app_cs(status, config, model):
def test_auxiliary_app_cs(status, config, model, apps_machines):
expected_units = [
ApplicationUnit(
name="rabbitmq-server/0",
os_version=OpenStackRelease("yoga"),
workload_version="3.8",
machine="0/lxd/19",
machine=apps_machines["rmq"]["0/lxd/19"],
)
]
rmq_status = status["rabbitmq_server"]
Expand All @@ -79,6 +80,7 @@ def test_auxiliary_app_cs(status, config, model):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
assert app.channel == "stable"
assert app.is_valid_track(app.channel) is True
Expand All @@ -89,14 +91,17 @@ def test_auxiliary_app_cs(status, config, model):
assert app.current_os_release == "yoga"


def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(status, config, model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(
status, config, model, apps_machines
):
target = OpenStackRelease("victoria")
app = RabbitMQServer(
"rabbitmq-server",
status["rabbitmq_server"],
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)

upgrade_plan = app.generate_upgrade_plan(target)
Expand Down Expand Up @@ -149,7 +154,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria_change_channel(status, config
assert upgrade_plan == expected_plan


def test_auxiliary_upgrade_plan_ussuri_to_victoria(status, config, model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria(status, config, model, apps_machines):
target = OpenStackRelease("victoria")
rmq_status = status["rabbitmq_server"]
# rabbitmq already on channel 3.9 on ussuri
Expand All @@ -160,6 +165,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria(status, config, model):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)

upgrade_plan = app.generate_upgrade_plan(target)
Expand Down Expand Up @@ -207,7 +213,9 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria(status, config, model):
assert upgrade_plan == expected_plan


def test_auxiliary_upgrade_plan_ussuri_to_victoria_ch_migration(status, config, model):
def test_auxiliary_upgrade_plan_ussuri_to_victoria_ch_migration(
status, config, model, apps_machines
):
target = OpenStackRelease("victoria")
rmq_status = status["rabbitmq_server"]
rmq_status.charm = "cs:amd64/focal/rabbitmq-server-638"
Expand All @@ -218,6 +226,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria_ch_migration(status, config,
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
upgrade_plan = app.generate_upgrade_plan(target)
expected_plan = ApplicationUpgradePlan(
Expand Down Expand Up @@ -268,7 +277,7 @@ def test_auxiliary_upgrade_plan_ussuri_to_victoria_ch_migration(status, config,
assert upgrade_plan == expected_plan


def test_auxiliary_upgrade_plan_unknown_track(status, config, model):
def test_auxiliary_upgrade_plan_unknown_track(status, config, model, apps_machines):
rmq_status = status["rabbitmq_server"]
# 2.0 is an unknown track
rmq_status.charm_channel = "2.0/stable"
Expand All @@ -279,21 +288,25 @@ def test_auxiliary_upgrade_plan_unknown_track(status, config, model):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)


def test_auxiliary_app_unknown_version_raise_ApplicationError(status, config, model):
def test_auxiliary_app_unknown_version_raise_ApplicationError(
status, config, model, apps_machines
):
with pytest.raises(ApplicationError):
RabbitMQServer(
"rabbitmq-server",
status["unknown_rabbitmq_server"],
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)


def test_auxiliary_raise_error_unknown_series(status, config, model):
def test_auxiliary_raise_error_unknown_series(status, config, model, apps_machines):
app_status = status["rabbitmq_server"]
app_status.series = "foo"
with pytest.raises(ApplicationError):
Expand All @@ -303,10 +316,11 @@ def test_auxiliary_raise_error_unknown_series(status, config, model):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)


def test_auxiliary_raise_error_os_not_on_lookup(status, config, model, mocker):
def test_auxiliary_raise_error_os_not_on_lookup(status, config, model, mocker, apps_machines):
# change OpenStack release to a version that is not on openstack_to_track_mapping.csv
mocker.patch(
"cou.apps.core.OpenStackApplication.current_os_release",
Expand All @@ -320,12 +334,13 @@ def test_auxiliary_raise_error_os_not_on_lookup(status, config, model, mocker):
config["auxiliary_ussuri"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
with pytest.raises(ApplicationError):
app.possible_current_channels


def test_auxiliary_raise_halt_upgrade(status, config, model):
def test_auxiliary_raise_halt_upgrade(status, config, model, apps_machines):
target = OpenStackRelease("victoria")
# source is already configured to wallaby, so the plan halt with target victoria
app = RabbitMQServer(
Expand All @@ -334,12 +349,13 @@ def test_auxiliary_raise_halt_upgrade(status, config, model):
config["auxiliary_wallaby"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
with pytest.raises(HaltUpgradePlanGeneration):
app.generate_upgrade_plan(target)


def test_auxiliary_no_suitable_channel(status, config, model):
def test_auxiliary_no_suitable_channel(status, config, model, apps_machines):
# OPENSTACK_TO_TRACK_MAPPING can't find a track for rabbitmq, focal, zed.
target = OpenStackRelease("zed")
app_status = status["rabbitmq_server"]
Expand All @@ -350,19 +366,21 @@ def test_auxiliary_no_suitable_channel(status, config, model):
config["auxiliary_wallaby"],
model,
"rabbitmq-server",
apps_machines["rmq"],
)
with pytest.raises(ApplicationError):
app.target_channel(target)


def test_ceph_mon_app(status, config, model):
def test_ceph_mon_app(status, config, model, apps_machines):
"""Test the correctness of instantiating CephMonApplication."""
app = CephMonApplication(
"ceph-mon",
status["ceph-mon_xena"],
status["ceph_mon_pacific"],
config["auxiliary_xena"],
model,
"ceph-mon",
apps_machines["ceph-mon"],
)
assert app.channel == "pacific/stable"
assert app.os_origin == "cloud:focal-xena"
Expand All @@ -371,27 +389,24 @@ def test_ceph_mon_app(status, config, model):
name="ceph-mon/0",
os_version=OpenStackRelease("xena"),
workload_version="16.2.0",
machine="7",
machine=apps_machines["ceph-mon"]["6"],
)
]
assert app.apt_source_codename == "xena"
assert app.channel_codename == "xena"
assert app.is_subordinate is False


def test_ceph_mon_upgrade_plan_xena_to_yoga(
status,
config,
model,
):
def test_ceph_mon_upgrade_plan_xena_to_yoga(status, config, model, apps_machines):
"""Test when ceph version changes between os releases."""
target = OpenStackRelease("yoga")
app = CephMonApplication(
"ceph-mon",
status["ceph-mon_xena"],
status["ceph_mon_pacific"],
config["auxiliary_xena"],
model,
"ceph-mon",
apps_machines["ceph-mon"],
)

upgrade_plan = app.generate_upgrade_plan(target)
Expand Down Expand Up @@ -452,15 +467,17 @@ def test_ceph_mon_upgrade_plan_ussuri_to_victoria(
status,
config,
model,
apps_machines,
):
"""Test when ceph version remains the same between os releases."""
target = OpenStackRelease("victoria")
app = CephMonApplication(
"ceph-mon",
status["ceph-mon_ussuri"],
status["ceph_mon_octopus"],
config["auxiliary_ussuri"],
model,
"ceph-mon",
apps_machines["ceph-mon"],
)
upgrade_plan = app.generate_upgrade_plan(target)

Expand Down Expand Up @@ -511,13 +528,14 @@ def test_ceph_mon_upgrade_plan_ussuri_to_victoria(
assert upgrade_plan == expected_plan


def test_ovn_principal(status, config, model):
def test_ovn_principal(status, config, model, apps_machines):
app = OvnPrincipalApplication(
"ovn-central",
status["ovn_central_ussuri_22"],
status["ovn_central_22"],
config["auxiliary_ussuri"],
model,
"ovn-central",
apps_machines["ovn-central"],
)
assert app.channel == "22.03/stable"
assert app.os_origin == "distro"
Expand All @@ -527,7 +545,7 @@ def test_ovn_principal(status, config, model):
assert app.is_subordinate is False


def test_ovn_workload_ver_lower_than_22_principal(status, config, model):
def test_ovn_workload_ver_lower_than_22_principal(status, config, model, apps_machines):
target = OpenStackRelease("victoria")

exp_error_msg_ovn_upgrade = (
Expand All @@ -539,19 +557,20 @@ def test_ovn_workload_ver_lower_than_22_principal(status, config, model):

app_ovn_central = OvnPrincipalApplication(
"ovn-central",
status["ovn_central_ussuri_20"],
status["ovn_central_20"],
config["auxiliary_ussuri"],
model,
"ovn-central",
apps_machines["ovn-central"],
)

with pytest.raises(ApplicationError, match=exp_error_msg_ovn_upgrade):
app_ovn_central.generate_upgrade_plan(target)


@pytest.mark.parametrize("channel", ["55.7", "19.03"])
def test_ovn_no_compatible_os_release(status, config, model, channel):
ovn_central_status = status["ovn_central_ussuri_22"]
def test_ovn_no_compatible_os_release(status, config, model, channel, apps_machines):
ovn_central_status = status["ovn_central_22"]
ovn_central_status.charm_channel = channel
with pytest.raises(ApplicationError):
OvnPrincipalApplication(
Expand All @@ -560,17 +579,19 @@ def test_ovn_no_compatible_os_release(status, config, model, channel):
config["auxiliary_ussuri"],
model,
"ovn-central",
apps_machines["ovn-central"],
)


def test_ovn_principal_upgrade_plan(status, config, model):
def test_ovn_principal_upgrade_plan(status, config, model, apps_machines):
target = OpenStackRelease("victoria")
app = OvnPrincipalApplication(
"ovn-central",
status["ovn_central_ussuri_22"],
status["ovn_central_22"],
config["auxiliary_ussuri"],
model,
"ovn-central",
apps_machines["ovn-central"],
)

upgrade_plan = app.generate_upgrade_plan(target)
Expand Down Expand Up @@ -618,15 +639,16 @@ def test_ovn_principal_upgrade_plan(status, config, model):
assert upgrade_plan == expected_plan


def test_mysql_innodb_cluster_upgrade(status, config, model):
def test_mysql_innodb_cluster_upgrade(status, config, model, apps_machines):
target = OpenStackRelease("victoria")
# source is already configured to wallaby, so the plan halt with target victoria
app = MysqlInnodbClusterApplication(
"mysql-innodb-cluster",
status["mysql-innodb-cluster"],
status["mysql_innodb_cluster"],
config["auxiliary_ussuri"],
model,
"mysql-innodb-cluster",
apps_machines["mysql-innodb-cluster"],
)
upgrade_plan = app.generate_upgrade_plan(target)
expected_plan = ApplicationUpgradePlan(
Expand Down
Loading

0 comments on commit 646d3c8

Please sign in to comment.