Skip to content

Commit

Permalink
feat: basic integration testing with packit + testing-farm + tmt (#158)
Browse files Browse the repository at this point in the history
* feat: basic integration testing with tmt

Introduce a minimal setup for integration tests of insights-client.
The tests are written using pytest and an helper plugin for
insights-client and other Red Hat client tools [1].

The tests are wrapped as single "integration" test for tmt [2], which
makes it possible to run them automatically e.g. in testing-farm.

There is a simple test added to show how the setup for the tests works.

[1] https://github.com/ptoscano/pytest-client-tools/
[2] https://github.com/teemtee/tmt/

Signed-off-by: Pino Toscano <[email protected]>

* feat: run integration tests in testing-farm

Extend the packit configuration to trigger tests on testing-farm after
the completion of the build jobs.

The tests are split for the different distributions supported; this is
due to the current limitation of testing-farm in the way additional
repositories can be supplied: as the name of a Fedora Copr repository
cannot be specified, each distribution needs to get the repository URL
for it.

Manually specify the RHEL targets/composes due to the limitations in the
packit<->testing-farm mapping of RHEL composes.

Signed-off-by: Pino Toscano <[email protected]>

* fix: workaround newer gnupg & insights-core/insights-client

It looks like gnupg as available in Fedora 39 and newer does not
validate anymore signatures in case their key is not part of the current
keyring (which is what insights-client does).

Since the way both insights-core and insights-client validate GPG
signatures is being reworked/improved [1][2], add a crude workaround on
Fedora 39+.

[1] RedHatInsights/insights-core#3930
[2] #154

Signed-off-by: Pino Toscano <[email protected]>

---------

Signed-off-by: Pino Toscano <[email protected]>
  • Loading branch information
ptoscano authored Jan 5, 2024
1 parent 3b4cde9 commit 20c3287
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions .fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
46 changes: 46 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,49 @@ jobs:
- fedora-all
- rhel-8
- rhel-9

- job: tests
trigger: pull_request
identifier: "unit/centos-stream"
targets:
- centos-stream-8
- centos-stream-9
labels:
- unit
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/yggdrasil/latest/repo/centos-stream-$releasever/group_yggdrasil-latest-centos-stream-$releasever.repo

- job: tests
trigger: pull_request
identifier: "unit/fedora"
targets:
- fedora-all
labels:
- unit
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/yggdrasil/latest/repo/fedora-$releasever/group_yggdrasil-latest-fedora-$releasever.repo

- job: tests
trigger: pull_request
identifier: "unit/rhel"
targets:
rhel-8-x86_64:
distros:
- RHEL-8-Released
rhel-9-x86_64:
distros:
- RHEL-9.4.0-Nightly
labels:
- unit
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/yggdrasil/latest/repo/rhel-$releasever/group_yggdrasil-latest-rhel-$releasever.repo
use_internal_tf: true
1 change: 1 addition & 0 deletions integration-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/ptoscano/pytest-client-tools@main
4 changes: 4 additions & 0 deletions integration-tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_version(insights_client):
proc = insights_client.run("--version")
assert b"Client: " in proc.stdout
assert b"Core: " in proc.stdout
6 changes: 6 additions & 0 deletions systemtest/plans/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
summary: rhc test suite
discover:
how: fmf

execute:
how: tmt
3 changes: 3 additions & 0 deletions systemtest/tests/integration/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
summary: Runs tmt tests
test: ./test.sh
duration: 10m
28 changes: 28 additions & 0 deletions systemtest/tests/integration/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -eu
set -x

. /etc/os-release
if test "${ID}" = fedora -a ${VERSION_ID} -ge 39; then
# HACK
# on newer gnupg import the key to the local keyring; this will be solved
# once both insights-core and insights-client are fixed to not rely on
# root's .gnupg directory:
# - https://github.com/RedHatInsights/insights-core/pull/3930
# - https://github.com/RedHatInsights/insights-client/pull/154
gpg --import /etc/insights-client/redhattools.pub.gpg
fi

# get to project root
cd ../../../

dnf --setopt install_weak_deps=False install -y \
podman git-core python3-pip python3-pytest

python3 -m venv venv
# shellcheck disable=SC1091
. venv/bin/activate

pip install -r integration-tests/requirements.txt

pytest -v integration-tests

0 comments on commit 20c3287

Please sign in to comment.