Skip to content

Commit

Permalink
Fix set_action_managed_upgrade (canonical#378)
Browse files Browse the repository at this point in the history
- pythonlibjuju pass a string to configuration and not boolean and this
was breaking the execution
  • Loading branch information
gabrielcocenza authored Apr 18, 2024
1 parent 8f1300c commit 9694087
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
10 changes: 7 additions & 3 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,19 @@ def _set_action_managed_upgrade(self, enable: bool) -> UpgradeStep:
)
return UpgradeStep()

if self.config["action-managed-upgrade"].get("value") == enable:
amu_config = self.config["action-managed-upgrade"].get("value")
if amu_config == enable:
logger.debug(
"%s application already has action-managed-upgrade set to %s", self.name, enable
)
return UpgradeStep()

return UpgradeStep(
f"Change charm config of '{self.name}' 'action-managed-upgrade' to '{enable}'",
coro=self.model.set_application_config(self.name, {"action-managed-upgrade": enable}),
f"Change charm config of '{self.name}' 'action-managed-upgrade' "
f"from '{amu_config}' to '{enable}'",
coro=self.model.set_application_config(
self.name, {"action-managed-upgrade": str(enable)}
),
)

def _get_pause_unit_step(self, unit: Unit, dependent: bool = False) -> UnitUpgradeStep:
Expand Down
4 changes: 2 additions & 2 deletions tests/mocked_plans/sample_plans/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plan: |
Upgrade software packages of 'keystone' from the current APT repositories
Upgrade software packages on unit 'keystone/0'
Refresh 'keystone' to the latest revision of 'ussuri/stable'
Change charm config of 'keystone' 'action-managed-upgrade' to 'False'
Change charm config of 'keystone' 'action-managed-upgrade' from 'True' to 'False'
Upgrade 'keystone' to the new channel: 'victoria/stable'
Change charm config of 'keystone' 'openstack-origin' to 'cloud:focal-victoria'
Wait for up to 2400s for model 'base' to reach the idle state
Expand All @@ -22,7 +22,7 @@ plan: |
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/apps/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def test_application_get_latest_os_version_failed(mock_find_compatible_versions,
(
{"action-managed-upgrade": {"value": False}},
True,
"Change charm config of 'my_app' 'action-managed-upgrade' to 'True'",
"Change charm config of 'my_app' 'action-managed-upgrade' from 'False' to 'True'",
),
({"action-managed-upgrade": {"value": False}}, False, None),
({"action-managed-upgrade": {"value": True}}, True, None),
(
{"action-managed-upgrade": {"value": True}},
False,
"Change charm config of 'my_app' 'action-managed-upgrade' to 'False'",
"Change charm config of 'my_app' 'action-managed-upgrade' from 'True' to 'False'",
),
],
)
Expand All @@ -113,7 +113,7 @@ def test_set_action_managed_upgrade(charm_config, enable, exp_description, model
# Note (rgildein): we need to set exp_step here, since we need to use model fixture
exp_step = UpgradeStep(
description=exp_description,
coro=model.set_application_config(app_name, {"action-managed-upgrade": enable}),
coro=model.set_application_config(app_name, {"action-managed-upgrade": str(enable)}),
)
else:
exp_step = UpgradeStep()
Expand Down
26 changes: 15 additions & 11 deletions tests/unit/apps/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ def test_upgrade_plan_ussuri_to_victoria(model):
coro=model.upgrade_charm(app.name, "ussuri/stable"),
),
UpgradeStep(
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' to 'False'",
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' "
"from 'True' to 'False'",
parallel=False,
coro=model.set_application_config(app.name, {"action-managed-upgrade": False}),
coro=model.set_application_config(app.name, {"action-managed-upgrade": str(False)}),
),
UpgradeStep(
description=f"Upgrade '{app.name}' to the new channel: 'victoria/stable'",
Expand Down Expand Up @@ -296,9 +297,10 @@ def test_upgrade_plan_ussuri_to_victoria_ch_migration(model):
coro=model.upgrade_charm(app.name, "ussuri/stable", switch="ch:keystone"),
),
UpgradeStep(
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' to 'False'",
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' "
"from 'True' to 'False'",
parallel=False,
coro=model.set_application_config(app.name, {"action-managed-upgrade": False}),
coro=model.set_application_config(app.name, {"action-managed-upgrade": str(False)}),
),
UpgradeStep(
description=f"Upgrade '{app.name}' to the new channel: 'victoria/stable'",
Expand Down Expand Up @@ -379,9 +381,10 @@ def test_upgrade_plan_channel_on_next_os_release(model):
upgrade_steps = [
upgrade_packages,
UpgradeStep(
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' to 'False'",
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' "
"from 'True' to 'False'",
parallel=False,
coro=model.set_application_config(app.name, {"action-managed-upgrade": False}),
coro=model.set_application_config(app.name, {"action-managed-upgrade": str(False)}),
),
UpgradeStep(
description=f"Change charm config of '{app.name}' "
Expand Down Expand Up @@ -461,9 +464,10 @@ def test_upgrade_plan_origin_already_on_next_openstack_release(model):
coro=model.upgrade_charm(app.name, "ussuri/stable"),
),
UpgradeStep(
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' to 'False'",
description=f"Change charm config of '{app.name}' 'action-managed-upgrade' "
"from 'True' to 'False'",
parallel=False,
coro=model.set_application_config(app.name, {"action-managed-upgrade": False}),
coro=model.set_application_config(app.name, {"action-managed-upgrade": str(False)}),
),
UpgradeStep(
description=f"Upgrade '{app.name}' to the new channel: 'victoria/stable'",
Expand Down Expand Up @@ -787,7 +791,7 @@ def test_nova_compute_upgrade_plan(model):
Upgrade software packages on unit 'nova-compute/1'
Upgrade software packages on unit 'nova-compute/2'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0, nova-compute/1, nova-compute/2
Expand Down Expand Up @@ -852,7 +856,7 @@ def test_nova_compute_upgrade_plan_single_unit(model):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand Down Expand Up @@ -954,7 +958,7 @@ def test_cinder_upgrade_plan_single_unit(model):
Upgrade software packages of 'cinder' from the current APT repositories
Upgrade software packages on unit 'cinder/0'
Refresh 'cinder' to the latest revision of 'ussuri/stable'
Change charm config of 'cinder' 'action-managed-upgrade' to 'True'
Change charm config of 'cinder' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'cinder' to the new channel: 'victoria/stable'
Change charm config of 'cinder' 'openstack-origin' to 'cloud:focal-victoria'
Upgrade plan for units: cinder/0
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/steps/test_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,15 @@ def test_hypervisor_upgrade_plan(model):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'cinder' 'action-managed-upgrade' to 'True'
Change charm config of 'cinder' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'cinder' to the new channel: 'victoria/stable'
Change charm config of 'cinder' 'openstack-origin' to 'cloud:focal-victoria'
Upgrade plan for units: cinder/0
Upgrade plan for unit 'cinder/0'
Pause the unit: 'cinder/0'
Upgrade the unit: 'cinder/0'
Resume the unit: 'cinder/0'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand All @@ -427,7 +427,7 @@ def test_hypervisor_upgrade_plan(model):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/1'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/1
Expand All @@ -444,7 +444,7 @@ def test_hypervisor_upgrade_plan(model):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/2'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/2
Expand Down Expand Up @@ -527,15 +527,15 @@ def test_hypervisor_upgrade_plan_single_machine(model):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'cinder' 'action-managed-upgrade' to 'True'
Change charm config of 'cinder' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'cinder' to the new channel: 'victoria/stable'
Change charm config of 'cinder' 'openstack-origin' to 'cloud:focal-victoria'
Upgrade plan for units: cinder/0
Upgrade plan for unit 'cinder/0'
Pause the unit: 'cinder/0'
Upgrade the unit: 'cinder/0'
Resume the unit: 'cinder/0'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/steps/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def test_generate_plan(mock_filter_hypervisors, model, cli_args):
Upgrade software packages of 'keystone' from the current APT repositories
Upgrade software packages on unit 'keystone/0'
Refresh 'keystone' to the latest revision of 'ussuri/stable'
Change charm config of 'keystone' 'action-managed-upgrade' to 'False'
Change charm config of 'keystone' 'action-managed-upgrade' from 'True' to 'False'
Upgrade 'keystone' to the new channel: 'victoria/stable'
Change charm config of 'keystone' 'openstack-origin' to 'cloud:focal-victoria'
Wait for up to 2400s for model 'test_model' to reach the idle state
Expand All @@ -167,7 +167,7 @@ async def test_generate_plan(mock_filter_hypervisors, model, cli_args):
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand All @@ -192,7 +192,7 @@ async def test_generate_plan(mock_filter_hypervisors, model, cli_args):
Data Plane subordinate(s) upgrade plan
Upgrade plan for 'ovn-chassis' to 'victoria'
Refresh 'ovn-chassis' to the latest revision of '22.03/stable'
"""
""" # noqa: E501 line too long
)
cli_args.upgrade_group = None
cli_args.force = False
Expand Down Expand Up @@ -323,7 +323,7 @@ async def test_generate_plan_with_warning_messages(mock_filter_hypervisors, mode
Upgrade software packages of 'nova-compute' from the current APT repositories
Upgrade software packages on unit 'nova-compute/0'
Refresh 'nova-compute' to the latest revision of 'ussuri/stable'
Change charm config of 'nova-compute' 'action-managed-upgrade' to 'True'
Change charm config of 'nova-compute' 'action-managed-upgrade' from 'False' to 'True'
Upgrade 'nova-compute' to the new channel: 'victoria/stable'
Change charm config of 'nova-compute' 'source' to 'cloud:focal-victoria'
Upgrade plan for units: nova-compute/0
Expand All @@ -348,7 +348,7 @@ async def test_generate_plan_with_warning_messages(mock_filter_hypervisors, mode
Data Plane subordinate(s) upgrade plan
Upgrade plan for 'ovn-chassis' to 'victoria'
Refresh 'ovn-chassis' to the latest revision of '22.03/stable'
"""
""" # noqa: E501 line too long
)
cli_args.upgrade_group = None
cli_args.force = False
Expand Down

0 comments on commit 9694087

Please sign in to comment.