Skip to content

Commit ca090d9

Browse files
ArangoGutierrezelezar
authored andcommitted
[no-relnote] Move runner declaration to BeforeSuite
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 0a77548 commit ca090d9

File tree

4 files changed

+63
-49
lines changed

4 files changed

+63
-49
lines changed

tests/e2e/e2e_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030

3131
// Test context
3232
var (
33+
runner Runner
34+
3335
ctx context.Context
3436

3537
installCTK bool
@@ -48,13 +50,34 @@ func TestMain(t *testing.T) {
4850
RegisterFailHandler(Fail)
4951

5052
ctx = context.Background()
51-
getTestEnv()
5253

5354
RunSpecs(t,
5455
suiteName,
5556
)
5657
}
5758

59+
var _ = BeforeSuite(func() {
60+
getTestEnv()
61+
62+
runner = NewRunner(
63+
WithHost(sshHost),
64+
WithPort(sshPort),
65+
WithSshKey(sshKey),
66+
WithSshUser(sshUser),
67+
)
68+
69+
if installCTK {
70+
installer, err := NewToolkitInstaller(
71+
WithImage(nvidiaContainerToolkitImage),
72+
WithMode(InstallUsingNVIDIACTKInstaller),
73+
)
74+
Expect(err).ToNot(HaveOccurred())
75+
76+
_, _, err = installer.Install(runner)
77+
Expect(err).ToNot(HaveOccurred())
78+
}
79+
})
80+
5881
// getTestEnv gets the test environment variables
5982
func getTestEnv() {
6083
defer GinkgoRecover()
@@ -73,7 +96,6 @@ func getTestEnv() {
7396
sshUser = getRequiredEnvvar[string]("E2E_SSH_USER")
7497
sshPort = getEnvVarOrDefault("E2E_SSH_PORT", "22")
7598
}
76-
7799
}
78100

79101
// getRequiredEnvvar returns the specified envvar if set or raises an error.

tests/e2e/nvidia-container-cli_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,12 @@ IN_NS
7171

7272
var _ = Describe("nvidia-container-cli", Ordered, ContinueOnFailure, Label("libnvidia-container"), func() {
7373
var (
74-
runner Runner
7574
nestedContainerRunner Runner
7675
containerName = "node-container-e2e"
7776
hostOutput string
7877
)
7978

8079
BeforeAll(func(ctx context.Context) {
81-
runner = NewRunner(
82-
WithHost(sshHost),
83-
WithPort(sshPort),
84-
WithSshKey(sshKey),
85-
WithSshUser(sshUser),
86-
)
87-
88-
// If installCTK is true, install the toolkit on the host. before creating
89-
// the nested container.
90-
if installCTK {
91-
installer, err := NewToolkitInstaller(
92-
WithImage(nvidiaContainerToolkitImage),
93-
WithMode(InstallUsingNVIDIACTKInstaller),
94-
)
95-
Expect(err).ToNot(HaveOccurred())
96-
97-
_, _, err = installer.Install(runner)
98-
Expect(err).ToNot(HaveOccurred())
99-
}
100-
10180
var err error
10281
nestedContainerRunner, err = NewNestedContainerRunner(runner, installCTK, containerName)
10382
Expect(err).ToNot(HaveOccurred())

tests/e2e/nvidia-container-toolkit_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,11 @@ import (
2828

2929
// Integration tests for Docker runtime
3030
var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
31-
var runner Runner
3231
var hostDriverVersion string
3332
var hostDriverMajor string
3433

3534
// Install the NVIDIA Container Toolkit
3635
BeforeAll(func(ctx context.Context) {
37-
runner = NewRunner(
38-
WithHost(sshHost),
39-
WithPort(sshPort),
40-
WithSshKey(sshKey),
41-
WithSshUser(sshUser),
42-
)
43-
44-
if installCTK {
45-
installer, err := NewToolkitInstaller(
46-
WithImage(nvidiaContainerToolkitImage),
47-
WithMode(InstallUsingPackagingImage),
48-
)
49-
Expect(err).ToNot(HaveOccurred())
50-
51-
_, _, err = installer.Install(runner)
52-
Expect(err).ToNot(HaveOccurred())
53-
}
54-
5536
driverOutput, _, err := runner.Run("nvidia-smi -q | grep \"Driver Version\"")
5637
Expect(err).ToNot(HaveOccurred())
5738
parts := strings.SplitN(driverOutput, ":", 2)

tests/e2e/runner.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
)
3030

3131
const (
32-
startTestContainerTemplate = `docker run -d --name {{.ContainerName}} --privileged --runtime=nvidia \
32+
outerContainerTemplate = `docker run -d --name {{.ContainerName}} --privileged --runtime=nvidia \
3333
-e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all \
3434
-e NVIDIA_DRIVER_CAPABILITIES=all \
3535
{{ range $i, $a := .AdditionalArguments -}}
@@ -160,16 +160,48 @@ func NewNestedContainerRunner(runner Runner, installCTK bool, containerName stri
160160
for _, lib := range strings.Split(output, "\n") {
161161
additionalContainerArguments = append(additionalContainerArguments, "-v "+lib+":"+lib)
162162
}
163-
additionalContainerArguments = append(additionalContainerArguments, "-v /usr/bin/nvidia-container-cli:/usr/bin/nvidia-container-cli")
163+
164+
// Look for NVIDIA binaries in standard locations and mount them as volumes
165+
nvidiaBinaries := []string{
166+
"nvidia-container-cli",
167+
"nvidia-container-runtime",
168+
"nvidia-container-runtime-hook",
169+
"nvidia-ctk",
170+
"nvidia-cdi-hook",
171+
"nvidia-container-runtime.cdi",
172+
"nvidia-container-runtime.legacy",
173+
}
174+
175+
searchPaths := []string{
176+
"/usr/bin",
177+
"/usr/sbin",
178+
"/usr/local/bin",
179+
"/usr/local/sbin",
180+
}
181+
182+
for _, binary := range nvidiaBinaries {
183+
for _, searchPath := range searchPaths {
184+
binaryPath := searchPath + "/" + binary
185+
// Check if the binary exists at this path
186+
checkCmd := fmt.Sprintf("test -f %s && echo 'exists'", binaryPath)
187+
output, _, err := runner.Run(checkCmd)
188+
if err == nil && strings.TrimSpace(output) == "exists" {
189+
// Binary found, add it as a volume mount
190+
additionalContainerArguments = append(additionalContainerArguments,
191+
fmt.Sprintf("-v %s:%s", binaryPath, binaryPath))
192+
break // Move to the next binary once found
193+
}
194+
}
195+
}
164196
}
165197

166198
// Launch the container in detached mode.
167-
var startContainerScriptBuilder strings.Builder
168-
startContainerTemplate, err := template.New("startContainer").Parse(startTestContainerTemplate)
199+
var outerContainerScriptBuilder strings.Builder
200+
outerContainerTemplate, err := template.New("outerContainer").Parse(outerContainerTemplate)
169201
if err != nil {
170202
return nil, fmt.Errorf("failed to parse start container template: %w", err)
171203
}
172-
err = startContainerTemplate.Execute(&startContainerScriptBuilder, struct {
204+
err = outerContainerTemplate.Execute(&outerContainerScriptBuilder, struct {
173205
ContainerName string
174206
AdditionalArguments []string
175207
}{
@@ -180,8 +212,8 @@ func NewNestedContainerRunner(runner Runner, installCTK bool, containerName stri
180212
return nil, fmt.Errorf("failed to execute start container template: %w", err)
181213
}
182214

183-
startContainerScript := startContainerScriptBuilder.String()
184-
_, _, err = runner.Run(startContainerScript)
215+
outerContainerScript := outerContainerScriptBuilder.String()
216+
_, _, err = runner.Run(outerContainerScript)
185217
if err != nil {
186218
return nil, fmt.Errorf("failed to run start container script: %w", err)
187219
}

0 commit comments

Comments
 (0)