diff --git a/src/charm.py b/src/charm.py index 9dae00059..4e09b693f 100755 --- a/src/charm.py +++ b/src/charm.py @@ -574,6 +574,22 @@ def _ensure_reconcile_timer_is_active(self) -> None: logger.error("Reconciliation event timer is not activated") self._set_reconcile_timer() + @staticmethod + def _log_juju_processes() -> None: + """Log the running Juju processes. + + Log all processes with 'juju' in the command line. + """ + try: + processes, _ = execute_command( + ["ps", "afuwwx"], + check_exit=True, + ) + juju_processes = "\n".join(line for line in processes.splitlines() if "juju" in line) + logger.info("Juju processes: %s", juju_processes) + except SubprocessError: + logger.exception("Failed to get Juju processes") + @catch_charm_errors def _on_upgrade_charm(self, _: UpgradeCharmEvent) -> None: """Handle the update of charm.""" @@ -898,6 +914,7 @@ def _on_update_dependencies_action(self, event: ActionEvent) -> None: def _on_update_status(self, _: UpdateStatusEvent) -> None: """Handle the update of charm status.""" self._ensure_reconcile_timer_is_active() + self._log_juju_processes() @catch_charm_errors def _on_stop(self, _: StopEvent) -> None: diff --git a/templates/dispatch-event.service.j2 b/templates/dispatch-event.service.j2 index b4482795f..8908f048f 100644 --- a/templates/dispatch-event.service.j2 +++ b/templates/dispatch-event.service.j2 @@ -4,7 +4,7 @@ Description=Dispatch the {{event}} event on {{unit}} [Service] Type=oneshot # For juju 3 and juju 2 compatibility. The juju-run binary was renamed to juju-exec for juju 3. -ExecStart=/usr/bin/timeout "{{timeout}}" /usr/bin/run-one /usr/bin/bash -c '/usr/bin/juju-exec "{{unit}}" "JUJU_DISPATCH_PATH={{event}} ./dispatch" || /usr/bin/juju-run "{{unit}}" "JUJU_DISPATCH_PATH={{event}} ./dispatch"' +ExecStart=/usr/bin/timeout "{{timeout}}" /usr/bin/run-one /usr/bin/bash -c '/usr/bin/juju-exec "{{unit}}" "JUJU_DISPATCH_PATH={{event}} /usr/bin/timeout {{timeout}} ./dispatch" || /usr/bin/juju-run "{{unit}}" "JUJU_DISPATCH_PATH={{event}} /usr/bin/timeout {{timeout}} ./dispatch"' [Install] WantedBy=multi-user.target diff --git a/tests/integration/test_runner_manager_openstack.py b/tests/integration/test_runner_manager_openstack.py index cb88d84ba..ba4d71b10 100644 --- a/tests/integration/test_runner_manager_openstack.py +++ b/tests/integration/test_runner_manager_openstack.py @@ -7,7 +7,7 @@ import json from pathlib import Path from secrets import token_hex -from typing import Iterator +from typing import AsyncGenerator, Iterator import pytest import pytest_asyncio @@ -105,7 +105,7 @@ async def openstack_runner_manager_fixture( proxy_config: ProxyConfig, runner_label: str, openstack_connection: OpenstackConnection, -) -> OpenStackRunnerManager: +) -> AsyncGenerator[OpenStackRunnerManager, None]: """Create OpenstackRunnerManager instance. The prefix args of OpenstackRunnerManager set to app_name to let openstack_connection_fixture @@ -133,7 +133,7 @@ async def openstack_runner_manager_fixture( ssh_debug_connections=None, repo_policy_compliance=None, ) - return OpenStackRunnerManager( + yield OpenStackRunnerManager( app_name, f"{app_name}-0", cloud_config, server_config, runner_config, service_config ) @@ -144,13 +144,13 @@ async def runner_manager_fixture( token: str, github_path: GitHubPath, log_dir_base_path: dict[str, Path], -) -> RunnerManager: +) -> AsyncGenerator[RunnerManager, None]: """Get RunnerManager instance. Import of log_dir_base_path to monkeypatch the runner logs path with tmp_path. """ config = RunnerManagerConfig(token, github_path) - return RunnerManager("test_runner", openstack_runner_manager, config) + yield RunnerManager("test_runner", openstack_runner_manager, config) @pytest_asyncio.fixture(scope="function", name="runner_manager_with_one_runner")