From 31bc099b6cf242a94ad278f3143209a5cca0d37c Mon Sep 17 00:00:00 2001 From: Lokesh Mandvekar Date: Thu, 25 Jul 2024 09:01:26 -0400 Subject: [PATCH] TMT: initial enablement 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 --- .fmf/version | 1 + .gitignore | 3 ++ .packit.yaml | 82 +++++++++++++++++++++++++++++++++--- Makefile | 9 +++- plans/all.fmf | 20 +++++++++ rpm/netavark.spec | 19 +++++++++ src/dhcp_proxy/lib.rs | 5 +-- test-dhcp/001-basic.bats | 5 +-- test/500-plugin.bats | 2 +- test/helpers.bash | 1 + test/tmt/main.fmf | 25 +++++++++++ test/tmt/test_integration.sh | 34 +++++++++++++++ 12 files changed, 189 insertions(+), 17 deletions(-) create mode 100644 .fmf/version create mode 100644 plans/all.fmf create mode 100644 test/tmt/main.fmf create mode 100644 test/tmt/test_integration.sh diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/.gitignore b/.gitignore index 9093ace2a..f4054b9fa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ vendor/ src/proto-build/netavark_proxy.rs contrib/systemd/*/*.service .vscode* +rpm/RPMS +rpm/SRPMS +rpm/*.tar.gz diff --git a/.packit.yaml b/.packit.yaml index abbfa15e6..98056982a 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -24,9 +24,9 @@ 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: {} @@ -41,8 +41,8 @@ jobs: - job: copr_build trigger: pull_request packages: [netavark-centos] - notifications: *copr_build_failure_notification - targets: + #notifications: *copr_build_failure_notification + targets: ¢os_targets - centos-stream-9-x86_64 - centos-stream-9-aarch64 - centos-stream-10-x86_64 @@ -52,8 +52,8 @@ jobs: - job: copr_build trigger: pull_request packages: [netavark-rhel] - notifications: *copr_build_failure_notification - targets: + #notifications: *copr_build_failure_notification + targets: &rhel_targets - epel-9-x86_64 - epel-9-aarch64 enable_net: true @@ -70,6 +70,74 @@ 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-all + 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: + # TODO: enable centos-stream-9 after + # https://github.com/fedora-copr/copr/issues/3334 is fixed + - centos-stream-10 + 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 + + - job: tests + trigger: pull_request + packages: [netavark-centos] + #notifications: + #failure_comment: + # message: "TMT tests failed. @containers/packit-build please check." + targets: + # TODO: fold centos-stream-9 into previous job after + # https://github.com/fedora-copr/copr/issues/3334 is fixed + - centos-stream-9 + tf_extra_params: + environments: + - artifacts: + - type: repository-file + id: https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/repo/centos-stream-9/rhcontainerbot-podman-next-centos-stream-9.repo + - type: repository-file + id: https://src.fedoraproject.org/rpms/epel-release/raw/epel9/f/epel.repo + + - job: tests + trigger: pull_request + packages: [netavark-rhel] + #notifications: + #failure_comment: + # message: "TMT tests failed. @containers/packit-build please check." + targets: + epel-9-x86_64: + distros: [RHEL-9.4.0-Nightly,RHEL-9-Nightly] + epel-9-aarch64: + distros: [RHEL-9.4.0-Nightly,RHEL-9-Nightly] + use_internal_tf: true + tf_extra_params: + environments: + - artifacts: + - type: repository-file + id: https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/repo/epel-$releasever/rhcontainerbot-podman-next-epel-$releasever.repo + - type: repository-file + id: https://src.fedoraproject.org/rpms/epel-release/raw/epel9/f/epel.repo + # Sync to Fedora - job: propose_downstream trigger: release diff --git a/Makefile b/Makefile index 6b9b7d9bc..e6920ac7b 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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/ diff --git a/plans/all.fmf b/plans/all.fmf new file mode 100644 index 000000000..4b754d2da --- /dev/null +++ b/plans/all.fmf @@ -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 diff --git a/rpm/netavark.spec b/rpm/netavark.spec index 72337a307..676e96cd6 100644 --- a/rpm/netavark.spec +++ b/rpm/netavark.spec @@ -83,6 +83,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 @@ -105,12 +112,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 @@ -132,6 +145,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 diff --git a/src/dhcp_proxy/lib.rs b/src/dhcp_proxy/lib.rs index 848b76b05..cb35bc02b 100644 --- a/src/dhcp_proxy/lib.rs +++ b/src/dhcp_proxy/lib.rs @@ -40,10 +40,7 @@ pub mod g_rpc { impl From for Lease { fn from(l: DhcpV4Lease) -> Lease { // Since these fields are optional as per mozim. Match them first and then set them - let domain_name = match l.domain_name { - None => String::from(""), - Some(l) => l, - }; + let domain_name = l.domain_name.unwrap_or_default(); let mtu = l.mtu.unwrap_or(0) as u32; Lease { diff --git a/test-dhcp/001-basic.bats b/test-dhcp/001-basic.bats index 4cf6c5879..ac577fed5 100644 --- a/test-dhcp/001-basic.bats +++ b/test-dhcp/001-basic.bats @@ -5,7 +5,4 @@ load helpers -@test "simple example" { - -} - +@test "simple example" {} diff --git a/test/500-plugin.bats b/test/500-plugin.bats index 6649d503e..39b7f1411 100644 --- a/test/500-plugin.bats +++ b/test/500-plugin.bats @@ -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" { diff --git a/test/helpers.bash b/test/helpers.bash index 93b480d00..4a365ca39 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -2,6 +2,7 @@ # Netavark binary to run NETAVARK=${NETAVARK:-./bin/netavark} +TEST_PLUGINS=${TEST_PLUGINS:-./targets/release/examples} TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})} diff --git a/test/tmt/main.fmf b/test/tmt/main.fmf new file mode 100644 index 000000000..5fe6c417d --- /dev/null +++ b/test/tmt/main.fmf @@ -0,0 +1,25 @@ +# Only common dependencies that are NOT required to run test_integration.sh are +# specified here. Everything else is in test_integration.sh. +require: + - cargo + - make + - protobuf-compiler + +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 diff --git a/test/tmt/test_integration.sh b/test/tmt/test_integration.sh new file mode 100644 index 000000000..d6c2e79f9 --- /dev/null +++ b/test/tmt/test_integration.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -exo pipefail + +cat /etc/redhat-release + +# 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 install \ + bats \ + bind-utils \ + bridge-utils \ + cargo \ + clippy \ + dbus-daemon \ + dnsmasq \ + firewalld \ + go-md2man \ + iptables \ + jq \ + make \ + net-tools \ + nftables \ + nmap-ncat \ + rustfmt + +rpm -q aardvark-dns cargo netavark + +# Run tests +make -C ../.. NETAVARK=/usr/libexec/podman/netavark TEST_PLUGINS=/usr/share/netavark/test/examples integration