Skip to content

Commit

Permalink
remove loop devices in integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
javierdelapuente committed Dec 16, 2024
1 parent a1e26d0 commit d730cbf
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 126 deletions.
14 changes: 0 additions & 14 deletions scripts/pre-integration-test.sh

This file was deleted.

5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def pytest_addoption(parser: Parser):
action="store",
help="No proxy configuration value for juju model proxy configuration.",
)
parser.addoption(
"--loop-device",
action="store",
help="The loop device to create shared FS for metrics logging",
)
parser.addoption(
"--openstack-clouds-yaml",
action="store",
Expand Down
15 changes: 1 addition & 14 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
MONGODB_APP_NAME,
InstanceHelper,
deploy_github_runner_charm,
inject_lxd_profile,
reconcile,
wait_for,
)
Expand Down Expand Up @@ -101,18 +100,12 @@ def openstack_clouds_yaml_fixture(pytestconfig: pytest.Config) -> str | None:


@pytest.fixture(scope="module")
def charm_file(
pytestconfig: pytest.Config, loop_device: Optional[str], openstack_clouds_yaml: Optional[str]
) -> str:
def charm_file(pytestconfig: pytest.Config, openstack_clouds_yaml: Optional[str]) -> str:
"""Path to the built charm."""
charm = pytestconfig.getoption("--charm-file")
assert charm, "Please specify the --charm-file command line option"
charm_path_str = f"./{charm}"

if openstack_clouds_yaml:
return charm_path_str

inject_lxd_profile(charm_file=Path(charm_path_str), loop_device=loop_device)
return charm_path_str


Expand Down Expand Up @@ -191,12 +184,6 @@ def openstack_no_proxy_fixture(pytestconfig: pytest.Config) -> str:
return "" if no_proxy is None else no_proxy


@pytest.fixture(scope="module")
def loop_device(pytestconfig: pytest.Config) -> Optional[str]:
"""Configured loop_device setting."""
return pytestconfig.getoption("--loop-device")


@pytest.fixture(scope="module", name="private_endpoint_config")
def private_endpoint_config_fixture(pytestconfig: pytest.Config) -> PrivateEndpointConfigs | None:
"""The private endpoint configuration values."""
Expand Down
22 changes: 0 additions & 22 deletions tests/integration/helpers/charm_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,6 @@ async def clear_metrics_log(unit: Unit) -> None:
assert retcode == 0, f"Failed to clear metrics log, {stderr}"


async def print_loop_device_info(unit: Unit, loop_device: str) -> None:
"""Print loop device info on the unit.
Args:
unit: The unit to print the loop device info on.
loop_device: The loop device to print the info for.
"""
retcode, stdout, stderr = await run_in_unit(
unit=unit,
command="sudo losetup -lJ",
)
assert retcode == 0, f"Failed to get loop devices: {stdout} {stderr}"
assert stdout is not None, "Failed to get loop devices, no stdout message"
loop_devices_info = json.loads(stdout)
for loop_device_info in loop_devices_info["loopdevices"]:
if loop_device_info["name"] == loop_device:
logging.info("Loop device %s info: %s", loop_device, loop_device_info)
break
else:
logging.info("Loop device %s not found", loop_device)


async def get_metrics_log(unit: Unit) -> str:
"""Retrieve the metrics log from the unit.
Expand Down
38 changes: 0 additions & 38 deletions tests/integration/helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import subprocess
import time
import typing
import zipfile
from datetime import datetime, timezone
from functools import partial
from typing import Awaitable, Callable, ParamSpec, TypeVar, cast
Expand Down Expand Up @@ -508,43 +507,6 @@ async def wait_for(
raise TimeoutError()


def inject_lxd_profile(charm_file: pathlib.Path, loop_device: str | None) -> None:
"""Injects LXD profile to charm file.
Args:
charm_file: Path to charm file to deploy.
loop_device: Loop device used to mount runner image.
"""
lxd_profile_str = """config:
security.nesting: true
security.privileged: true
raw.lxc: |
lxc.apparmor.profile=unconfined
lxc.mount.auto=proc:rw sys:rw cgroup:rw
lxc.cgroup.devices.allow=a
lxc.cap.drop=
devices:
kmsg:
path: /dev/kmsg
source: /dev/kmsg
type: unix-char
"""
if loop_device:
lxd_profile_str += f""" loop-control:
path: /dev/loop-control
type: unix-char
loop14:
path: {loop_device}
type: unix-block
"""

with zipfile.ZipFile(charm_file, mode="a") as file:
file.writestr(
"lxd-profile.yaml",
lxd_profile_str,
)


async def is_upgrade_charm_event_emitted(unit: Unit) -> bool:
"""Check if the upgrade_charm event is emitted.
Expand Down
26 changes: 0 additions & 26 deletions tests/integration/test_charm_metrics_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"""Integration tests for metrics/logs assuming Github workflow failures or a runner crash."""
import time
from asyncio import sleep
from typing import AsyncIterator

import pytest
import pytest_asyncio
from github.Branch import Branch
from github.Repository import Repository
from github_runner_manager.metrics.runner import PostJobStatus
Expand All @@ -19,7 +17,6 @@
assert_events_after_reconciliation,
cancel_workflow_run,
clear_metrics_log,
print_loop_device_info,
wait_for_runner_to_be_marked_offline,
wait_for_workflow_to_start,
)
Expand All @@ -33,29 +30,6 @@
from tests.integration.helpers.openstack import OpenStackInstanceHelper, setup_repo_policy


@pytest_asyncio.fixture(scope="function", name="app")
async def app_fixture(
model: Model, app_for_metric: Application, loop_device: str
) -> AsyncIterator[Application]:
"""Setup and teardown the charm after each test.
Clear the metrics log before each test.
"""
unit = app_for_metric.units[0]
await clear_metrics_log(unit)
await print_loop_device_info(unit, loop_device)
await app_for_metric.set_config(
{
VIRTUAL_MACHINES_CONFIG_NAME: "0",
"repo-policy-compliance-token": "",
"repo-policy-compliance-url": "",
}
)
await reconcile(app=app_for_metric, model=model)

yield app_for_metric


@pytest.mark.openstack
@pytest.mark.asyncio
@pytest.mark.abort_on_fail
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/test_charm_metrics_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
assert_events_after_reconciliation,
clear_metrics_log,
get_metrics_log,
print_loop_device_info,
)
from tests.integration.helpers.common import (
DISPATCH_TEST_WORKFLOW_FILENAME,
Expand All @@ -30,16 +29,13 @@


@pytest_asyncio.fixture(scope="function", name="app")
async def app_fixture(
model: Model, app_for_metric: Application, loop_device: str
) -> AsyncIterator[Application]:
async def app_fixture(model: Model, app_for_metric: Application) -> AsyncIterator[Application]:
"""Setup and teardown the charm after each test.
Clear the metrics log before each test.
"""
unit = app_for_metric.units[0]
await clear_metrics_log(unit)
await print_loop_device_info(unit, loop_device)

yield app_for_metric

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_charm_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async def test_charm_upgrade(
model: Model,
ops_test: OpsTest,
charm_file: str,
loop_device: str | None,
app_name: str,
path: str,
token: str,
Expand All @@ -53,7 +52,7 @@ async def test_charm_upgrade(
"""
latest_stable_path = tmp_path / "github-runner.charm"
latest_stable_revision = 302 # update this value every release to stable.
# download the charm and inject lxd profile for testing
# download the charm
retcode, stdout, stderr = await ops_test.juju(
"download",
"github-runner",
Expand Down

0 comments on commit d730cbf

Please sign in to comment.