From 5365981e87f15178200ef3a846b974b4b530c8a9 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Mon, 18 Nov 2024 11:08:13 +0100 Subject: [PATCH] feat: Add initial support for tmt * Card ID: CCT-741 * Added basic configuration for tmt - subscription-manager is installed from COPR build - Python virtual environment is created - Install testing framework - Some simple smoke test is run (busctl calls RHSM D-Bus method) --- .packit.yml | 26 ++++++++++++++++++++++ integration-tests/__init__.py | 0 integration-tests/requirements.txt | 3 +++ integration-tests/test_consumer.py | 24 +++++++++++++++++++++ systemtest/.fmf/version | 1 + systemtest/copr-setup.sh | 16 ++++++++++++++ systemtest/plans/main.fmf | 5 +++++ systemtest/tests/integration/main.fmf | 3 +++ systemtest/tests/integration/test.sh | 31 +++++++++++++++++++++++++++ 9 files changed, 109 insertions(+) create mode 100644 integration-tests/__init__.py create mode 100644 integration-tests/requirements.txt create mode 100644 integration-tests/test_consumer.py create mode 100644 systemtest/.fmf/version create mode 100644 systemtest/copr-setup.sh create mode 100644 systemtest/plans/main.fmf create mode 100644 systemtest/tests/integration/main.fmf create mode 100644 systemtest/tests/integration/test.sh diff --git a/.packit.yml b/.packit.yml index 8bffe1f543..2f7be44275 100644 --- a/.packit.yml +++ b/.packit.yml @@ -18,3 +18,29 @@ jobs: targets: - centos-stream-10 - fedora-all + +# - job: tests +# trigger: pull_request +# identifier: "unit/centos-stream" +# targets: +# - centos-stream-10 +# 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 diff --git a/integration-tests/__init__.py b/integration-tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/integration-tests/requirements.txt b/integration-tests/requirements.txt new file mode 100644 index 0000000000..94f0c45d60 --- /dev/null +++ b/integration-tests/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/ptoscano/pytest-client-tools@main +pyyaml +sh diff --git a/integration-tests/test_consumer.py b/integration-tests/test_consumer.py new file mode 100644 index 0000000000..aebcbdc9c9 --- /dev/null +++ b/integration-tests/test_consumer.py @@ -0,0 +1,24 @@ +""" +This Python module contains integration tests for rhc. +It uses pytest-client-tools Python module.More information about this +module could be found: https://github.com/ptoscano/pytest-client-tools/ +""" + +import contextlib +import sh + + +def test_busctl_get_consumer_uuid(): + """ + Simple smoke test using busctl CLI tool. It tries to call simple D-Bus method. + """ + with contextlib.suppress(Exception): + sh.busctl( + "call", + "com.redhat.RHSM1", + "/com/redhat/RHSM1/Consumer", + "com.redhat.RHSM1.Consumer", + "GetUuid", + "s", + '""', + ) diff --git a/systemtest/.fmf/version b/systemtest/.fmf/version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/systemtest/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/systemtest/copr-setup.sh b/systemtest/copr-setup.sh new file mode 100644 index 0000000000..b62fd60500 --- /dev/null +++ b/systemtest/copr-setup.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash -eux +dnf install -y dnf-plugins-core + +# Determine the repo needed from copr +source /etc/os-release + +if [ "$ID" == "centos" ]; then + ID='centos-stream' +fi +VERSION_MAJOR=$(echo "${VERSION_ID}" | cut -d '.' -f 1) +COPR_REPO="${ID}-${VERSION_MAJOR}-$(uname -m)" + +# Install subscription-manager from COPR repository +dnf remove -y --noautoremove subscription-manager +dnf copr -y enable packit/candlepin-subscription-manager-"${ghprbPullId}" "${COPR_REPO}" +dnf install -y subscription-manager --disablerepo=* --enablerepo=*subscription-manager* diff --git a/systemtest/plans/main.fmf b/systemtest/plans/main.fmf new file mode 100644 index 0000000000..af4bed151e --- /dev/null +++ b/systemtest/plans/main.fmf @@ -0,0 +1,5 @@ +summary: rhsm test suite +discover: + how: fmf +execute: + how: tmt diff --git a/systemtest/tests/integration/main.fmf b/systemtest/tests/integration/main.fmf new file mode 100644 index 0000000000..9d6c3e5b57 --- /dev/null +++ b/systemtest/tests/integration/main.fmf @@ -0,0 +1,3 @@ +summary: Runs tmt tests +test: ./test.sh +duration: 1h diff --git a/systemtest/tests/integration/test.sh b/systemtest/tests/integration/test.sh new file mode 100644 index 0000000000..2c59a81911 --- /dev/null +++ b/systemtest/tests/integration/test.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -ux + +# get to project root +cd ../../../ + +# Check for GitHub pull request ID and install build if needed. +# This is for the downstream PR jobs. +[ -z "${ghprbPullId+x}" ] || ./systemtest/copr-setup.sh + +dnf --setopt install_weak_deps=False install -y \ + podman git-core python3-pip python3-pytest logrotate + +python3 -m venv venv +# shellcheck disable=SC1091 +. venv/bin/activate + +# Install requirements for integration tests +pip install -r integration-tests/requirements.txt + +# Run all integration tests +pytest --junit-xml=./junit.xml -v integration-tests +retval=$? + +# Copy artifacts of integration tests +if [ -d "$TMT_PLAN_DATA" ]; then + cp ./junit.xml "$TMT_PLAN_DATA/junit.xml" +fi + +# Return exit code of integration tests +exit $retval