From d730cbf7aa8638a5d1c83ca603eb1a835eaf54a9 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Mon, 16 Dec 2024 17:06:00 +0100 Subject: [PATCH] remove loop devices in integration testing --- scripts/pre-integration-test.sh | 14 ------- tests/conftest.py | 5 --- tests/integration/conftest.py | 15 +------- tests/integration/helpers/charm_metrics.py | 22 ----------- tests/integration/helpers/common.py | 38 ------------------- .../integration/test_charm_metrics_failure.py | 26 ------------- .../integration/test_charm_metrics_success.py | 6 +-- tests/integration/test_charm_upgrade.py | 3 +- 8 files changed, 3 insertions(+), 126 deletions(-) delete mode 100755 scripts/pre-integration-test.sh diff --git a/scripts/pre-integration-test.sh b/scripts/pre-integration-test.sh deleted file mode 100755 index 04540449d..000000000 --- a/scripts/pre-integration-test.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2024 Canonical Ltd. -# See LICENSE file for licensing details. - -# Enable kernel module br_netfilter -sudo modprobe br_netfilter - -# Install tinyproxy -sudo apt install tinyproxy -y - -# Find a loop-device -loop_device=$(sudo losetup -f) -echo "PYTEST_ADDOPTS=--loop-device=$loop_device" >> "$GITHUB_ENV" diff --git a/tests/conftest.py b/tests/conftest.py index c07f2e872..4942b019c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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", diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index ae6d5608b..f47ed2a16 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -40,7 +40,6 @@ MONGODB_APP_NAME, InstanceHelper, deploy_github_runner_charm, - inject_lxd_profile, reconcile, wait_for, ) @@ -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 @@ -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.""" diff --git a/tests/integration/helpers/charm_metrics.py b/tests/integration/helpers/charm_metrics.py index 6baea6990..646c6ae9b 100644 --- a/tests/integration/helpers/charm_metrics.py +++ b/tests/integration/helpers/charm_metrics.py @@ -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. diff --git a/tests/integration/helpers/common.py b/tests/integration/helpers/common.py index dcc28020c..c9554d35c 100644 --- a/tests/integration/helpers/common.py +++ b/tests/integration/helpers/common.py @@ -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 @@ -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. diff --git a/tests/integration/test_charm_metrics_failure.py b/tests/integration/test_charm_metrics_failure.py index c7249f9d7..aebba74b7 100644 --- a/tests/integration/test_charm_metrics_failure.py +++ b/tests/integration/test_charm_metrics_failure.py @@ -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 @@ -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, ) @@ -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 diff --git a/tests/integration/test_charm_metrics_success.py b/tests/integration/test_charm_metrics_success.py index 8da7808fa..932dc5d6e 100644 --- a/tests/integration/test_charm_metrics_success.py +++ b/tests/integration/test_charm_metrics_success.py @@ -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, @@ -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 diff --git a/tests/integration/test_charm_upgrade.py b/tests/integration/test_charm_upgrade.py index 2f9fb3caf..467633bac 100644 --- a/tests/integration/test_charm_upgrade.py +++ b/tests/integration/test_charm_upgrade.py @@ -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, @@ -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",