Skip to content

Commit

Permalink
Added step to upgrade unit by running openstack-upgrade action.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcocenza committed Feb 7, 2024
1 parent 02b9a2a commit 650bff1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/apps/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 650bff1

Please sign in to comment.