Skip to content

Commit

Permalink
Tweak exec command for the topology observer
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Oct 12, 2023
1 parent 1dcd205 commit dd08d7c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"groupName": "Juju 2"
}, {
"matchPackageNames": ["urllib3"],
"allowedVersions": "<2.0.0"
"allowedVersions": "<2.1.0"
}, {
"matchPackageNames": ["pydantic"],
"allowedVersions": "<2.0.0"
Expand Down
7 changes: 6 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def __init__(self, *args):

self.secrets = {APP_SCOPE: {}, UNIT_SCOPE: {}}

self._observer = ClusterTopologyObserver(self)
juju_version = JujuVersion.from_environ()
if juju_version.major > 2:
run_cmd = "/usr/bin/juju-exec"

Check warning on line 104 in src/charm.py

View check run for this annotation

Codecov / codecov/patch

src/charm.py#L104

Added line #L104 was not covered by tests
else:
run_cmd = "/usr/bin/juju-run"
self._observer = ClusterTopologyObserver(self, run_cmd)
self.framework.observe(self.on.cluster_topology_change, self._on_cluster_topology_change)
self.framework.observe(self.on.install, self._on_install)
self.framework.observe(self.on.leader_elected, self._on_leader_elected)
Expand Down
6 changes: 4 additions & 2 deletions src/cluster_topology_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ class ClusterTopologyObserver(Object):
Observed cluster topology changes cause :class"`ClusterTopologyChangeEvent` to be emitted.
"""

def __init__(self, charm: CharmBase):
def __init__(self, charm: CharmBase, run_cmd: str):
"""Constructor for ClusterTopologyObserver.
Args:
charm: the charm that is instantiating the library.
run_cmd: run command to use to dispatch events.
"""
super().__init__(charm, "cluster-topology-observer")

self._charm = charm
self._run_cmd = run_cmd

def start_observer(self):
"""Start the cluster topology observer running in a new process."""
Expand Down Expand Up @@ -79,7 +81,7 @@ def start_observer(self):
"src/cluster_topology_observer.py",
self._charm._patroni._patroni_url,
f"{self._charm._patroni.verify}",
"/usr/bin/juju-run",
self._run_cmd,
self._charm.unit.name,
self._charm.charm_dir,
],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_cluster_topology_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MockCharm(CharmBase):
def __init__(self, *args):
super().__init__(*args)

self.observer = ClusterTopologyObserver(self)
self.observer = ClusterTopologyObserver(self, "test-command")
self.framework.observe(self.on.cluster_topology_change, self._on_cluster_topology_change)

def _on_cluster_topology_change(self, _) -> None:
Expand Down

0 comments on commit dd08d7c

Please sign in to comment.