18
18
the is-wrong-architecture helper function, as follows:
19
19
20
20
```python
21
- import sys
22
-
23
21
from ops import main
24
22
from charms.mysql.v0.architecture import WrongArchitectureWarningCharm, is_wrong_architecture
25
23
33
31
import os
34
32
import pathlib
35
33
import platform
36
- import sys
37
34
38
35
import yaml
39
- from ops import BlockedStatus , CharmBase
36
+ from ops .charm import CharmBase
37
+ from ops .model import BlockedStatus
40
38
41
39
# The unique Charmhub library identifier, never change it
42
40
LIBID = "827e04542dba4c2a93bdc70ae40afdb1"
@@ -56,13 +54,22 @@ def __init__(self, *args):
56
54
super ().__init__ (* args )
57
55
58
56
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
+ )
61
67
62
68
63
69
def is_wrong_architecture () -> bool :
64
70
"""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" )
66
73
67
74
if not manifest_path .exists ():
68
75
logger .error ("Cannot check architecture: manifest file not found in %s" , manifest_path )
0 commit comments