Skip to content

Commit

Permalink
TMT: initial enablement
Browse files Browse the repository at this point in the history
This commit adds `validate`, `unit`, and `integration` tests using
for aarch64 and x86_64 arches on all active Fedora and CentOS Stream
versions.

Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
  • Loading branch information
lsm5 committed Oct 31, 2024
1 parent 5ab4cb1 commit 92a4f0b
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 9 deletions.
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/
src/proto-build/netavark_proxy.rs
contrib/systemd/*/*.service
.vscode*
rpm/RPMS
rpm/SRPMS
rpm/*.tar.gz
56 changes: 49 additions & 7 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ packages:
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 +24,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-all-x86_64
- fedora-all-aarch64
enable_net: true

- job: copr_build
trigger: pull_request
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 +50,8 @@ jobs:
- job: copr_build
trigger: pull_request
packages: [netavark-centos]
notifications: *copr_build_failure_notification
targets:
#notifications: *copr_build_failure_notification
targets: &centos_targets
- centos-stream-9-x86_64
- centos-stream-9-aarch64
- centos-stream-10-x86_64
Expand All @@ -59,6 +70,37 @@ jobs:
project: podman-next
enable_net: true

- job: tests
trigger: pull_request
packages: [netavark-fedora]
#notifications:
#failure_comment:
# message: "TMT tests failed. @containers/packit-build please check."
targets:
- fedora-development
- fedora-latest
- fedora-latest-stable
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

- job: tests
trigger: pull_request
packages: [netavark-centos]
#notifications:
#failure_comment:
# message: "TMT tests failed. @containers/packit-build please check."
targets: *centos_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
- type: repository-file
id: https://src.fedoraproject.org/rpms/epel-release/raw/epel$releasever/f/epel.repo

# Sync to Fedora
- job: propose_downstream
trigger: release
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ build_netavark: bin $(CARGO_TARGET_DIR)

.PHONY: examples
examples: bin $(CARGO_TARGET_DIR)
cargo build --examples $(release)
$(CARGO) build --examples $(release)

.PHONY: crate-publish
crate-publish:
Expand Down Expand Up @@ -122,7 +122,14 @@ unit: $(CARGO_TARGET_DIR)
$(CARGO) test

.PHONY: integration
# The TEST_PLUGINS envvar is used by bats to specify path to test-plugins
# directory
ifdef TEST_PLUGINS
$(info Skipping examples build as TEST_PLUGINS is set)
integration: $(CARGO_TARGET_DIR)
else
integration: $(CARGO_TARGET_DIR) examples
endif
# needs to be run as root or with podman unshare --rootless-netns
bats test/
bats test-dhcp/
Expand Down
20 changes: 20 additions & 0 deletions plans/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
discover:
how: fmf
execute:
how: tmt

/upstream:
summary: Run tests on upstream PRs
discover+:
filter: tag:upstream
adjust+:
enabled: false
when: initiator is not defined or initiator != packit

/downstream:
summary: Run tests on bodhi / errata and dist-git PRs
discover+:
filter: tag:downstream
adjust+:
enabled: false
when: initiator == packit
19 changes: 19 additions & 0 deletions rpm/netavark.spec
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ Its features include:
* Support for IPv4 and IPv6
* Support for container DNS resolution via aardvark-dns.

%package tests
Summary: Tests for %{name}
Requires: %{name} = %{epoch}:%{version}-%{release}

%description tests
%{summary}

%prep
%autosetup -Sgit %{name}-%{version}
# Following steps are only required on environments like koji which have no
Expand All @@ -110,12 +117,18 @@ NETAVARK_DEFAULT_FW=%{default_fw} %{__make} CARGO="%{__cargo}" build
%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}/test/examples
cp -pav targets/release/examples/* %{buildroot}%{_datadir}/%{name}/test/examples

%preun
%systemd_preun %{name}-dhcp-proxy.service
%systemd_preun %{name}-firewalld-reload.service
Expand All @@ -137,6 +150,12 @@ cd docs
%{_unitdir}/%{name}-dhcp-proxy.socket
%{_unitdir}/%{name}-firewalld-reload.service

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

%changelog
%if %{defined autochangelog}
%autochangelog
Expand Down
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
40 changes: 40 additions & 0 deletions test/tmt/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Only common dependencies that are NOT required to run test_integration.sh are
# specified here. Everything else is in test_integration.sh.
require:
- bats
- bind-utils
- bridge-utils
- cargo
- clippy
- dbus-daemon
- dnsmasq
- firewalld
- go-md2man
- git-core
- iptables
- jq
- make
- net-tools
- nftables
- nmap-ncat
- protobuf-compiler
- rustfmt

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

/validate:
tag: upstream
summary: Validate test
test: make -C ../.. validate

/unit:
tag: upstream
summary: Unit test
test: make -C ../.. unit

/integration:
tag: [ upstream, downstream ]
summary: Integration tests
test: bash test_integration.sh
16 changes: 16 additions & 0 deletions test/tmt/test_integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -exo pipefail

# Remove testing-farm repos if they exist because they interfere with the
# podman-next copr. The default distro repos will not be removed and can be
# used wherever relevant.
rm -f /etc/yum.repos.d/tag-repository.repo

# Install dependencies for running tests
dnf -y update aardvark-dns

rpm -q aardvark-dns cargo netavark

# Run tests
make -C ../.. NETAVARK=/usr/libexec/podman/netavark TEST_PLUGINS=/usr/share/netavark/test/examples integration

0 comments on commit 92a4f0b

Please sign in to comment.