Standard Test Interface
Standard Discovery, Staging and Invocation of Integration Tests.
Version: 2.0.0
Summary
Let’s define a clear delineation of between a test suite (including framework) and the CI system that is running the test suite. This is the standard interface. What follows is a standard way to discover, package and invoke integration tests for a package stored in a Fedora dist-git repo.
Many Fedora packages have unit tests. These tests are typically run during a %check
RPM build step and run in a build root. On the other hand, integration testing should happen against a composed system. Upstream projects have integration tests, both Fedora QA and the Atomic Host team would like to create more integration tests, Red Hat would like to bring integration tests upstream.
Benefit to Fedora
Developers benefit by having a consistent target for how to describe tests, while also being able to execute them locally while debugging issues or iterating on tests.
By staging and invoking tests consistently in Fedora we create an eco-system for the tests that allows varied test frameworks as well as CI system infrastructure to interoperate. The integration tests outlast the implementation details of either the frameworks they’re written in or the CI systems running them.
Definitions
Terminology
- Test Subject
-
The items that are to be tested. Examples: RPMs, OCI image, ISO, QCow2, Module repository …
- Test
-
A callable/runnable piece of code and corresponding test data and mocks which exercises and evaluates a test subject.
- Test environment
-
Environment where actual test run takes place. Test has direct impact on test environment.
- Test Suite
-
The collection of all tests that apply to a test subject.
- Test Framework
-
A library or component that the test suite and tests use to accomplish their job. Examples: Avocado, GNOME Installed Tests, Meta Test Family, Ansible tests in Atomic Host, Tunir tests, docker test images…
- Test Result
-
A boolean pass/fail output of a test suite. Test results_ are for consumption by automated aspects of a testing systems.
- Test Artifact
-
Any additional output of the test suite such as the stdout/stderr output, log files, screenshots, core dumps, or TAP/Junit/subunit streams. Test artifacts are for consumption by humans, archival or big data analysis.
- Testing System
-
A CI or other testing system that would like to discover, stage and invoke tests for a test subject. Examples: Jenkins, Taskotron, ZUUL, CentOS CI, Papr, Travis, Semaphore, Openshift CI/CD, Ubuntu CI…
- Test Runner
-
Testing system delegates running of the test to test runner which can be different from test environment. For example ansible is run on the test runner and tests are executed on the managed host. Usually a stable version of OS is used for test runner.
Results Format
The following format should be used to report results of individual tests in the results.yml
file:
results: - {result: pass, test: test1, logs: [test1.log]} - {result: fail, test: test2, logs: [test2.log, debug.log]} - {result: error, test: test3, logs: [test3.log, debug.log, error.log]}
- result
-
Test result. One of
pass
,fail
orerror
. Mandatory. - test
-
Test name. A unique identifier. Mandatory.
- logs
-
One or more logs with detailed test output. Optional. Path should be relative to the artifacts directory. Some user interfaces might show only a single log by default. In that case first log from the list should be presented to the user.
The result
field can contain following values:
- pass
-
Test has successfully finished and passed.
- fail
-
Test has successfully finished and failed.
- error
-
There has been a problem with test execution.
Responsibilities
The Testing System is responsible to:
-
Build or otherwise acquire the test subject, such as a package, container image, tree…
-
Decide which test suite to run, often by using the standard interface to discover appropriate tests for the dist-git repo that a test subject originated in.
-
Schedule, provision or orchestrate a job to run the test suite on appropriate compute, storage…
-
Stage the test suite as described by the standard interface.
-
Invoke the test suite as described by the standard interface.
-
Gather the test results and test artifacts as described by the standard interface.
-
Announce and relay the test results and test artifacts for gating, archival…
The Standard Interface describes how to:
-
Discover a test suite for a given dist-git repo.
-
Uniquely identify a test suite.
-
Stage a test suite and its dependencies such as test frameworks.
-
Provide the test subject to the test suite.
-
Invoke a test suite in a consistent way.
-
Gather test results and test artifacts from the invoked test suite.
The Test Suite is responsible to:
-
Declare its dependencies such as a test framework via the standard interface.
-
Execute the test framework as necessary.
-
Provision (usually locally) any containers or virtual machines necessary for testing the test subject.
-
Provide test results and test subjects back according to the standard
The format of the textual logs and test artifacts that come out of a test suite is not prescribed by this document. Nor is it envisioned to be standardized across all possible test suites.
Requirements
-
The test suite and test framework SHOULD NOT leak its implementation details into the testing system, other than via the standard interface.
-
The test suite and test framework SHOULD NOT rely on the behavior of the testing system other than the standard interface.
-
The standard interface MUST enable a dist-git packager to run a test suite locally.
-
Test suites or test frameworks MAY call out to the network for certain tasks.
-
-
It MUST be possible to stage an upstream test suite using the standard interface.
-
Both in-situ tests, and more rigorous outside-in tests MUST be possible with the standard interface.
-
For in-situ tests the test suite is in the same file system tree and process space as the test subject.
-
For outside-in tests the test suite is outside of the file system tree and process space of the test subject.
-
-
The test suite and test framework SHOULD be able to provision containers and virtual machines necessary for its testing without requesting them from the testing system.
-
The standard interface SHOULD describe how to uniquely identify a test suite.
Detailed Description
This standard interface describes how to discover, stage and invoke tests. It is important to cleanly separate implementation details of the testing system from the test suite and its framework. It is also important to allow Fedora packagers to locally and manually invoke a test suite.
First see the Terminogy, division of Responsibilities and Requirements.
Staging
Tests files will be added into the tests/
folder of a dist-git repository branch. The structure of the files and folders is left to the liberty of the packagers but there are one or more playbooks in the tests/
folder that can be invoked to run the test suites.
-
The testing system SHOULD stage the tests on target (eg: Fedora) operating system appropriate for the branch name of the dist-git repository containing the tests.
-
The testing system SHOULD stage a clean test runner for each set of tests it runs.
-
The testing system MUST stage the following package on the test runner:
-
standard-test-roles
-
-
The testing system MUST clone the dist-git repository for the test on the test runner, and checks out the appropriate branch.
-
The contents of
/etc/yum.repos.d
on the staged system SHOULD be replaced with repository information that reflects the known good Fedora packages corresponding to the branch of the dist-git repository.-
The testing system MAY use multiple repositories, including updates or updates-testing to ensure this.
-
Invocation
The testing system MUST run each playbook matching the glob tests/tests*.yml
in the dist-git repo. Each of these files constitutes a test suite. Each test suite is invoked by the testing system independently and executed in a clear test environment as follows.
The test subjects are passed to the playbook and inventory as operating system environment and ansible environment. Often only one test subject is passed in. However multiple subjects may be concatenated together in a shell escaped string. The playbooks and/or inventory script split the string. The extensions as follows are used to determine the type of subject:
- *.rpm
-
Absolute path to an RPM file
- *.repo
-
Absolute repo filenames appropriate for
/etc/yum.repos.d
- *.qcow2, *.qcow2c
-
Absolute path to one virtual machine disk image bootable with cloud-init
- *.oci
-
Absolute path of one OCI container image filesystem bundle
- docker:*
-
Fully qualified path to a docker image in a registry
- …
-
Other test subject identifiers may be added later.
Various tests in a playbook constitute a test suite. Some parts of these test suites will run in certain contexts, against certain deliverable artifacts. Certain tests will run against Atomic Host deliverables, while others will not. Certain tests will run against Docker deliverables while others will not. This is related to, but does not exactly overlap with the test subject identifiers above. Ansible tags are used to denote these contexts.
- atomic
-
Atomic Host
- container
-
A Docker or OCI container
- classic
-
Tested against a classic installed YUM/DNF installed system.
- …
-
Other test subject identifiers may be added later.
To invoke the tests, the testing system must perform the following tasks for each test suite playbook:
-
MUST execute the playbook with the following operating system environment variables:
-
TEST_SUBJECTS
: The test subjects string as described above -
TEST_ARTIFACTS
: The full path of an empty folder for test artifacts
-
-
SHOULD execute the playbook with all Ansible tags best represent the intended test context.
-
The choice of test context tags is related to the test subject being tested
-
-
MUST execute Ansible with inventory set to the full path of the file or directory
tests/inventory
if it exists.-
If the
tests/inventory
file doesn’t exist, then/usr/share/ansible/inventory
SHOULD be used as a default.
-
-
MUST execute the playbook as root.
-
MUST execute the playbook passing
git_branch
as ansible variable.-
The branch used to clone tests*.yml
-
-
MUST examine the exit code of the playbook. A zero exit code means tests completed successfully, non-zero means a problem with running tests.
-
MUST examine the file
results.yml
in theartifacts
folder to detect whether tests passed of failed. -
MUST treat the file
test.log
in theartifacts
folder as the main readable output of the test. -
SHOULD place the textual stdout/stderr of the
ansible-playbook
command in theansible.log
file in theartifacts
folder. -
SHOULD treat the contents of the
artifacts
folder as the test artifacts.
Each test suite playbook or test framework contained therein:
-
SHOULD drop privileges appropriately if the test suite should be run as non-root.
-
MUST install any requirements of its test suite or test framework and MUST fail if this is not possible.
-
MUST provision the test subject listed in the
subjects
variable appropriately for its playbook name (described above) and MUST fail if this is not possible. -
MUST place the main readable output of the test suite into a
test.log
file in theartifacts
variable folder. This MUST happen even if some of the test suites fail. -
SHOULD place additional test artifacts in the folder defined in the
artifacts
variable. -
MUST return a zero exit code of the playbook if tests have been executed successfully, or a non-zero exit code if failed to run any test (e.g. because of an infrastructure error).
-
MUST create a
results.yml
file in theartifacts
directory with test results in the results format defined above.
If an inventory file or script exists, it:
-
MUST describe where to invoke the playbook and how to connect to that target.
-
SHOULD launch or install any supported
$TEST_SUBJECTS
so that the playbook can be invoked against them. -
SHOULD put relevant logs in the
$TEST_ARTIFACTS
directory.
Scope
Since the tests are added in a sub-folder of the dist-git repo, there are no changes required to the Fedora infrastructure and will have no impact on the packagers' workflow and tooling.
Only the testing system will need to be taught to install the requirements and run the playbooks.
User Experience
A standard way to package, store and run tests benefits Fedora stability, and makes Fedora better for users.
-
This structure makes it easy to run locally thus potentially reproducing an error triggered on the test system.
-
Ansible is being more and more popular, thus making it easier for people to contribute new tests
-
Used by a lot of sys-admin, ansible could help sys-admin to bring test-cases to the packagers and developers about situation where something failed for them.
Upgrade/compatibility impact
There are no real upgrade or compatibility impact. The tests will be branched per release as spec files are branched dist-git is now.
Proposals and Evaluation
During the selection process for a standard test invocation and layout format for Fedora, several proposals were examined.
Contact
-
Name: Stef Walter, stefw@fedoraproject.org
-
Name: Pierre-Yves Chibon, pingou@fedoraproject.org
-
Name: Andrei Stepanov
-
Name: Serhii Turivnyi, sturivny@fedoraproject.org
Want to help? Learn how to contribute to Fedora Docs ›