From f06f766f780a053dbcc7a9ba715e213892381913 Mon Sep 17 00:00:00 2001 From: Tianqi Date: Thu, 28 Mar 2024 16:03:58 -0400 Subject: [PATCH] Add Swift application class Add a new Swift application class for swift-proxy and swift-storage. This class will also raise ApplicationNotSupported exception when generating a plan. Also make sure both swift-proxy and swift-storage are considered as data-plane applications. --- cou/apps/core.py | 27 +++++++++++++++++++++++ cou/exceptions.py | 4 ++++ cou/steps/plan.py | 2 +- cou/utils/openstack.py | 2 +- tests/unit/apps/test_core.py | 42 ++++++++++++++++++++++++++++++++++-- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/cou/apps/core.py b/cou/apps/core.py index d852cb27..d37473f0 100644 --- a/cou/apps/core.py +++ b/cou/apps/core.py @@ -18,6 +18,7 @@ from cou.apps.base import LONG_IDLE_TIMEOUT, OpenStackApplication from cou.apps.factory import AppFactory +from cou.exceptions import ApplicationNotSupported from cou.steps import UnitUpgradeStep, UpgradeStep from cou.utils.juju_utils import Unit from cou.utils.nova_compute import verify_empty_hypervisor @@ -145,3 +146,29 @@ def _get_disable_scheduler_step(self, unit: Unit) -> UnitUpgradeStep: unit_name=unit.name, action_name="disable", raise_on_failure=True ), ) + + +@AppFactory.register_application(["swift-proxy", "swift-storage"]) +class Swift(OpenStackApplication): + """Swift application. + + Swift applications, including swift-proxy and swift-storage, are considered as + valid OpenStack components, but not currently supported by COU for upgrade. + """ + + def upgrade_plan_sanity_checks( + self, target: OpenStackRelease, units: Optional[list[Unit]] + ) -> None: + """Run sanity checks before generating upgrade plan. + + :param target: OpenStack release as target to upgrade. + :type target: OpenStackRelease + :param units: Units to generate upgrade plan, defaults to None + :type units: Optional[list[Unit]], optional + :raises ApplicationNotSupported: When application is known but not currently + supported by COU. + """ + raise ApplicationNotSupported( + f"'{self.name}' application is not currently supported by COU. Please manually " + "upgrade it at the end of data-plane upgrades." + ) diff --git a/cou/exceptions.py b/cou/exceptions.py index a44faebe..2e3e0ff6 100644 --- a/cou/exceptions.py +++ b/cou/exceptions.py @@ -147,3 +147,7 @@ def __init__(self, message: str, exit_code: int) -> None: """ self.exit_code = exit_code super().__init__(message) + + +class ApplicationNotSupported(COUException): + """COU exception when the application is known but not supported by COU.""" diff --git a/cou/steps/plan.py b/cou/steps/plan.py index 72420b06..57aa4cfc 100644 --- a/cou/steps/plan.py +++ b/cou/steps/plan.py @@ -32,7 +32,7 @@ ) from cou.apps.base import OpenStackApplication from cou.apps.channel_based import ChannelBasedApplication # noqa: F401 -from cou.apps.core import Keystone, Octavia # noqa: F401 +from cou.apps.core import Keystone, Octavia, Swift # noqa: F401 from cou.apps.subordinate import SubordinateApplication, SubordinateBase # noqa: F401 from cou.commands import CONTROL_PLANE, DATA_PLANE, HYPERVISORS, CLIargs from cou.exceptions import ( diff --git a/cou/utils/openstack.py b/cou/utils/openstack.py index 4290f708..f1c53d0a 100644 --- a/cou/utils/openstack.py +++ b/cou/utils/openstack.py @@ -44,7 +44,7 @@ "mysql": ["mysql-innodb-cluster", "mysql-router"], } -DATA_PLANE_CHARMS = ["nova-compute", "ceph-osd"] +DATA_PLANE_CHARMS = ["nova-compute", "ceph-osd", "swift-proxy", "swift-storage"] # https://docs.openstack.org/charm-guide/latest/admin/upgrades/openstack.html#list-the-upgrade-order UPGRADE_ORDER = [ diff --git a/tests/unit/apps/test_core.py b/tests/unit/apps/test_core.py index a5533afe..0408ab95 100644 --- a/tests/unit/apps/test_core.py +++ b/tests/unit/apps/test_core.py @@ -17,8 +17,12 @@ from juju.client._definitions import ApplicationStatus, UnitStatus from cou.apps.base import OpenStackApplication -from cou.apps.core import Keystone, NovaCompute -from cou.exceptions import ApplicationError, HaltUpgradePlanGeneration +from cou.apps.core import Keystone, NovaCompute, Swift +from cou.exceptions import ( + ApplicationError, + ApplicationNotSupported, + HaltUpgradePlanGeneration, +) from cou.steps import ( ApplicationUpgradePlan, PostUpgradeStep, @@ -1032,3 +1036,37 @@ def test_cinder_upgrade_plan_single_unit(model): plan = cinder.generate_upgrade_plan(target, False, [units["cinder/0"]]) assert str(plan) == exp_plan + + +def test_swift_application_not_supported(model): + """Test Swift application raising ApplicationNotSupported error.""" + target = OpenStackRelease("victoria") + machines = {"0": MagicMock(spec_set=Machine)} + app = Swift( + name="swift-proxy", + can_upgrade_to="ussuri/stable", + charm="swift-proxy", + channel="ussuri/stable", + config={}, + machines=machines, + model=model, + origin="ch", + series="focal", + subordinate_to=[], + units={ + "swift-proxy/0": Unit( + name="swift-proxy/0", + workload_version="2.25.0", + machine=machines["0"], + ) + }, + workload_version="2.25.0", + ) + + exp_error = ( + "'swift-proxy' application is not currently supported by COU. Please manually " + "upgrade it at the end of data-plane upgrades." + ) + + with pytest.raises(ApplicationNotSupported, match=exp_error): + app.generate_upgrade_plan(target, False)