Skip to content

Commit

Permalink
integration: completely remove LocalHarness. (#912)
Browse files Browse the repository at this point in the history
The LocalHarness is a harness used for running integration tests
on the local machine where the tests are directly invoked
(be it via `tox`, `pytest`, etc).

It presents numerous limitations (can't run any multi-node tests)
and poses a lot of potential risks (cleanup failing in case of
fatal errors in the test fixtures) which outweighs most of its
convenience benefits (especially when compared to the LXD
substrate).

This patch completely removes the LocalHarness and all references to it
from the documentation, making LXD the new default.

Signed-off-by: Nashwan Azhari <[email protected]>
  • Loading branch information
Nashwan Azhari authored Dec 18, 2024
1 parent 5c3e5e0 commit e37327f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 102 deletions.
13 changes: 1 addition & 12 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,15 @@ 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()
elif config.SUBSTRATE == "juju":
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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tests/test_util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/tests/test_util/harness/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,7 +11,6 @@
Harness,
Instance,
JujuHarness,
LocalHarness,
LXDHarness,
MultipassHarness,
]
3 changes: 1 addition & 2 deletions tests/integration/tests/test_util/harness/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 0 additions & 80 deletions tests/integration/tests/test_util/harness/local.py

This file was deleted.

0 comments on commit e37327f

Please sign in to comment.