Skip to content

Commit c1acb20

Browse files
[DEP-5588] Fix architecture lib helpers (#564)
1 parent f1cce24 commit c1acb20

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/charms/mysql/v0/architecture.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
the is-wrong-architecture helper function, as follows:
1919
2020
```python
21-
import sys
22-
2321
from ops import main
2422
from charms.mysql.v0.architecture import WrongArchitectureWarningCharm, is_wrong_architecture
2523
@@ -33,10 +31,10 @@
3331
import os
3432
import pathlib
3533
import platform
36-
import sys
3734

3835
import yaml
39-
from ops import BlockedStatus, CharmBase
36+
from ops.charm import CharmBase
37+
from ops.model import BlockedStatus
4038

4139
# The unique Charmhub library identifier, never change it
4240
LIBID = "827e04542dba4c2a93bdc70ae40afdb1"
@@ -56,13 +54,22 @@ def __init__(self, *args):
5654
super().__init__(*args)
5755

5856
hw_arch = platform.machine()
59-
self.unit.status = BlockedStatus(f"Error: Charm incompatible with {hw_arch} architecture")
60-
sys.exit(0)
57+
self.unit.status = BlockedStatus(
58+
f"Charm incompatible with {hw_arch} architecture. "
59+
f"If this app is being refreshed, rollback"
60+
)
61+
raise RuntimeError(
62+
f"Incompatible architecture: this charm revision does not support {hw_arch}. "
63+
f"If this app is being refreshed, rollback with instructions from Charmhub docs. "
64+
f"If this app is being deployed for the first time, remove it and deploy it again "
65+
f"using a compatible revision."
66+
)
6167

6268

6369
def is_wrong_architecture() -> bool:
6470
"""Checks if charm was deployed on wrong architecture."""
65-
manifest_path = pathlib.Path(os.environ["CHARM_DIR"], "manifest.yaml")
71+
charm_path = os.environ.get("CHARM_DIR", "")
72+
manifest_path = pathlib.Path(charm_path, "manifest.yaml")
6673

6774
if not manifest_path.exists():
6875
logger.error("Cannot check architecture: manifest file not found in %s", manifest_path)

0 commit comments

Comments
 (0)