Skip to content

Commit 244939c

Browse files
[no-relnote] Add test to check CDI injection by default
Now that the NVIDIA Container Toolkit uses CDI injection by default. This does not trigger the code in the nvidia-container-cli that creates the empty files on the host. Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent b442fe8 commit 244939c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

tests/e2e/nvidia-container-toolkit_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package e2e
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"path/filepath"
2223
"strings"
2324

@@ -257,4 +258,54 @@ var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
257258
Expect(libs).To(ContainElements([]string{"libcuda.so", "libcuda.so.1"}))
258259
})
259260
})
261+
262+
When("A container tries to create firmware files on the host", Ordered, func() {
263+
var outputDir string
264+
BeforeAll(func(ctx context.Context) {
265+
pwd, _, err := runner.Run("pwd")
266+
Expect(err).ToNot(HaveOccurred())
267+
outputDir = filepath.Join(strings.TrimSpace(pwd), "test-output")
268+
269+
_, _, err = runner.Run(fmt.Sprintf("mkdir -p %s", outputDir))
270+
Expect(err).ToNot(HaveOccurred())
271+
272+
_, _, err = runner.Run("docker pull ubuntu")
273+
Expect(err).ToNot(HaveOccurred())
274+
275+
dockerBuildCmd := fmt.Sprintf(`docker build -t firmware-test --build-arg RM_VERSION="$(basename $(ls -d /lib/firmware/nvidia/*.*))" --build-arg CURRENT_DIR=%q - <<EOF`, outputDir)
276+
dockerBuildDockerfile := `
277+
FROM ubuntu
278+
RUN mkdir -p /lib/firmware/nvidia/
279+
ARG RM_VERSION
280+
ARG CURRENT_DIR
281+
RUN ln -s /../../../../../../../../\$CURRENT_DIR /lib/firmware/nvidia/\$RM_VERSION
282+
EOF`
283+
_, _, err = runner.Run(dockerBuildCmd + dockerBuildDockerfile)
284+
Expect(err).ToNot(HaveOccurred())
285+
})
286+
287+
AfterAll(func(ctx context.Context) {
288+
if outputDir != "" {
289+
runner.Run(fmt.Sprintf("rm -rf %s", outputDir))
290+
}
291+
})
292+
293+
It("should not fail when using CDI", func(ctx context.Context) {
294+
output, _, err := runner.Run("docker run --rm --runtime=nvidia --gpus=all firmware-test")
295+
Expect(err).ToNot(HaveOccurred())
296+
Expect(output).To(BeEmpty())
297+
298+
output, _, _ = runner.Run(fmt.Sprintf("ls -A %s", outputDir))
299+
Expect(output).To(BeEmpty())
300+
})
301+
302+
It("should fail when using the nvidia-container-runtime-hook", Label("legacy"), func(ctx context.Context) {
303+
_, stderr, err := runner.Run("docker run --rm --runtime=runc --gpus=all firmware-test")
304+
Expect(err).To(HaveOccurred())
305+
Expect(stderr).To(ContainSubstring("nvidia-container-cli.real: mount error: path error:"))
306+
307+
output, _, _ := runner.Run(fmt.Sprintf("ls -A %s", outputDir))
308+
Expect(output).To(BeEmpty())
309+
})
310+
})
260311
})

tests/e2e/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (r remoteRunner) Run(script string) (string, string, error) {
124124
// Run the script
125125
err = session.Run(script)
126126
if err != nil {
127-
return "", "", fmt.Errorf("script execution failed: %v\nSTDOUT: %s\nSTDERR: %s", err, stdout.String(), stderr.String())
127+
return "", stderr.String(), fmt.Errorf("script execution failed: %v\nSTDOUT: %s\nSTDERR: %s", err, stdout.String(), stderr.String())
128128
}
129129

130130
// Return stdout as string if no errors

0 commit comments

Comments
 (0)