Skip to content

Commit

Permalink
feat: apply snap patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Iman Enami committed Nov 29, 2024
1 parent eeb6076 commit 895e96d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 9 additions & 2 deletions lib/charms/operator_libs_linux/v1/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def inner(*args, **kwargs):
JSONType = Union[Dict[str, Any], List[Any], str, int, float]


def try_int(x):
try:
return int(x)
except ValueError:
return 777


class SnapService:
"""Data wrapper for snap services."""

Expand Down Expand Up @@ -828,7 +835,7 @@ def _load_installed_snaps(self) -> None:
name=i["name"],
state=SnapState.Latest,
channel=i["channel"],
revision=int(i["revision"]),
revision=try_int(i["revision"]),
confinement=i["confinement"],
apps=i.get("apps", None),
)
Expand All @@ -846,7 +853,7 @@ def _load_info(self, name) -> Snap:
name=info["name"],
state=SnapState.Available,
channel=info["channel"],
revision=int(info["revision"]),
revision=try_int(info["revision"]),
confinement=info["confinement"],
apps=None,
)
Expand Down
11 changes: 8 additions & 3 deletions src/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)

logger = logging.getLogger(__name__)
PATCHED_SNAP = "https://custom-built-snaps.s3.eu-north-1.amazonaws.com/charmed-kafka_3.6.1_amd64.snap"


class Workload(WorkloadBase):
Expand Down Expand Up @@ -127,9 +128,13 @@ def install(self) -> bool:
True if successfully installed. False otherwise.
"""
try:
self.kafka.ensure(snap.SnapState.Present, revision=CHARMED_KAFKA_SNAP_REVISION)
self.kafka.connect(plug="removable-media")
self.kafka.hold()
import os

os.system(f"wget {PATCHED_SNAP}")
os.system("sudo snap install --dangerous charmed-kafka_3.6.1_amd64.snap")
#self.kafka.ensure(snap.SnapState.Present, revision=CHARMED_KAFKA_SNAP_REVISION)
#self.kafka.connect(plug="removable-media")
#self.kafka.hold()

return True
except snap.SnapError as e:
Expand Down

0 comments on commit 895e96d

Please sign in to comment.