Skip to content

Commit

Permalink
Merge branch 'main' into fix/timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon authored Sep 20, 2024
2 parents 178b518 + b937a40 commit d44bb3a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion templates/dispatch-event.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions tests/integration/test_runner_manager_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -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")
Expand Down

0 comments on commit d44bb3a

Please sign in to comment.