Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartz committed Sep 18, 2024
1 parent da15805 commit 20e0fa7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/charm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/runner_manager_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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")
Expand Down
20 changes: 14 additions & 6 deletions tests/integration/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_runner_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 20e0fa7

Please sign in to comment.