diff --git a/src/charm.py b/src/charm.py index 06927b521..e11dd4f74 100755 --- a/src/charm.py +++ b/src/charm.py @@ -7,7 +7,6 @@ # pylint: disable=too-many-lines """Charm for creating and managing GitHub self-hosted runner instances.""" -from ghapi.actions import github_token from github_runner_manager.manager.cloud_runner_manager import ( GitHubRunnerConfig, SupportServiceConfig, @@ -1310,7 +1309,7 @@ def _get_runner_scaler( ), # TODO think if queue_name should be really decided by charm runner_manager=runner_manager_config, cloud_runner_manager=openstack_runner_manager_config, - github_token=token + github_token=token, ) return RunnerScaler( runner_manager=runner_manager, reactive_runner_config=reactive_runner_config diff --git a/src/charm_state.py b/src/charm_state.py index c473f26b9..afe174388 100644 --- a/src/charm_state.py +++ b/src/charm_state.py @@ -38,6 +38,11 @@ from firewall import FirewallEntry from utilities import get_env_var +REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG = ( + "Reactive mode not supported for local LXD instances. " + "Please remove the mongodb integration." +) + logger = logging.getLogger(__name__) ARCHITECTURES_ARM64 = {"aarch64", "arm64"} @@ -1197,12 +1202,8 @@ def from_charm( # noqa: C901 reactive_config = ReactiveConfig.from_database(database) if instance_type == InstanceType.LOCAL_LXD and reactive_config: - logger.error( - "Reactive mode not supported for local LXD instances. Please remove the mongodb integration." - ) - raise CharmConfigInvalidError( - "Reactive mode not supported for local LXD instances. Please remove the mongodb integration." - ) + logger.error(REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG) + raise CharmConfigInvalidError(REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG) state = cls( arch=arch, diff --git a/src/runner_manager_type.py b/src/runner_manager_type.py index 17e32fa46..4c5ca9820 100644 --- a/src/runner_manager_type.py +++ b/src/runner_manager_type.py @@ -6,7 +6,6 @@ from dataclasses import dataclass from enum import Enum, auto from pathlib import Path -from typing import Iterable import jinja2 from github_runner_manager.repo_policy_compliance_client import RepoPolicyComplianceClient diff --git a/tests/integration/helpers/common.py b/tests/integration/helpers/common.py index fa34c47a7..95c8b051b 100644 --- a/tests/integration/helpers/common.py +++ b/tests/integration/helpers/common.py @@ -391,7 +391,8 @@ async def dispatch_workflow( app: The charm to dispatch the workflow for. branch: The branch to dispatch the workflow on. github_repository: The github repository to dispatch the workflow on. - conclusion: The expected workflow run conclusion. This argument is ignored if wait is False. + conclusion: The expected workflow run conclusion. + This argument is ignored if wait is False. workflow_id_or_name: The workflow filename in .github/workflows in main branch to run or its id. dispatch_input: Workflow input values. @@ -424,6 +425,7 @@ async def dispatch_workflow( return run + async def wait_for_completion(run: WorkflowRun, conclusion: str) -> None: """Wait for the workflow run to complete. @@ -437,7 +439,9 @@ async def wait_for_completion(run: WorkflowRun, conclusion: str) -> None: check_interval=60, ) # The run object is updated by _is_workflow_run_complete function above. - assert run.conclusion == conclusion, f"Unexpected run conclusion, expected: {conclusion}, got: {run.conclusion}" + assert ( + run.conclusion == conclusion + ), f"Unexpected run conclusion, expected: {conclusion}, got: {run.conclusion}" P = ParamSpec("P") diff --git a/tests/integration/test_reactive.py b/tests/integration/test_reactive.py index 6172dd6cd..461ec687c 100644 --- a/tests/integration/test_reactive.py +++ b/tests/integration/test_reactive.py @@ -14,13 +14,21 @@ from kombu import Connection from pytest_operator.plugin import OpsTest -from tests.integration.helpers.common import get_file_content, reconcile, run_in_unit, \ - dispatch_workflow, DISPATCH_TEST_WORKFLOW_FILENAME, wait_for_completion +from tests.integration.helpers.common import ( + DISPATCH_TEST_WORKFLOW_FILENAME, + dispatch_workflow, + reconcile, + wait_for_completion, +) @pytest.mark.openstack -async def test_reactive_mode_consumes_jobs(ops_test: OpsTest, app_for_reactive: Application, github_repository: Repository, - test_github_branch: Branch): +async def test_reactive_mode_consumes_jobs( + ops_test: OpsTest, + app_for_reactive: Application, + github_repository: Repository, + test_github_branch: Branch, +): """ arrange: A charm integrated with mongodb and a message is added to the queue. act: Call reconcile. @@ -32,13 +40,13 @@ async def test_reactive_mode_consumes_jobs(ops_test: OpsTest, app_for_reactive: mongodb_uri = await _get_mongodb_uri_from_secrets(ops_test, unit.model) assert mongodb_uri, "mongodb uri not found in integration data or secret" - run = await dispatch_workflow( + run = await dispatch_workflow( app=app_for_reactive, branch=test_github_branch, github_repository=github_repository, conclusion="success", workflow_id_or_name=DISPATCH_TEST_WORKFLOW_FILENAME, - wait=False + wait=False, ) jobs = list(run.jobs()) assert len(jobs) == 1, "Expected 1 job to be created" diff --git a/tests/unit/test_runner_scaler.py b/tests/unit/test_runner_scaler.py index f3199fd99..5cfae4c4f 100644 --- a/tests/unit/test_runner_scaler.py +++ b/tests/unit/test_runner_scaler.py @@ -73,8 +73,8 @@ def runner_manager_fixture( "github_runner_manager.manager.runner_manager.runner_metrics.issue_events", MagicMock() ) - config = RunnerManagerConfig("mock_token", github_path) - runner_manager = RunnerManager("mock_runners", mock_cloud, config) + config = RunnerManagerConfig("mock_runners", "mock_token", github_path) + runner_manager = RunnerManager(mock_cloud, config) runner_manager._github = mock_github return runner_manager