Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tmt and packit ci configuration #18

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
44 changes: 0 additions & 44 deletions .github/workflows/verify.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Default packit instance is a prod and only this is used
# stg instance is present for testing new packit features in forked repositories where stg is installed.
packit_instances: ["prod", "stg"]
upstream_project_url: https://github.com/skodjob/streams-e2e
issue_repository: https://github.com/skodjob/streams-e2e
jobs:
- job: tests
trigger: pull_request
# Suffix for job name
identifier: "verify"
targets:
# This target is not used at all by our tests, but it has to be one of the available - https://packit.dev/docs/configuration/#aliases
- centos-stream-9-x86_64
# ARM is commented since apicurio-operator upstream is not supported on ARM
# - centos-stream-9-aarch64
# We don't need to build any packages for Fedora/RHEL/CentOS, it is not related to streams-e2e tests
skip_build: true
manual_trigger: true
env: { IP_FAMILY: ipv4 }
labels:
- verify
- dummy
tf_extra_params:
test:
tmt:
name: verify
###############################################################################################
73 changes: 73 additions & 0 deletions tmt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Testing farm

This document gives a detailed breakdown of the testing processes using testing farm service.

## Pre-requisites

* Python >=3.9
* TMT command line tool (optional) - for lint and check tmt formatted test plans and tests
* `pip install tmt[all]`
* Testing farm command line tool - for trigger your test plan in testing-farm
* `pip install tft-cli`

## Links

