diff --git a/tests/integration/README.md b/tests/integration/README.md index b16d964e0..2e82a7f14 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -2,7 +2,7 @@ ## Overview -End to end tests are written in Python. They are built on top of a [Harness](./tests/conftest.py) fixture so that they can run on multiple environments like LXD, Multipass, Juju, or the local machine. +End to end tests are written in Python. They are built on top of a [Harness](./tests/conftest.py) fixture so that they can run on multiple environments like LXD, Multipass, or Juju. End to end tests can be configured using environment variables. You can see all available options in [./tests/config.py](./tests/config.py). @@ -28,17 +28,6 @@ In general, all end to end tests will require specifying the local path to the s End to end tests are typically run with: `cd tests/integration && tox -e integration` -### Running end to end tests on the local machine - -```bash -export TEST_SNAP=$PWD/k8s.snap -export TEST_SUBSTRATE=local - -cd tests/integration && tox -e integration -``` - -> *NOTE*: When running locally, end to end tests that create more than one instance will fail. - ### Running end to end tests on LXD containers First, make sure that you have initialized LXD: diff --git a/tests/integration/tests/conftest.py b/tests/integration/tests/conftest.py index 52bc3ba1c..8022b53ce 100644 --- a/tests/integration/tests/conftest.py +++ b/tests/integration/tests/conftest.py @@ -81,9 +81,7 @@ def _generate_inspection_report(h: harness.Harness, instance_id: str): @pytest.fixture(scope="session") def h() -> harness.Harness: LOG.debug("Create harness for %s", config.SUBSTRATE) - if config.SUBSTRATE == "local": - h = harness.LocalHarness() - elif config.SUBSTRATE == "lxd": + if config.SUBSTRATE == "lxd": h = harness.LXDHarness() elif config.SUBSTRATE == "multipass": h = harness.MultipassHarness() @@ -91,7 +89,7 @@ def h() -> harness.Harness: h = harness.JujuHarness() else: raise harness.HarnessError( - "TEST_SUBSTRATE must be one of: local, lxd, multipass, juju" + "TEST_SUBSTRATE must be one of: lxd, multipass, juju" ) yield h diff --git a/tests/integration/tests/test_util/config.py b/tests/integration/tests/test_util/config.py index 23f75e894..7da84e6cd 100644 --- a/tests/integration/tests/test_util/config.py +++ b/tests/integration/tests/test_util/config.py @@ -44,8 +44,8 @@ SNAP_NAME = os.getenv("TEST_SNAP_NAME") or "k8s" # SUBSTRATE is the substrate to use for running the integration tests. -# One of 'local' (default), 'lxd', 'juju', or 'multipass'. -SUBSTRATE = os.getenv("TEST_SUBSTRATE") or "local" +# One of 'lxd' (default), 'juju', or 'multipass'. +SUBSTRATE = os.getenv("TEST_SUBSTRATE") or "lxd" # SKIP_CLEANUP can be used to prevent machines to be automatically destroyed # after the tests complete. diff --git a/tests/integration/tests/test_util/harness/__init__.py b/tests/integration/tests/test_util/harness/__init__.py index 1aa0c6f94..2198fcd2e 100644 --- a/tests/integration/tests/test_util/harness/__init__.py +++ b/tests/integration/tests/test_util/harness/__init__.py @@ -3,7 +3,6 @@ # from test_util.harness.base import Harness, HarnessError, Instance from test_util.harness.juju import JujuHarness -from test_util.harness.local import LocalHarness from test_util.harness.lxd import LXDHarness from test_util.harness.multipass import MultipassHarness @@ -12,7 +11,6 @@ Harness, Instance, JujuHarness, - LocalHarness, LXDHarness, MultipassHarness, ] diff --git a/tests/integration/tests/test_util/harness/base.py b/tests/integration/tests/test_util/harness/base.py index 7e01ea04f..d928afa70 100644 --- a/tests/integration/tests/test_util/harness/base.py +++ b/tests/integration/tests/test_util/harness/base.py @@ -43,8 +43,7 @@ def __str__(self) -> str: class Harness: """Abstract how integration tests can start and manage multiple machines. This allows - writing integration tests that can run on the local machine, LXD, or Multipass with minimum - effort. + writing integration tests that can run on LXD, or Multipass with minimum effort. """ name: str diff --git a/tests/integration/tests/test_util/harness/local.py b/tests/integration/tests/test_util/harness/local.py deleted file mode 100644 index 7c71b2970..000000000 --- a/tests/integration/tests/test_util/harness/local.py +++ /dev/null @@ -1,80 +0,0 @@ -# -# Copyright 2024 Canonical, Ltd. -# - -import logging -import shlex -import shutil -import socket -import subprocess -from pathlib import Path - -from test_util.harness import Harness, HarnessError, Instance -from test_util.util import run - -LOG = logging.getLogger(__name__) - - -class LocalHarness(Harness): - """A Harness that uses the local machine. Asking for more than 1 instance will fail.""" - - name = "local" - - def __init__(self): - super(LocalHarness, self).__init__() - self.initialized = False - self.hostname = socket.gethostname().lower() - - LOG.debug("Configured local substrate") - - def new_instance(self, network_type: str = "IPv4") -> Instance: - if self.initialized: - raise HarnessError("local substrate only supports up to one instance") - - if network_type != "IPv4": - raise HarnessError("Currently only IPv4 is supported by Local harness") - - self.initialized = True - LOG.debug("Initializing instance") - try: - self.exec(self.hostname, ["snap", "wait", "system", "seed.loaded"]) - except subprocess.CalledProcessError as e: - raise HarnessError("failed to wait for snapd seed") from e - - return Instance(self, self.hostname) - - def send_file(self, _: str, source: str, destination: str): - if not self.initialized: - raise HarnessError("no instance initialized") - - if not Path(destination).is_absolute(): - raise HarnessError(f"path {destination} must be absolute") - - LOG.debug("Copying file %s to %s", source, destination) - try: - self.exec( - _, ["mkdir", "-m=0777", "-p", Path(destination).parent.as_posix()] - ) - shutil.copy(source, destination) - except subprocess.CalledProcessError as e: - raise HarnessError("failed to copy file") from e - except shutil.SameFileError: - pass - - def pull_file(self, _: str, source: str, destination: str): - return self.send_file(_, destination, source) - - def exec(self, _: str, command: list, **kwargs): - if not self.initialized: - raise HarnessError("no instance initialized") - - LOG.debug("Executing command %s on %s", command, self.hostname) - return run(["sudo", "-E", "bash", "-c", shlex.join(command)], **kwargs) - - def delete_instance(self, _: str): - LOG.debug("Stopping instance") - self.initialized = False - - def cleanup(self): - LOG.debug("Stopping instance") - self.initialized = False