From 8e9ff0998eb56a17a0ee7cb99d4399bbff828ea8 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Fri, 15 Nov 2024 16:51:43 +0100 Subject: [PATCH 1/2] fix: Renamed integration-tests to cockpit-tests * Card ID: CCT-741 * The new name describes better the purpose of the directory * We are going to add real integration tests and there would be interference in names --- .cockpit-ci/run | 2 +- {integration-tests => cockpit-tests}/run | 10 +++++----- {integration-tests => cockpit-tests}/vm.install | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename {integration-tests => cockpit-tests}/run (86%) rename {integration-tests => cockpit-tests}/vm.install (100%) diff --git a/.cockpit-ci/run b/.cockpit-ci/run index 2400c9fa6e..dc220f39bd 120000 --- a/.cockpit-ci/run +++ b/.cockpit-ci/run @@ -1 +1 @@ -../integration-tests/run \ No newline at end of file +../cockpit-tests/run \ No newline at end of file diff --git a/integration-tests/run b/cockpit-tests/run similarity index 86% rename from integration-tests/run rename to cockpit-tests/run index a414cc413f..a442cb3e0d 100755 --- a/integration-tests/run +++ b/cockpit-tests/run @@ -6,8 +6,8 @@ # like this: # # $ export TEST_OS=rhel-8-4 -# $ ./integration-tests/run prepare -# $ ./integration-tests/check-subscriptions -v -j1 -t +# $ ./cockpit-tests/run prepare +# $ ./cockpit-tests/check-subscriptions -v -j1 -t # # You need a couple of things installed for that. At least Python 3, # a Chromium browser, and libvirtd. See @@ -20,7 +20,7 @@ ifeq ($(TEST_OS),) TEST_OS = rhel-8-4 endif export TEST_OS -SUB_MAN_COCKPIT=$(CURDIR)/integration-tests/submancockpit +SUB_MAN_COCKPIT=$(CURDIR)/cockpit-tests/submancockpit VM_IMAGE=$(SUB_MAN_COCKPIT)/test/images/$(TEST_OS).qcow2 SUBMAN_TAR=$(CURDIR)/dist/subscription-manager.tar.gz SMBEXT_TAR=$(CURDIR)/dist/subscription-manager-build-extra.tar.gz @@ -45,7 +45,7 @@ $(SUBMAN_TAR): $(SMBEXT_TAR): tar czf $(SMBEXT_TAR) build_ext -$(VM_IMAGE): $(SUB_MAN_COCKPIT) $(SUBMAN_TAR) $(SMBEXT_TAR) integration-tests/vm.install +$(VM_IMAGE): $(SUB_MAN_COCKPIT) $(SUBMAN_TAR) $(SMBEXT_TAR) cockpit-tests/vm.install rm -f $(VM_IMAGE) # setup the test image from subscription-manager-cockpit without # a custom subscription-manager, which will be installed manually @@ -54,7 +54,7 @@ $(VM_IMAGE): $(SUB_MAN_COCKPIT) $(SUBMAN_TAR) $(SMBEXT_TAR) integration-tests/vm cd $(SUB_MAN_COCKPIT) && bots/image-customize -v $(TEST_OS) \ -u $(SUBMAN_TAR):/var/tmp/ \ -u $(SMBEXT_TAR):/var/tmp/ \ - -s ../../integration-tests/vm.install + -s ../../cockpit-tests/vm.install $(SUB_MAN_COCKPIT): git clone --quiet https://github.com/candlepin/subscription-manager-cockpit.git $(SUB_MAN_COCKPIT) diff --git a/integration-tests/vm.install b/cockpit-tests/vm.install similarity index 100% rename from integration-tests/vm.install rename to cockpit-tests/vm.install From 57231d6d81d50890141e402b8a71129d79b58ee3 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Mon, 18 Nov 2024 11:08:13 +0100 Subject: [PATCH 2/2] 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