Skip to content

Commit

Permalink
e2e tests: use /var/tmp, not $TMPDIR, as workdirs
Browse files Browse the repository at this point in the history
TMPDIR is typically /tmp which is typically(*) a tmpfs.

This PR ignores $TMPDIR when $CI is defined, forcing all
e2e tests to set up one central working directory in /var/tmp
instead.

Also, lots of cleanup.

 (*) For many years, up to and still including the time of
     this PR, /tmp on Fedora CI VMs is actually NOT tmpfs,
     it is just / (root). This is nonstandard and undesirable.
     Efforts are underway to remove this special case.

Signed-off-by: Ed Santiago <santiago@redhat.com>
  • Loading branch information
edsantiago committed Apr 26, 2024
1 parent e5cfbbb commit eaf60c7
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
DEBIAN_NAME: "debian-13"

# Image identifiers
IMAGE_SUFFIX: "c20240409t192511z-f39f38d13"
IMAGE_SUFFIX: "c20240411t124913z-f39f38d13"

# EC2 images
FEDORA_AMI: "fedora-aws-${IMAGE_SUFFIX}"
Expand Down
2 changes: 1 addition & 1 deletion contrib/cirrus/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ exec_container() {
set -x
# shellcheck disable=SC2154
exec bin/podman run --rm --privileged --net=host --cgroupns=host \
-v `mktemp -d -p /var/tmp`:/tmp:Z \
-v `mktemp -d -p /var/tmp`:/var/tmp:Z \
-v /dev/fuse:/dev/fuse \
-v "$GOPATH:$GOPATH:Z" \
--workdir "$GOSRC" \
Expand Down
83 changes: 44 additions & 39 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type PodmanTestIntegration struct {
TmpDir string
}

var GlobalTmpDir string // Single top-level tmpdir for all tests
var LockTmpDir string

// PodmanSessionIntegration struct for command line session
Expand Down Expand Up @@ -101,14 +102,14 @@ func TestLibpod(t *testing.T) {
}

var (
tempdir string
tempdir string // Working dir for _one_ subtest
err error
podmanTest *PodmanTestIntegration
safeIPOctets [2]uint8
timingsFile *os.File

_ = BeforeEach(func() {
tempdir, err = CreateTempDirInTempDir()
tempdir, err = os.MkdirTemp(GlobalTmpDir, "subtest-")
Expect(err).ToNot(HaveOccurred())
podmanTest = PodmanTestCreate(tempdir)
podmanTest.Setup()
Expand All @@ -130,26 +131,34 @@ var (
)

const (
// lockdir - do not use directly use LockTmpDir
// lockdir - do not use directly; use LockTmpDir
lockdir = "libpodlock"
// imageCacheDir - do not use directly use ImageCacheDir
imageCacheDir = "imagecachedir"
)

var _ = SynchronizedBeforeSuite(func() []byte {
globalTmpDir := GinkgoT().TempDir()
// One global scratch directory under which all test files will live.
// The usual case is that these tests are running in CI, on VMs
// with limited RAM, so we use /var/tmp.
baseTmpDir := "/var/tmp"
if os.Getenv("CI") == "" {
// Almost certainly a manual run, e.g., a developer with
// a hotrod workstation. Assume they know what they're doing.
baseTmpDir = ""
}
globalTmpDir, err := os.MkdirTemp(baseTmpDir, "podman-e2e-")
Expect(err).ToNot(HaveOccurred())

// make cache dir
ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
if err := os.MkdirAll(ImageCacheDir, 0700); err != nil {
GinkgoWriter.Printf("%q\n", err)
os.Exit(1)
}
err = os.MkdirAll(ImageCacheDir, 0700)
Expect(err).ToNot(HaveOccurred())

// Cache images
cwd, _ := os.Getwd()
INTEGRATION_ROOT = filepath.Join(cwd, "../../")
podman := PodmanTestSetup(GinkgoT().TempDir())
podman := PodmanTestSetup(filepath.Join(globalTmpDir, "image-init"))

// Pull cirros but don't put it into the cache
pullImages := []string{CIRROS_IMAGE, fedoraToolbox, volumeTest}
Expand Down Expand Up @@ -177,16 +186,16 @@ var _ = SynchronizedBeforeSuite(func() []byte {
podman.StopRemoteService()
}

// remove temporary podman files, images are now cached in ImageCacheDir
// remove temporary podman files; images are now cached in ImageCacheDir
rmAll(podman.PodmanBinary, podman.TempDir)

return []byte(globalTmpDir)
}, func(data []byte) {
cwd, _ := os.Getwd()
INTEGRATION_ROOT = filepath.Join(cwd, "../../")
globalTmpDir := string(data)
ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
LockTmpDir = filepath.Join(globalTmpDir, lockdir)
GlobalTmpDir = string(data)
ImageCacheDir = filepath.Join(GlobalTmpDir, imageCacheDir)
LockTmpDir = filepath.Join(GlobalTmpDir, lockdir)

timingsFile, err = os.Create(fmt.Sprintf("%s/timings-%d", LockTmpDir, GinkgoParallelProcess()))
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -229,7 +238,7 @@ var _ = SynchronizedAfterSuite(func() {
}

cwd, _ := os.Getwd()
rmAll(getPodmanBinary(cwd), ImageCacheDir)
rmAll(getPodmanBinary(cwd), GlobalTmpDir)
})

func getPodmanBinary(cwd string) string {
Expand All @@ -242,40 +251,38 @@ func getPodmanBinary(cwd string) string {

// PodmanTestCreate creates a PodmanTestIntegration instance for the tests
func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
var podmanRemoteBinary string

host := GetHostDistributionInfo()
cwd, _ := os.Getwd()

root := filepath.Join(tempDir, "root")
podmanBinary := getPodmanBinary(cwd)

podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote")
if os.Getenv("PODMAN_REMOTE_BINARY") != "" {
podmanRemoteBinary = os.Getenv("PODMAN_REMOTE_BINARY")
podmanRemoteBinary := os.Getenv("PODMAN_REMOTE_BINARY")
if podmanRemoteBinary == "" {
podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote")
}

quadletBinary := filepath.Join(cwd, "../../bin/quadlet")
if os.Getenv("QUADLET_BINARY") != "" {
quadletBinary = os.Getenv("QUADLET_BINARY")
quadletBinary := os.Getenv("QUADLET_BINARY")
if quadletBinary == "" {
quadletBinary = filepath.Join(cwd, "../../bin/quadlet")
}

conmonBinary := "/usr/libexec/podman/conmon"
altConmonBinary := "/usr/bin/conmon"
if _, err := os.Stat(conmonBinary); os.IsNotExist(err) {
conmonBinary = altConmonBinary
}
if os.Getenv("CONMON_BINARY") != "" {
conmonBinary = os.Getenv("CONMON_BINARY")
conmonBinary := os.Getenv("CONMON_BINARY")
if conmonBinary == "" {
conmonBinary = "/usr/libexec/podman/conmon"
if _, err := os.Stat(conmonBinary); errors.Is(err, os.ErrNotExist) {
conmonBinary = "/usr/bin/conmon"
}
}
storageOptions := STORAGE_OPTIONS
if os.Getenv("STORAGE_OPTIONS") != "" {
storageOptions = os.Getenv("STORAGE_OPTIONS")

storageOptions := os.Getenv("STORAGE_OPTIONS")
if storageOptions == "" {
storageOptions = STORAGE_OPTIONS
}

cgroupManager := CGROUP_MANAGER
if os.Getenv("CGROUP_MANAGER") != "" {
cgroupManager = os.Getenv("CGROUP_MANAGER")
cgroupManager := os.Getenv("CGROUP_MANAGER")
if cgroupManager == "" {
cgroupManager = CGROUP_MANAGER
}

ociRuntime := os.Getenv("OCI_RUNTIME")
Expand Down Expand Up @@ -390,10 +397,8 @@ func (p PodmanTestIntegration) AddImageToRWStore(image string) {
func imageTarPath(image string) string {
cacheDir := os.Getenv("PODMAN_TEST_IMAGE_CACHE_DIR")
if cacheDir == "" {
cacheDir = os.Getenv("TMPDIR")
if cacheDir == "" {
cacheDir = "/tmp"
}
// Avoid /tmp: it may be tmpfs, and these images are large
cacheDir = "/var/tmp"
}

// e.g., registry.com/fubar:latest -> registry.com-fubar-latest.tar
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/quadlet/basic.kube
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## assert-podman-args "kube"
## assert-podman-args "play"
## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml
## assert-podman-args "--replace"
## assert-podman-args "--service-container=true"
## assert-podman-stop-post-args "kube"
## assert-podman-stop-post-args "down"
## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
## assert-key-is "Service" "KillMode" "mixed"
## assert-key-is "Service" "Type" "notify"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/configmap.kube
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## assert-podman-args "--configmap" "/opt/k8s/abs.yml"
## assert-podman-args-regex "--configmap" ".*/podman_test.*/quadlet/rel.yml"
## assert-podman-args-regex "--configmap" ".*/podman-e2e-.*/subtest-.*/quadlet/rel.yml"

[Kube]
Yaml=deployment.yml
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/downforce.kube
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## assert-podman-stop-post-args "kube"
## assert-podman-stop-post-args "down"
## assert-podman-stop-post-args "--force"
## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml

[Kube]
Yaml=deployment.yml
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/env-file.container
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args --env-file /opt/env/abs-1
## assert-podman-args --env-file /opt/env/abs-2
## assert-podman-args-regex --env-file /.*/podman_test.*/quadlet/rel-1
## assert-podman-args-regex --env-file /.*/podman-e2e-.*/subtest-.*/quadlet/rel-1
## assert-podman-args --env-file %h/env

[Container]
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/quadlet/mount.container
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Mount=type=tmpfs,tmpfs-size=512M,destination=/path/in/container
Mount=type=image,source=fedora,destination=/fedora-image,rw=true
## assert-podman-args-key-val "--mount" "," "type=devpts,destination=/dev/pts"
Mount=type=devpts,destination=/dev/pts
## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman_test.*/quadlet/path/on/host,destination=/path/in/container"
## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman-e2e-.*/subtest-.*/quadlet/path/on/host,destination=/path/in/container"
Mount=type=bind,source=./path/on/host,destination=/path/in/container
## assert-podman-args-key-val "--mount" "," "type=volume,source=vol1,destination=/path/in/container,ro"
Mount=type=volume,source=vol1,destination=/path/in/container,ro
## assert-podman-args-key-val "--mount" "," "type=bind,source=/tmp,\"dst=/path,1\""
Mount=type=bind,src=/tmp,\"dst=/path,1\"
## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman_test.*/quadlet/src,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1"
## assert-podman-args-key-val-regex "--mount" "," "type=bind,source=.*/podman-e2e-.*/subtest-.*/quadlet/src,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1"
Mount=type=bind,source=./src/,destination=/dst/,idmap=uids=12-34-1;gids=56-78-1
4 changes: 2 additions & 2 deletions test/e2e/quadlet/oneshot.kube
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## assert-podman-args "kube"
## assert-podman-args "play"
## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml
## assert-podman-args "--replace"
## assert-podman-args "--service-container=true"
## assert-podman-stop-post-args "kube"
## assert-podman-stop-post-args "down"
## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
## assert-key-is "Service" "KillMode" "mixed"
## assert-key-is "Service" "Type" "oneshot"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/volume.container
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## assert-podman-args -v /host/dir:/container/volume
## assert-podman-args -v /host/dir2:/container/volume2:Z
## assert-podman-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3
## assert-podman-args-regex -v .*/podman-e2e-.*/subtest-.*/quadlet/host/dir3:/container/volume3
## assert-podman-args -v named:/container/named
## assert-podman-args -v systemd-quadlet:/container/quadlet
## assert-podman-args -v %h/container:/container/volume4
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/volume.pod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## assert-podman-pre-args -v /host/dir:/container/volume
## assert-podman-pre-args -v /host/dir2:/container/volume2:Z
## assert-podman-pre-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3
## assert-podman-pre-args-regex -v .*/podman-e2e-.*/subtest-.*/quadlet/host/dir3:/container/volume3
## assert-podman-pre-args -v named:/container/named
## assert-podman-pre-args -v systemd-quadlet:/container/quadlet
## assert-podman-pre-args -v %h/container:/container/volume4
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/workingdir-unit.kube
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman_test.*/quadlet"
## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman-e2e-.*/subtest-.*/quadlet"

[Kube]
Yaml=deployment.yml
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/workingdir-yaml-rel.kube
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman_test.*/quadlet/myservice"
## assert-key-is-regex "Service" "WorkingDirectory" ".*/podman-e2e-.*/subtest-.*/quadlet/myservice"

[Kube]
Yaml=./myservice/deployment.yml
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,12 @@ BOGUS=foo
"---basic.service---",
"## assert-podman-args \"kube\"",
"## assert-podman-args \"play\"",
"## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml",
"## assert-podman-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml",
"## assert-podman-args \"--replace\"",
"## assert-podman-args \"--service-container=true\"",
"## assert-podman-stop-post-args \"kube\"",
"## assert-podman-stop-post-args \"down\"",
"## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml",
"## assert-podman-stop-post-final-args-regex .*/podman-e2e-.*/subtest-.*/quadlet/deployment.yml",
"## assert-key-is \"Unit\" \"RequiresMountsFor\" \"%t/containers\"",
"## assert-key-is \"Service\" \"KillMode\" \"mixed\"",
"## assert-key-is \"Service\" \"Type\" \"notify\"",
Expand Down
8 changes: 0 additions & 8 deletions test/e2e/run_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,6 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(session.OutputToString()).To(Equal(sysctlValue))
})

It("podman run network expose host port 18082 to container port 8000 using slirp4netns port handler", func() {
session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:port_handler=slirp4netns", "-dt", "-p", "18082:8000", ALPINE, "/bin/sh"})
session.Wait(30)
Expect(session).Should(ExitCleanly())
ncBusy := SystemExec("nc", []string{"-l", "-p", "18082"})
Expect(ncBusy).To(ExitWithError())
})

It("podman run network expose host port 8080 to container port 8000 using invalid port handler", func() {
session := podmanTest.Podman([]string{"run", "--network", "slirp4netns:port_handler=invalid", "-dt", "-p", "8080:8000", ALPINE, "/bin/sh"})
session.Wait(30)
Expand Down
6 changes: 0 additions & 6 deletions test/utils/common_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ var _ = Describe("Common functions test", func() {
ProcessOneCgroupPath = defaultCgroupPath
})

It("Test CreateTempDirInTempDir", func() {
tmpDir, _ := CreateTempDirInTempDir()
_, err := os.Stat(tmpDir)
Expect(os.IsNotExist(err)).ShouldNot(BeTrue(), "Directory is not created as expect")
})

It("Test SystemExec", func() {
session := SystemExec(GoechoPath, []string{})
Expect(session.Command.Process).ShouldNot(BeNil(), "SystemExec cannot start a process")
Expand Down
5 changes: 0 additions & 5 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ func (s *PodmanSession) WaitWithTimeout(timeout int) {
os.Stderr.Sync()
}

// CreateTempDirInTempDir create a temp dir with prefix podman_test
func CreateTempDirInTempDir() (string, error) {
return os.MkdirTemp("", "podman_test")
}

// SystemExec is used to exec a system command to check its exit code or output
func SystemExec(command string, args []string) *PodmanSession {
c := exec.Command(command, args...)
Expand Down

0 comments on commit eaf60c7

Please sign in to comment.