From ed7288aae7b28da0f4cf58e07b64bf7d508f0da1 Mon Sep 17 00:00:00 2001 From: David Trudgian Date: Tue, 5 Mar 2024 10:37:51 +0000 Subject: [PATCH 1/2] e2e: require sqfstar / tar2sqfs for OCI profiles Require `sqfstar` or `tar2sqfs` to be present for OCI-mode tests. We can't create an OCI-SIF without them. Also list these in `bin.FindBin`, as we aim to keep track of all external binary dependencies needed by non-test code there. Fixes #2472 --- e2e/internal/e2e/profile.go | 1 + internal/pkg/test/tool/require/require.go | 17 +++++++++++++++++ internal/pkg/util/bin/bin.go | 3 +++ 3 files changed, 21 insertions(+) diff --git a/e2e/internal/e2e/profile.go b/e2e/internal/e2e/profile.go index 636387498e..88261a9a90 100644 --- a/e2e/internal/e2e/profile.go +++ b/e2e/internal/e2e/profile.go @@ -278,6 +278,7 @@ func ociRequirements(t *testing.T) { require.Kernel(t, 4, 18) // FUSE in userns require.UserNamespace(t) require.Command(t, "runc") + require.OneCommand(t, []string{"sqfstar", "tar2sqfs"}) uid := uint32(origUID) diff --git a/internal/pkg/test/tool/require/require.go b/internal/pkg/test/tool/require/require.go index 8d714a6273..0109d10776 100644 --- a/internal/pkg/test/tool/require/require.go +++ b/internal/pkg/test/tool/require/require.go @@ -270,6 +270,23 @@ func Command(t *testing.T, command string) { t.Skipf("%s command not found in $PATH", command) } +// OneCommand checks if one of the provided commands is available (via +// Singularity's internal bin.FindBin() facility, or else simply on the PATH). +// If none are found, the current test is skipped with a message. +func OneCommand(t *testing.T, commands []string) { + for _, c := range commands { + if _, err := bin.FindBin(c); err == nil { + return + } + + if _, err := exec.LookPath(c); err == nil { + return + } + } + + t.Skipf("%v commands not found in $PATH", commands) +} + // Seccomp checks that seccomp is enabled, if not the // current test is skipped with a message. func Seccomp(t *testing.T) { diff --git a/internal/pkg/util/bin/bin.go b/internal/pkg/util/bin/bin.go index 5d210e8ba3..3b7e05144e 100644 --- a/internal/pkg/util/bin/bin.go +++ b/internal/pkg/util/bin/bin.go @@ -53,6 +53,9 @@ func FindBin(name string) (path string, err error) { // unprivileged overlays case "fuse-overlayfs": return findOnPath(name) + // tar to squashfs tools for OCI-mode image conversion + case "tar2sqfs", "sqfstar": + return findOnPath(name) default: return "", fmt.Errorf("executable name %q is not known to FindBin", name) } From 28e2d4db9eb377213e8170e6d059d8f7a9cfa413 Mon Sep 17 00:00:00 2001 From: David Trudgian Date: Tue, 5 Mar 2024 10:45:22 +0000 Subject: [PATCH 2/2] e2e: allow runc or crun for OCI profiles OCI-Mode supports `crun` as well as `runc`. Make sure we don't skip if only `crun` is present. --- e2e/internal/e2e/profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/internal/e2e/profile.go b/e2e/internal/e2e/profile.go index 88261a9a90..a59b8f2306 100644 --- a/e2e/internal/e2e/profile.go +++ b/e2e/internal/e2e/profile.go @@ -277,7 +277,7 @@ func fakerootRequirements(t *testing.T) { func ociRequirements(t *testing.T) { require.Kernel(t, 4, 18) // FUSE in userns require.UserNamespace(t) - require.Command(t, "runc") + require.OneCommand(t, []string{"runc", "crun"}) require.OneCommand(t, []string{"sqfstar", "tar2sqfs"}) uid := uint32(origUID)