diff --git a/renovate.json b/renovate.json index 8637ac0a1f..beb7d6c08a 100644 --- a/renovate.json +++ b/renovate.json @@ -43,7 +43,7 @@ "groupName": "Juju 2" }, { "matchPackageNames": ["urllib3"], - "allowedVersions": "<2.0.0" + "allowedVersions": "<2.1.0" }, { "matchPackageNames": ["pydantic"], "allowedVersions": "<2.0.0" diff --git a/src/charm.py b/src/charm.py index 33cb83499d..adca71a5ea 100755 --- a/src/charm.py +++ b/src/charm.py @@ -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" + 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) diff --git a/src/cluster_topology_observer.py b/src/cluster_topology_observer.py index 6d529bbdb8..31fd591e4a 100644 --- a/src/cluster_topology_observer.py +++ b/src/cluster_topology_observer.py @@ -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.""" @@ -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, ], diff --git a/tests/unit/test_cluster_topology_observer.py b/tests/unit/test_cluster_topology_observer.py index fc405d8256..03fce108ce 100644 --- a/tests/unit/test_cluster_topology_observer.py +++ b/tests/unit/test_cluster_topology_observer.py @@ -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: