From f0f12658dee460fbf41c95353fd83ddcc99ada86 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 26 Oct 2022 11:37:30 -0600 Subject: [PATCH] Test runners: nuke podman from $PATH before tests We've had some oopsies in system tests: podman foo bar run podman foo bar ...all of which should be run_podman with underscore. Those have been passing because /usr/bin/podman is the fallback from $PATH. In those (few) cases, we haven't actually been testing the podman we should be testing. Solution: nuke /usr/bin/podman and podman-remote before invoking system and unit tests. As an extra level of paranoia, check for other podmans in $PATH - if any exist, bail out with a fatal error. Also: in a few cases where runner.sh invokes podman for containerized something-something, run bin/podman instead of podman from $PATH. Also: fix existing dependencies on /usr/bin/podman Signed-off-by: Ed Santiago --- contrib/cirrus/runner.sh | 14 +++++++++++--- test/e2e/system_connection_test.go | 10 ++++++++++ test/e2e/systemd_test.go | 8 ++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh index 2c8b7289bd..e49d1038d6 100755 --- a/contrib/cirrus/runner.sh +++ b/contrib/cirrus/runner.sh @@ -146,7 +146,7 @@ exec_container() { # VM Images and Container images are built using (nearly) identical operations. set -x # shellcheck disable=SC2154 - exec podman run --rm --privileged --net=host --cgroupns=host \ + exec bin/podman run --rm --privileged --net=host --cgroupns=host \ -v `mktemp -d -p /var/tmp`:/tmp:Z \ -v /dev/fuse:/dev/fuse \ -v "$GOPATH:$GOPATH:Z" \ @@ -187,7 +187,7 @@ function _run_swagger() { # Swagger validation takes a significant amount of time msg "Pulling \$CTR_FQIN '$CTR_FQIN' (background process)" - podman pull --quiet $CTR_FQIN & + bin/podman pull --quiet $CTR_FQIN & cd $GOSRC make swagger @@ -209,7 +209,7 @@ eof msg "Waiting for backgrounded podman pull to complete..." wait %% - podman run -it --rm --security-opt label=disable \ + bin/podman run -it --rm --security-opt label=disable \ --env-file=$envvarsfile \ -v $GOSRC:$GOSRC:ro \ --workdir $GOSRC \ @@ -375,6 +375,14 @@ dotest() { podman) localremote="local" ;; esac + # We've had some oopsies where tests invoke 'podman' instead of + # /path/to/built/podman. Let's catch those. + sudo rm -f /usr/bin/podman /usr/bin/podman-remote + fallback_podman=$(type -p podman || true) + if [[ -n "$fallback_podman" ]]; then + die "Found fallback podman '$fallback_podman' in \$PATH; tests require none, as a guarantee that we're testing the right binary." + fi + make ${localremote}${testsuite} PODMAN_SERVER_LOG=$PODMAN_SERVER_LOG \ |& logformatter } diff --git a/test/e2e/system_connection_test.go b/test/e2e/system_connection_test.go index 31cbfe3495..221f598eb7 100644 --- a/test/e2e/system_connection_test.go +++ b/test/e2e/system_connection_test.go @@ -253,6 +253,16 @@ var _ = Describe("podman system connection", func() { u, err := user.Current() Expect(err).ShouldNot(HaveOccurred()) + // Ensure that the remote end uses our built podman + if os.Getenv("PODMAN_BINARY") == "" { + err = os.Setenv("PODMAN_BINARY", podmanTest.PodmanBinary) + Expect(err).ShouldNot(HaveOccurred()) + + defer func() { + os.Unsetenv("PODMAN_BINARY") + }() + } + cmd := exec.Command(podmanTest.RemotePodmanBinary, "system", "connection", "add", "--default", diff --git a/test/e2e/systemd_test.go b/test/e2e/systemd_test.go index 7b79a724d9..371eabc4cd 100644 --- a/test/e2e/systemd_test.go +++ b/test/e2e/systemd_test.go @@ -27,16 +27,16 @@ var _ = Describe("Podman systemd", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - systemdUnitFile = `[Unit] + systemdUnitFile = fmt.Sprintf(`[Unit] Description=redis container [Service] Restart=always -ExecStart=/usr/bin/podman start -a redis -ExecStop=/usr/bin/podman stop -t 10 redis +ExecStart=%s start -a redis +ExecStop=%s stop -t 10 redis KillMode=process [Install] WantedBy=default.target -` +`, podmanTest.PodmanBinary, podmanTest.PodmanBinary) }) AfterEach(func() {