diff --git a/pkg/katautils/create_test.go b/pkg/katautils/create_test.go index 77701838e9..3caa54d3e2 100644 --- a/pkg/katautils/create_test.go +++ b/pkg/katautils/create_test.go @@ -16,6 +16,7 @@ import ( "path" "path/filepath" "strings" + "syscall" "testing" vc "github.com/kata-containers/runtime/virtcontainers" @@ -177,12 +178,30 @@ func findLastParam(key string, params []vc.Param) (string, error) { } func TestSetEphemeralStorageType(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledNeedRoot) + } + assert := assert.New(t) + dir, err := ioutil.TempDir(testDir, "foo") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + ephePath := filepath.Join(dir, k8sEmptyDir, "tmp-volume") + err = os.MkdirAll(ephePath, testDirMode) + assert.Nil(err) + + err = syscall.Mount("tmpfs", ephePath, "tmpfs", 0, "") + assert.Nil(err) + defer syscall.Unmount(ephePath, 0) + ociSpec := oci.CompatOCISpec{} var ociMounts []specs.Mount mount := specs.Mount{ - Source: "/var/lib/kubelet/pods/366c3a77-4869-11e8-b479-507b9ddd5ce4/volumes/kubernetes.io~empty-dir/cache-volume", + Source: ephePath, } ociMounts = append(ociMounts, mount) diff --git a/pkg/katautils/utils_test.go b/pkg/katautils/utils_test.go index d061e6dc0d..4a1d7a5f11 100644 --- a/pkg/katautils/utils_test.go +++ b/pkg/katautils/utils_test.go @@ -368,7 +368,24 @@ func TestGetFileContents(t *testing.T) { } func TestIsEphemeralStorage(t *testing.T) { - sampleEphePath := "/var/lib/kubelet/pods/366c3a75-4869-11e8-b479-507b9ddd5ce4/volumes/kubernetes.io~empty-dir/cache-volume" + if os.Geteuid() != 0 { + t.Skip(testDisabledNeedRoot) + } + + dir, err := ioutil.TempDir(testDir, "foo") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + sampleEphePath := filepath.Join(dir, k8sEmptyDir, "tmp-volume") + err = os.MkdirAll(sampleEphePath, testDirMode) + assert.Nil(t, err) + + err = syscall.Mount("tmpfs", sampleEphePath, "tmpfs", 0, "") + assert.Nil(t, err) + defer syscall.Unmount(sampleEphePath, 0) + isEphe := IsEphemeralStorage(sampleEphePath) if !isEphe { t.Fatalf("Unable to correctly determine volume type")