Skip to content

[skip-ci] TMT: initial enablement #820

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ vendor/
.idea/*
contrib/systemd/*/*.service
.vscode*
rpm/RPMS
rpm/SRPMS
rpm/*.tar.gz
91 changes: 84 additions & 7 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,40 @@
downstream_package_name: netavark
upstream_tag_template: v{version}

# These files get synced from upstream to downstream (Fedora / CentOS Stream) on every
# propose-downstream job. This is done so tests maintained upstream can be run
# downstream in Zuul CI and Bodhi.
# Ref: https://packit.dev/docs/configuration#files_to_sync
files_to_sync:
- src: rpm/gating.yaml
dest: gating.yaml
delete: true
- src: plans/
dest: plans/
delete: true
mkpath: true
- src: test/tmt
dest: test/tmt
delete: true
mkpath: true
- src: test-dhcp/tmt
dest: test-dhcp/tmt
delete: true
mkpath: true
- src: .fmf/
dest: .fmf/
delete: true
- .packit.yaml

packages:
netavark-fedora:
pkg_tool: fedpkg
specfile_path: rpm/netavark.spec
netavark-centos:
pkg_tool: centpkg
specfile_path: rpm/netavark.spec
netavark-eln:
specfile_path: rpm/netavark.spec

srpm_build_deps:
- cargo
Expand All @@ -22,12 +49,21 @@ jobs:
- job: copr_build
trigger: pull_request
packages: [netavark-fedora]
notifications: &copr_build_failure_notification
failure_comment:
message: "Ephemeral COPR build failed. @containers/packit-build please check."
#notifications: &copr_build_failure_notification
# failure_comment:
# message: "Ephemeral COPR build failed. @containers/packit-build please check."
targets: &fedora_copr_targets
- fedora-all-x86_64
- fedora-all-aarch64
enable_net: true

- job: copr_build
trigger: ignore
packages: [netavark-eln]
#notifications: &copr_build_failure_notification
# failure_comment:
# message: "Ephemeral COPR build failed. @containers/packit-build please check."
targets:
fedora-all-x86_64: {}
fedora-all-aarch64: {}
fedora-eln-x86_64:
additional_repos:
- "https://kojipkgs.fedoraproject.org/repos/eln-build/latest/x86_64/"
Expand All @@ -39,8 +75,8 @@ jobs:
- job: copr_build
trigger: pull_request
packages: [netavark-centos]
notifications: *copr_build_failure_notification
targets:
#notifications: *copr_build_failure_notification
targets: &centos_copr_targets
- centos-stream-9-x86_64
- centos-stream-9-aarch64
- centos-stream-10-x86_64
Expand All @@ -59,6 +95,47 @@ jobs:
project: podman-next
enable_net: true

# validate and unit tests
# rpm independent and sufficient to run on only one env
- job: tests
trigger: pull_request
packages: [netavark-fedora] # Include this else it will create multiple jobs
skip_build: true
targets:
- fedora-latest-stable
tmt_plan: "/plans/no-rpm"
identifier: "no-rpm"

- job: tests
trigger: pull_request
packages: [netavark-fedora]
#notifications:
#failure_comment:
# message: "TMT tests failed. @containers/packit-build please check."
targets: *fedora_copr_targets
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/repo/fedora-$releasever/rhcontainerbot-podman-next-fedora-$releasever.repo
tmt_plan: "/plans/rpm"
identifier: "rpm-fedora"

- job: tests
trigger: pull_request
packages: [netavark-centos]
#notifications:
#failure_comment:
# message: "TMT tests failed. @containers/packit-build please check."
targets: *centos_copr_targets
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/repo/centos-stream-$releasever/rhcontainerbot-podman-next-centos-stream-$releasever.repo
tmt_plan: "/plans/rpm"
identifier: "rpm-centos"

# Sync to Fedora
- job: propose_downstream
trigger: release
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ NV_UNIT_FILES = contrib/systemd/system/netavark-dhcp-proxy.service \
.PHONY: install
install: $(NV_UNIT_FILES)
install ${SELINUXOPT} -D -m0755 bin/netavark $(DESTDIR)$(LIBEXECPODMAN)/netavark
install ${SELINUXOPT} -D -m0755 bin/netavark-dhcp-proxy-client $(DESTDIR)$(LIBEXECPODMAN)/netavark-dhcp-proxy-client
$(MAKE) -C docs install
install ${SELINUXOPT} -m 755 -d ${DESTDIR}${SYSTEMDDIR}
install ${SELINUXOPT} -m 644 contrib/systemd/system/netavark-dhcp-proxy.socket ${DESTDIR}${SYSTEMDDIR}/netavark-dhcp-proxy.socket
Expand Down
43 changes: 43 additions & 0 deletions plans/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
discover:
how: fmf
execute:
how: tmt
prepare:
- when: distro == centos-stream or distro == rhel
how: shell
script: |
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm --eval '%{?rhel}').noarch.rpm
dnf -y config-manager --set-enabled epel
order: 10
- when: initiator == packit
how: shell
script: |
COPR_REPO_FILE="/etc/yum.repos.d/*podman-next*.repo"
if compgen -G $COPR_REPO_FILE > /dev/null; then
sed -i -n '/^priority=/!p;$apriority=1' $COPR_REPO_FILE
fi
dnf -y upgrade --allowerasing
order: 20

provision:
how: artemis
hardware:
memory: ">= 16 GB"
cpu:
cores: ">= 4"
threads: ">=8"
disk:
- size: ">= 512 GB"

/no-rpm:
summary: Run tests independent of rpm
discover+:
filter: tag:no-rpm
adjust+:
- enabled: false
when: initiator is not defined or initiator != packit

/rpm:
summary: Run tests on the rpm
discover+:
filter: tag:rpm
16 changes: 16 additions & 0 deletions rpm/gating.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- !Policy
product_versions:
- fedora-*
decision_context:
- bodhi_update_push_stable
- bodhi_update_push_testing
subject_type: koji_build
rules:
- !PassingTestCaseRule {test_case_name: fedora-ci.koji-build.tier0.functional}

--- !Policy
product_versions:
- rhel-*
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}
44 changes: 44 additions & 0 deletions rpm/netavark.spec
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ Its features include:
* Support for IPv4 and IPv6
* Support for container DNS resolution via aardvark-dns.

# Only intended to be used for gating tests
# End user usecases not supported
%package tests
Summary: Tests for %{name}
Requires: %{name} = %{epoch}:%{version}-%{release}
%if %{defined bats_ofc}
Requires: bats
%else
Recommends: bats
%endif
Requires: bind-utils
Requires: dbus-daemon
Requires: dnsmasq
Requires: firewalld
Requires: iptables
Requires: jq
Requires: net-tools
Requires: nftables
Requires: nmap-ncat

%description tests
%{summary}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this discussion recently about the podman RHEL rpm that this is not supported. So we should make sure if this ever gets top RHEL we do not ship it outside of the gating env if possible (i.e. follow whatever we decided to do with the podman rpm).

Outside of the bats test we do not support these examples either upstream. So maybe add the description here that these are test only binaries for gating and not recommended/supported for any other use.


%prep
%autosetup -Sgit %{name}-%{version}
# Following steps are only required on environments like koji which have no
Expand All @@ -104,18 +127,30 @@ tar fx %{SOURCE1}

%build
NETAVARK_DEFAULT_FW=%{default_fw} %{__make} CARGO="%{__cargo}" build
%{__make} CARGO="%{__cargo}" build_proxy_client
%if (0%{?fedora} || 0%{?rhel} >= 10) && !%{defined copr_username}
%cargo_license_summary
%{cargo_license} > LICENSE.dependencies
%cargo_vendor_manifest
%endif

# Build examples package for tests
%{__make} CARGO="%{__cargo}" examples

cd docs
%{__make}

%install
%{__make} DESTDIR=%{buildroot} PREFIX=%{_prefix} install

%{__install} -d -p %{buildroot}%{_datadir}/%{name}/{examples,test,test-dhcp}
%{__cp} -rpav targets/release/examples/* %{buildroot}%{_datadir}/%{name}/examples
%{__cp} -rpav test/* %{buildroot}%{_datadir}/%{name}/test
%{__cp} -rpav test-dhcp/* %{buildroot}%{_datadir}/%{name}/test-dhcp

%{__rm} -rf %{buildroot}%{_datadir}/%{name}/test/tmt
%{__rm} -rf %{buildroot}%{_datadir}/%{name}/test-dhcp/tmt

%preun
%systemd_preun %{name}-dhcp-proxy.service
%systemd_preun %{name}-firewalld-reload.service
Expand All @@ -138,5 +173,14 @@ cd docs
%{_unitdir}/%{name}-dhcp-proxy.socket
%{_unitdir}/%{name}-firewalld-reload.service

%files tests
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/examples
%dir %{_datadir}/%{name}/test
%dir %{_datadir}/%{name}/test-dhcp
%{_datadir}/%{name}/examples/*
%{_datadir}/%{name}/test/*
%{_datadir}/%{name}/test-dhcp/*

%changelog
%autochangelog
4 changes: 2 additions & 2 deletions test-dhcp/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TMP_TESTDIR=

# Netavark binary to run
NETAVARK=${NETAVARK:-./bin/netavark}

NETAVARK_DHCP_PROXY_CLIENT=${NETAVARK_DHCP_PROXY_CLIENT:-./bin/netavark-dhcp-proxy-client}
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}

# export RUST_BACKTRACE so that we get a helpful stack trace
Expand Down Expand Up @@ -407,7 +407,7 @@ function run_teardown(){
function run_client(){
local verb=$1
local conf=$2
run_in_container_netns "./bin/netavark-dhcp-proxy-client" --uds "$TMP_TESTDIR/nv-proxy.sock" -f "${conf}" "${verb}"
run_in_container_netns "$NETAVARK_DHCP_PROXY_CLIENT" --uds "$TMP_TESTDIR/nv-proxy.sock" -f "${conf}" "${verb}"
}

###################
Expand Down
17 changes: 17 additions & 0 deletions test-dhcp/tmt/integration.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Only common dependencies that are NOT required to run test_integration.sh are
# specified here. Everything else is in test_integration.sh.
require:
- iptables
- netavark-tests

adjust:
duration: 10m
when: arch == aarch64

tag: [ upstream, downstream ]
summary: Integration tests
test: bash integration.sh
environment:
NETAVARK: /usr/libexec/podman/netavark
NETAVARK_DHCP_PROXY_CLIENT: /usr/libexec/podman/netavark-dhcp-proxy-client
TEST_PLUGINS: /usr/share/netavark/examples
8 changes: 8 additions & 0 deletions test-dhcp/tmt/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -exo pipefail

rpm -q aardvark-dns cargo netavark

# Run tests
bats /usr/share/netavark/test-dhcp
2 changes: 1 addition & 1 deletion test/500-plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EOF
}

function run_netavark_plugins() {
run_netavark --plugin-directory ./targets/release/examples/ "$@"
run_netavark --plugin-directory $TEST_PLUGINS "$@"
}

@test "plugin - test error message" {
Expand Down
1 change: 1 addition & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Netavark binary to run
NETAVARK=${NETAVARK:-./bin/netavark}
TEST_PLUGINS=${TEST_PLUGINS:-./targets/release/examples}

TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}

Expand Down
8 changes: 8 additions & 0 deletions test/tmt/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -exo pipefail

rpm -q aardvark-dns cargo netavark

# Run tests
bats /usr/share/netavark/test
33 changes: 33 additions & 0 deletions test/tmt/netavark.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require:
- cargo
- clippy
- go-md2man
- git-core
- iptables
- make
- protobuf-compiler
- rustfmt

adjust+:
- duration: 10m
when: arch == aarch64

/validate:
tag: no-rpm
summary: Validate test
test: make -C $TMT_TREE validate

/unit:
tag: no-rpm
summary: Unit test
test: make -C $TMT_TREE unit

/integration:
tag: rpm
summary: Integration tests
test: bash integration.sh
environment:
NETAVARK: /usr/libexec/podman/netavark
TEST_PLUGINS: /usr/share/netavark/examples
require+:
- netavark-tests
13 changes: 13 additions & 0 deletions test/tmt/podman.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
summary: Podman tests dependent on netavark
require:
- netavark
- podman-tests

tag: [rpm]

test: |
/usr/bin/bats -t /usr/share/podman/test/system/030-run.bats
/usr/bin/bats -t /usr/share/podman/test/system/075-exec.bats
/usr/bin/bats -t /usr/share/podman/test/system/500-networking.bats

duration: 15m