Skip to content

Commit

Permalink
ops.main: only do _init_dispatch() if dispatch exists (#312)
Browse files Browse the repository at this point in the history
This avoids the situation where Juju is dispatch-aware but the charm
is not resulting in no symlinks getting created.

fixes: #310
  • Loading branch information
chipaca authored Jun 1, 2020
1 parent d69e7ac commit 4348872
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ops/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4348872

Please # to comment.