From 4348872c497954576c68105409e92e1a4d7e2988 Mon Sep 17 00:00:00 2001 From: chipaca Date: Mon, 1 Jun 2020 22:09:18 +0100 Subject: [PATCH] ops.main: only do _init_dispatch() if dispatch exists (#312) This avoids the situation where Juju is dispatch-aware but the charm is not resulting in no symlinks getting created. fixes: #310 --- ops/main.py | 2 +- test/test_main.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ops/main.py b/ops/main.py index dca8da056..c38727168 100755 --- a/ops/main.py +++ b/ops/main.py @@ -176,7 +176,7 @@ def __init__(self, charm_dir: Path): self._charm_dir = charm_dir self._exec_path = Path(sys.argv[0]) - if 'JUJU_DISPATCH_PATH' in os.environ: + if 'JUJU_DISPATCH_PATH' in os.environ and (charm_dir / 'dispatch').exists(): self._init_dispatch() else: self._init_legacy() diff --git a/test/test_main.py b/test/test_main.py index 99fe66b7b..7829c80ce 100755 --- a/test/test_main.py +++ b/test/test_main.py @@ -602,6 +602,12 @@ def test_setup_action_links(self): self.assertTrue(action_hook.exists()) +class TestMainWithNoDispatchButJujuIsDispatchAware(TestMainWithNoDispatch): + def _call_event(self, rel_path, env): + env["JUJU_DISPATCH_PATH"] = str(rel_path) + super()._call_event(rel_path, env) + + class TestMainWithNoDispatchButScriptsAreCopies(TestMainWithNoDispatch): hooks_are_symlinks = False