diff --git a/cou/apps/base.py b/cou/apps/base.py index edb27181..1ecf2e34 100644 --- a/cou/apps/base.py +++ b/cou/apps/base.py @@ -665,6 +665,21 @@ def _get_resume_unit_step(self, unit: ApplicationUnit) -> UnitUpgradeStep: ), ) + def _get_openstack_upgrade_step(self, unit: ApplicationUnit) -> UnitUpgradeStep: + """Get the step to upgrade a unit. + + :param unit: Unit to be upgraded. + :type unit: ApplicationUnit + :return: Step to upgrade a unit. + :rtype: UnitUpgradeStep + """ + return UnitUpgradeStep( + description=(f"Upgrade the unit: '{unit.name}'."), + coro=self.model.run_action( + unit_name=unit.name, action_name="openstack-upgrade", raise_on_failure=True + ), + ) + def _get_workload_upgrade_step(self, target: OpenStackRelease) -> UpgradeStep: """Get workload upgrade step by changing openstack-origin or source. diff --git a/tests/unit/apps/test_base.py b/tests/unit/apps/test_base.py index 59df7cec..85f834d7 100644 --- a/tests/unit/apps/test_base.py +++ b/tests/unit/apps/test_base.py @@ -100,3 +100,22 @@ def test_get_resume_unit_step(model): app = OpenStackApplication(app_name, status, {}, model, charm, {}) assert app._get_resume_unit_step(unit) == expected_upgrade_step + + +def test_get_openstack_upgrade_step(model): + charm = "app" + app_name = "my_app" + status = MagicMock(spec_set=ApplicationStatus()) + status.charm_channel = "ussuri/stable" + + unit = ApplicationUnit("my_app/0", MagicMock(), MagicMock(), MagicMock()) + + expected_upgrade_step = UnitUpgradeStep( + description=f"Upgrade the unit: '{unit.name}'.", + coro=model.run_action( + unit_name=unit.name, action_name="openstack-upgrade", raise_on_failure=True + ), + ) + + app = OpenStackApplication(app_name, status, {}, model, charm, {}) + assert app._get_openstack_upgrade_step(unit) == expected_upgrade_step