Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for support of NFS mount #1726

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions test/cri-containerd/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,74 @@ func Test_RunContainer_ExecUser_Root_LCOW(t *testing.T) {
t.Fatalf("expected user for exec to be 'root', got %q", string(r.Stdout))
}
}

// creates a linux container and attempts to mount a (non-existent) nfs share. Tests if the kernel has the
// required modules for supporting NFS mount.
func Test_Container_NFSMount_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowUbuntu})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// start a privileged pod & container. container must be privileged in order to be able to mount a NFS
// share.
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
sandboxRequest.Config.Linux = &runtime.LinuxPodSandboxConfig{
SecurityContext: &runtime.LinuxSandboxSecurityContext{
Privileged: true,
},
ambarve marked this conversation as resolved.
Show resolved Hide resolved
}
podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)

requestTemplate := getCreateContainerRequest(
podID,
t.Name()+"-container",
imageLcowUbuntu,
[]string{"bash", "-c", "while true; do echo 'hello'; sleep 1; done"},
sandboxRequest.Config,
)
requestTemplate.Config.Linux = &runtime.LinuxContainerConfig{
SecurityContext: &runtime.LinuxContainerSecurityContext{
Privileged: true,
},
}
containerID := createContainer(t, client, ctx, requestTemplate)
defer removeContainer(t, client, ctx, containerID)
startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)

execHelper := func(ctrID string, cmd []string) {
stdout, stderr, errcode := execContainer(t, client, ctx, ctrID, cmd)
if errcode != 0 {
t.Helper()
t.Logf("stdout: %s \n\n stderr: %s\n\n", stdout, stderr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a t.Helper() call before the t.Logf call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the t.Helper() to be in the errcode block of code or outside of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't matter I think. Either works.

t.Fatalf("failed to run '%v'\n: errcode: %d", cmd, errcode)
ambarve marked this conversation as resolved.
Show resolved Hide resolved
katiewasnothere marked this conversation as resolved.
Show resolved Hide resolved
}
}

// setup nfs client
nfsdir := "/mnt/nfstest"
execHelper(containerID, []string{"apt", "update"})
execHelper(containerID, []string{"apt", "install", "-y", "nfs-common"})
execHelper(containerID, []string{"mkdir", "-p", nfsdir})

// There is no NFS daemon running in the container, so it is expected that the mount call fails with
// the connection refused error. However getting upto the connection refused error verifies that the
// container has all the required NFS client modules to successfully mount a NFS. (This also means
// that the kernel was correctly built with the NFS client options). `retry=0` ensures it fails
// immediately instead of retrying. If the kernel isn't correctly configured the call would fail with
// "No Device" error.
stdout, stderr, errcode := execContainer(t, client, ctx, containerID, []string{"mount", "-v", "-t", "nfs", "localhost:/fake/nfs/mount", nfsdir, "-o", "vers=4,minorversion=1,sec=sys,retry=0"})
if errcode != 32 { // 32 is mount failure
t.Logf("stdout: %s \n\n stderr: %s\n", stdout, stderr)
t.Fatalf("mount call is expected to fail with mount failure error code: 32, errcode was %d instead", errcode)
} else if !strings.Contains(stderr, "Connection refused") {
t.Logf("stdout: %s \n\n stderr: %s\n", stdout, stderr)
t.Fatalf("mount call is expected to fail with Connection refused error")
}
}
1 change: 1 addition & 0 deletions test/cri-containerd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
imageLcowAlpineCoreDump = "cplatpublic.azurecr.io/stackoverflow-alpine:latest"
imageLcowCosmos = "cosmosarno/spark-master:2.4.1_2019-04-18_8e864ce"
imageLcowCustomUser = "cplatpublic.azurecr.io/linux_custom_user:latest"
imageLcowUbuntu = "ubuntu:latest"
alpineAspNet = "mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.11"
alpineAspnetUpgrade = "mcr.microsoft.com/dotnet/core/aspnet:3.1.2-alpine3.11"

Expand Down