Skip to content

Commit

Permalink
Merge branch 'main' into add-mocked-cloud-plan
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcocenza committed Apr 24, 2024
2 parents 7877a3c + 398678d commit a12216f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
9 changes: 9 additions & 0 deletions cou/apps/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def channel_codename(self) -> OpenStackRelease:

track: str = self._get_track_from_channel(self.channel)
compatible_os_releases = TRACK_TO_OPENSTACK_MAPPING[(self.charm, self.series, track)]

if not compatible_os_releases:
raise ApplicationError(
f"Channel: {self.channel} for charm '{self.charm}' on series '{self.series}' is "
f"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."
)

return max(compatible_os_releases)

def generate_upgrade_plan(
Expand Down
13 changes: 10 additions & 3 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Base application class."""
from __future__ import annotations

import asyncio
import logging
import os
from collections import defaultdict
Expand Down Expand Up @@ -350,6 +351,11 @@ async def _verify_workload_upgrade(self, target: OpenStackRelease, units: list[U
:type units: list[Unit]
:raises ApplicationError: When the workload version of the charm doesn't upgrade.
"""
# NOTE (gabrielcocenza) force the update-status hook on units
# to update the workload version
tasks = [self.model.run_on_unit(unit.name, "hooks/update-status") for unit in units]
await asyncio.gather(*tasks)

status = await self.model.get_status()
app_status = status.applications.get(self.name)
units_not_upgraded = []
Expand All @@ -363,7 +369,9 @@ async def _verify_workload_upgrade(self, target: OpenStackRelease, units: list[U

if units_not_upgraded:
raise ApplicationError(
f"Cannot upgrade units '{', '.join(units_not_upgraded)}' to {target}."
f"Unit(s) '{', '.join(units_not_upgraded)}' did not complete the upgrade to "
f"{target}. Some local processes may still be executing; you may try re-running "
"COU in a few minutes."
)

def upgrade_plan_sanity_checks(
Expand Down Expand Up @@ -789,8 +797,7 @@ def _check_channel(self) -> None:

raise ApplicationError(
f"Channel: {self.channel} for charm '{self.charm}' on series "
f"'{self.series}' is currently not supported in this tool. Please take a look at the "
"documentation: "
f"'{self.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."
)
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/apps/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ def test_auxiliary_upgrade_plan_unknown_track(model):
"""Test auxiliary upgrade plan with unknown track."""
channel = "2.0/stable"
exp_msg = (
f"Channel: {channel} for charm 'rabbitmq-server' on series 'focal' is currently "
"not supported in this tool. Please take a look at the documentation: "
f"Channel: {channel} for charm 'rabbitmq-server' on series 'focal' 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."
)
Expand Down Expand Up @@ -398,8 +398,8 @@ def test_auxiliary_raise_error_unknown_series(model):
series = "foo"
channel = "3.8/stable"
exp_msg = (
f"Channel: {channel} for charm 'rabbitmq-server' on series '{series}' is currently "
"not supported in this tool. Please take a look at the documentation: "
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."
)
Expand Down Expand Up @@ -436,8 +436,8 @@ def test_auxiliary_raise_error_os_not_on_lookup(current_os_release, model):
"""
current_os_release.return_value = OpenStackRelease("diablo")
exp_error_msg = (
"Channel: 3.8/stable for charm 'rabbitmq-server' on series 'focal' is currently not "
"supported in this tool. Please take a look at the documentation: "
"Channel: 3.8/stable for charm 'rabbitmq-server' on series 'focal' 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."
)
Expand Down Expand Up @@ -895,8 +895,8 @@ def test_ovn_no_compatible_os_release(channel, model):
charm = "ovn-central"
machines = {"0": MagicMock(spec_set=Machine)}
exp_msg = (
f"Channel: {channel} for charm '{charm}' on series 'focal' is currently "
"not supported in this tool. Please take a look at the documentation: "
f"Channel: {channel} for charm '{charm}' on series 'focal' 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."
)
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/apps/test_auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,33 @@ def test_auxiliary_subordinate_latest_stable(model):
)
plan = app.generate_upgrade_plan(target, force=False)
assert str(plan) == exp_plan


def test_auxiliary_subordinate_channel_codename_raise(model):
app = AuxiliarySubordinateApplication(
name="ceph-dashboard",
can_upgrade_to="",
charm="ceph-dashboard",
channel="luminous/stable",
config={},
machines={"0": MagicMock(spec_set=Machine)},
model=model,
origin="ch",
series="focal",
subordinate_to=["nova-compute"],
units={},
workload_version="",
)

exp_msg = (
"Channel: luminous/stable for charm 'ceph-dashboard' on series 'focal' 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."
)

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

with pytest.raises(ApplicationError, match=exp_msg):
app.current_os_release
4 changes: 2 additions & 2 deletions tests/unit/apps/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def test_check_channel_error(_):
channel = "stable"
series = "focal"
exp_error_msg = (
f"Channel: {channel} for charm '{name}' on series '{series}' is currently not supported "
"in this tool. Please take a look at the documentation: "
f"Channel: {channel} for charm '{name}' 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."
)
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/apps/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ async def test_application_verify_workload_upgrade(model):
async def test_application_verify_workload_upgrade_fail(model):
"""Test Kyestone application check unsuccessful upgrade."""
target = OpenStackRelease("victoria")
exp_msg = "Cannot upgrade units 'keystone/0' to victoria."
exp_msg = (
r"Unit\(s\) 'keystone/0' did not complete the upgrade to victoria. Some local processes "
r"may still be executing; you may try re-running COU in a few minutes."
)
machines = {"0": MagicMock(spec_set=Machine)}
app = Keystone(
name="keystone",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/apps/test_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def test_channel_setter_invalid(model, channel):
"""Test unsuccessful validation of channel upgrade plan for SubordinateApplication."""
machines = {"0": MagicMock(spec_set=Machine)}
exp_error_msg = (
f"Channel: {channel} for charm 'keystone-ldap' on series 'focal' is currently not "
"supported in this tool. Please take a look at the documentation: "
f"Channel: {channel} for charm 'keystone-ldap' on series 'focal' 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."
)
Expand Down

0 comments on commit a12216f

Please sign in to comment.