Skip to content

Commit 59aacff

Browse files
Sync abstract_charm.py with vm
1 parent 29f1cb8 commit 59aacff

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/abstract_charm.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,30 @@ def is_compatible(
4141
old_workload_version: str,
4242
new_workload_version: str,
4343
) -> bool:
44+
# Check charm version compatibility
4445
if not super().is_compatible(
4546
old_charm_version=old_charm_version,
4647
new_charm_version=new_charm_version,
4748
old_workload_version=old_workload_version,
4849
new_workload_version=new_workload_version,
4950
):
5051
return False
51-
# TODO: check workload version—prevent downgrade?
52-
return True
52+
53+
# Check workload version compatibility
54+
old_major, old_minor, old_patch = (
55+
int(component) for component in old_workload_version.split(".")
56+
)
57+
new_major, new_minor, new_patch = (
58+
int(component) for component in new_workload_version.split(".")
59+
)
60+
if old_major != new_major:
61+
return False
62+
if new_minor > old_minor:
63+
return True
64+
elif new_minor == old_minor:
65+
return new_patch >= old_patch
66+
else:
67+
return False
5368

5469

5570
class MySQLRouterCharm(ops.CharmBase, abc.ABC):
@@ -323,7 +338,7 @@ def reconcile(self, event=None) -> None: # noqa: C901
323338
if self._database_requires.is_relation_breaking(event):
324339
if self.refresh.in_progress:
325340
logger.warning(
326-
"Modifying relations during an upgrade is not supported. The charm may be in a broken, unrecoverable state. Re-deploy the charm"
341+
"Modifying relations during a refresh is not supported. The charm may be in a broken, unrecoverable state. Re-deploy the charm"
327342
)
328343
self._database_provides.delete_all_databags()
329344
elif (

0 commit comments

Comments
 (0)