Skip to content

Commit

Permalink
Harmonize and document test modifier variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jan 19, 2024
1 parent ecf4e23 commit 4ce5688
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
22 changes: 21 additions & 1 deletion testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,28 @@ $ ./run.py
```

# Creating tests
All tests are based on running a Python script. There are three test drivers:
All tests are based on running a Python script. There are these test drivers:

- `python-script`: run in host in both sandboxed and shared build mode.
- The build mode can be narrowed down with the `build_mode` attribute.
- `docker-wrapper`: run in a pristine docker Ubuntu image in shared build mode.

# Environment variables
The following variables can be used to modify test/testsuite behavior.

For `ALIRE_DISABLE_*` variables, their mere existence activates their function,
no matter their value, or lack of one.

- `ALIRE_DISABLE_DISTRO`: when defined, `alr` will be configured
to not detect the system distribution and fall back to unknown distribution.

- `ALIRE_DISABLE_DOCKER`: when defined, `alr` will skip tests that
require Docker (which are enabled by default if Docker is detected).

- `ALIRE_DISABLE_NETWORK_TESTS`: when defined, tests that
require non-local network use will be skipped.

Example disabling Docker tests for a single run on Bash:
```Bash
$ ALIRE_DISABLE_DOCKER= ./run.sh
```
5 changes: 2 additions & 3 deletions testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ def prepare_env(config_dir, env):

# If distro detection is disabled via environment, configure so in alr
if "ALIRE_DISABLE_DISTRO" in env:
if env["ALIRE_DISABLE_DISTRO"] == "true":
run_alr("-c", config_dir, "config", "--global",
"--set", "distribution.disable_detection", "true")
run_alr("-c", config_dir, "config", "--global",
"--set", "distribution.disable_detection", "true")


def run_alr(*args, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions testsuite/drivers/driver/docker_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from drivers import alr
from drivers.alr import run_alr
from drivers.helpers import MODIFIERS


def main():
Expand All @@ -34,6 +35,10 @@ def main():

# Set up the environment

# Copy any received modifiers
for modifier in [m for m in MODIFIERS if m in test_env]:
os.environ[modifier] = test_env[modifier]

# alr path
os.environ["ALR_PATH"] = "/usr/bin/alr" # Must match docker volume mount

Expand Down
19 changes: 14 additions & 5 deletions testsuite/drivers/driver/docker_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from importlib import import_module
from typing import Tuple

from drivers.helpers import FileLock, on_linux
from drivers.helpers import FileLock, on_linux, MODIFIERS
from e3.testsuite.driver.classic import (ClassicTestDriver,
TestAbortWithFailure,
TestSkip)

DOCKERFILE = "Dockerfile"
TAG = "alire_testsuite"
ENV_FLAG = "ALIRE_DOCKER_ENABLED" # Set to "False" to disable docker tests
ENV_FLAG = "ALIRE_DISABLE_DOCKER" # Export it to disable docker tests
LABEL_HASH = "hash"


Expand All @@ -22,7 +22,7 @@ def is_docker_available() -> bool:
return False

# Detect explicitly disabled
if os.environ.get(ENV_FLAG, "True").lower() in ["0", "false"]:
if ENV_FLAG in os.environ:
return False

# Detect python library
Expand Down Expand Up @@ -102,6 +102,11 @@ def run(self):

build_image()

# Augment the test environment with local modifiers that could
# impact the wrapped test, if defined
for modifier in [m for m in MODIFIERS if m in os.environ]:
self.test_env[modifier] = os.environ[modifier]

# Run our things
try:
container = get_client().containers.run(
Expand Down Expand Up @@ -137,6 +142,10 @@ def run(self):

# Check that the test succeeded inside the docker container
out_lines = output.splitlines()
if not out_lines or out_lines[-1] != 'SUCCESS':
self.result.log += f'missing SUCCESS output line:\n{output}'
if out_lines and out_lines[-1] == 'SUCCESS':
pass
elif out_lines and (reason := out_lines[-1]).startswith('SKIP:'):
raise TestSkip(reason.split(":")[-1].strip())
else:
self.result.log += 'missing SUCCESS output line'
raise TestAbortWithFailure('missing SUCCESS output line')
8 changes: 7 additions & 1 deletion testsuite/drivers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
from subprocess import run
from zipfile import ZipFile

# Environment variables that can be used to modify the testsuite behavior
MODIFIERS : list = [
'ALIRE_DISABLE_DISTRO'
, 'ALIRE_DISABLE_DOCKER'
, 'ALIRE_DISABLE_NETWORK_TESTS'
]

# Return the entries (sorted) under a given folder, both folders and files
# Optionally, return only those matching regex. Uses '/' always as separator.
Expand Down Expand Up @@ -77,7 +83,7 @@ def on_windows():

def distribution():

if os.environ.get('ALIRE_DISABLE_DISTRO') == 'true':
if 'ALIRE_DISABLE_DISTRO' in os.environ:
return 'DISTRO_UNKNOWN'

known_distro = ["debian", "ubuntu", "msys2", "arch", "rhel", "centos", "fedora"]
Expand Down

0 comments on commit 4ce5688

Please sign in to comment.