* [Test Management Tool (tmt)](https://tmt.readthedocs.io/en/latest/index.html)
* [Testing farm](https://docs.testing-farm.io/general/0.1/index.html)

## Current plans and tests
Plans are stored in [plans](./plans) folder, there is a file called `main.fmf` which contains test plan definition.
This definition is composed of hw requirements, prepare steps for created VM executor and specific plans. Specific
plan defines selectors for [tests](./tests) which should be executed.

### List of plans
* verify

## Usage

### Pre-requisites
1. Get API token for testing farm [(how-to obtain token)](https://docs.testing-farm.io/general/0.1/onboarding.html)
2. Store token into env var ```export TESTING_FARM_API_TOKEN="your_token"```

### Run tests

Run all plans
```commandline
testing-farm request --compose Fedora-38 --git-url https://github.com/skodjob/streams-e2e.git
```

Select specific plan and git branch
```commandline
testing-farm request --compose Fedora-38 \
--git-url https://github.com/skodjob/streams-e2e.git \
--git-ref some-branch \
--plan smoke
```

Run multi-arch build
```commandline
testing-farm request --compose Fedora-Rawhide \
--git-url https://github.com/skodjob/streams-e2e.git \
--git-ref some-branch \
--plan smoke \
--arch aarch64,x86_64
```

## Packit-as-a-service for PR check

[Packit-as-a-service](https://github.com/marketplace/packit-as-a-service) is a github application
for running testing-farm jobs from PR requested by command. Definition of the jobs is stored in
[.packit.yaml](../.packit.yaml). Packit can be triggered from the PR by comment, but only members of strimzi
organization are able to run tests.

### Usage

Run all jobs for PR
```
/packit test
```

Run selected jobs by label
```
/packit test --labels verify
```
120 changes: 120 additions & 0 deletions tmt/plans/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# TMT test plan definition
# https://tmt.readthedocs.io/en/latest/overview.html

# Baseline common for all test plans
#######################################################################
summary: Streams-e2e test suite
discover:
how: fmf

# Required HW
provision:
hardware:
memory: ">= 24 GiB"
cpu:
processors: ">= 8"
kornys marked this conversation as resolved.
Show resolved Hide resolved

# Install required packages and scripts for running streams-e2e suite
prepare:
- name: Clean cache
how : shell
script: |
OS=$(cat /etc/redhat-release || true)
if [[ ${OS} == *"CentOS"* ]]; then
sudo yum -y clean dbcache
else
sudo dnf -y clean dbcache
fi

- name: Install packages
how: install
package:
- wget
- java-17-openjdk-devel
- xz
- make
- git
- zip
- coreutils

- name: Install docker-ce
how: shell
script: |
OS=$(cat /etc/redhat-release || true)
if [[ ${OS} == *"CentOS"* ]]; then
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
else
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
fi

sudo yum install -y docker-ce
sudo systemctl enable docker --now

- name: Install yq
how: shell
script: |
ARCH=$(uname -m)
if [[ $ARCH == "x86_64" ]]; then ARCH="amd64"; fi
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi
./tmt/scripts/install_yq.sh ${ARCH}

- name: Install oc kubectl client
how: shell
script: |
PLATFORM=$(uname -m)
URL="http://mirror.openshift.com/pub/openshift-v4/${PLATFORM}/clients/ocp/stable/openshift-client-linux.tar.gz"
mkdir -p /tmp/openshift
wget ${URL} -O openshift.tar.gz -q
tar xzf openshift.tar.gz -C /tmp/openshift
sudo cp /tmp/openshift/oc /usr/bin/oc
sudo cp /tmp/openshift/kubectl /usr/bin/kubectl
sudo rm -rf /tmp/openshift/
sudo rm -rf openshift.tar.gz

- name: Install mvn
how: shell
script: |
mkdir -p /usr/share/maven /usr/share/maven/ref
curl -fsSL -o /tmp/apache-maven.tar.gz https://apache.osuosl.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1
rm -f /tmp/apache-maven.tar.gz
ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

- name: Install kind
how: shell
script: |
ARCH=$(uname -m)
if [[ $ARCH == "x86_64" ]]; then ARCH="amd64"; fi
if [[ $ARCH == "aarch64" ]]; then ARCH="arm64"; fi
./tmt/scripts/setup-kind.sh ${ARCH}

- name: Install helm
how: shell
script: |
./tmt/scripts/setup-helm.sh

- name: Install operator-sdk and olm
how: shell
script: |
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.36.0
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}
chmod +x operator-sdk_${OS}_${ARCH} && sudo mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk
operator-sdk olm install

# Discover tmt defined tests in tests/ folder
execute:
how: tmt

# Post install step to copy logs
finish:
how: shell
script: ./tmt/scripts/copy-logs.sh
#######################################################################

/verify:
summary: Run dummy streams-e2e test suite
discover+:
test:
- verify
15 changes: 15 additions & 0 deletions tmt/scripts/copy-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh -eux


TEST_LOG_DIR="${TMT_PLAN_DATA}/../discover/default-0/tests/target/logs"
XUNIT_LOG_DIR="${TMT_PLAN_DATA}/../discover/default-0/tests/target/failsafe-reports"

TARGET_DIR="${TMT_PLAN_DATA}"
LOGS_DIR="${TARGET_DIR}/logs"
XUNIT_DIR="${TARGET_DIR}/xunit"

mkdir -p "${LOGS_DIR}"
mkdir -p "${XUNIT_DIR}"

cp -R "${TEST_LOG_DIR}" "${LOGS_DIR}" || true
cp -R "${XUNIT_LOG_DIR}" "${XUNIT_DIR}" || true
9 changes: 9 additions & 0 deletions tmt/scripts/install_yq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

ARCH=$1
if [ -z "$ARCH" ]; then
ARCH="amd64"
fi

curl -L https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_${ARCH} > yq && chmod +x yq
kornys marked this conversation as resolved.
Show resolved Hide resolved
sudo mv yq /usr/bin/
44 changes: 44 additions & 0 deletions tmt/scripts/setup-helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -x

TEST_HELM3_VERSION=${TEST_HELM3_VERSION:-'v3.15.1'}
TEST_HELM_UNITTEST_VERSION=${TEST_HELM_UNITTEST_VERSION:-'v0.5.1'}

function install_helm3 {
export HELM_INSTALL_DIR=/usr/bin
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
# we need to modify the script with a different path because on the Azure pipelines the HELM_INSTALL_DIR env var is not honoured
sed -i 's#/usr/local/bin#/usr/bin#g' get_helm.sh
chmod 700 get_helm.sh

echo "Installing helm 3..."
sudo ./get_helm.sh --version "${TEST_HELM3_VERSION}"

echo "Verifying the installation of helm binary..."
# run a proper helm command instead of, for example, "which helm", to verify that we can call the binary
helm --help
helmCommandOutput=$?

if [ $helmCommandOutput != 0 ]; then
echo "helm binary hasn't been installed properly - exiting..."
exit 1
fi
}

function install_helm_unittest {
echo "Installing helm unittest plugin ..."
helm plugin install --version $TEST_HELM_UNITTEST_VERSION https://github.com/helm-unittest/helm-unittest.git

echo "Verifying the installation of helm unittest plugin ..."
# run a proper helm command instead of, for example, "which helm", to verify that we can call the binary
helm unittest --help
helmCommandOutput=$?

if [ $helmCommandOutput != 0 ]; then
echo "helm unittest plugin hasn't been installed properly - exiting..."
exit 1
fi
}

install_helm3
install_helm_unittest
Loading