Skip to content

Commit e2d415e

Browse files
committed
test(gdrcopy): precompiled
Signed-off-by: Justin Bera <justin.bera@datadoghq.com>
1 parent ff9bbfd commit e2d415e

2 files changed

Lines changed: 183 additions & 0 deletions

File tree

api/nvidia/v1alpha1/nvidiadriver_types_test.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,127 @@ func TestGDRCopyGetImagePath(t *testing.T) {
402402
})
403403
}
404404
}
405+
406+
func TestGDRCopyGetPrecompiledImagePath(t *testing.T) {
407+
testCases := []struct {
408+
description string
409+
spec *GDRCopySpec
410+
osVersion string
411+
kernelVersion string
412+
errorExpected bool
413+
expectedImage string
414+
}{
415+
{
416+
description: "malformed repository",
417+
spec: &GDRCopySpec{
418+
Repository: "malformed?/repo",
419+
},
420+
errorExpected: true,
421+
expectedImage: "",
422+
},
423+
{
424+
description: "malformed image",
425+
spec: &GDRCopySpec{
426+
Image: "malformed?image",
427+
},
428+
errorExpected: true,
429+
expectedImage: "",
430+
},
431+
{
432+
description: "only image provided with no tag or digest",
433+
spec: &GDRCopySpec{
434+
Image: "nvcr.io/nvidia/cloud-native/gdrdrv",
435+
},
436+
errorExpected: true,
437+
expectedImage: "",
438+
},
439+
{
440+
description: "only image provided with tag",
441+
spec: &GDRCopySpec{
442+
Image: "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2",
443+
},
444+
osVersion: "ubuntu22.04",
445+
kernelVersion: "5.4.0-150-generic",
446+
expectedImage: "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2-5.4.0-150-generic-ubuntu22.04",
447+
},
448+
{
449+
description: "only image provided with digest",
450+
spec: &GDRCopySpec{
451+
Image: "nvcr.io/nvidia/cloud-native/gdrdrv@sha256:" + testDigest,
452+
},
453+
osVersion: "ubuntu22.04",
454+
kernelVersion: "5.4.0-150-generic",
455+
errorExpected: true,
456+
expectedImage: "",
457+
},
458+
{
459+
description: "repository, image, and version set but image contains a tag",
460+
spec: &GDRCopySpec{
461+
Repository: "nvcr.io/nvidia/cloud-native",
462+
Image: "nvcr.io/nvidia/cloud-native/gdrdrv:v2.4.1",
463+
Version: "v2.5.2",
464+
},
465+
osVersion: "ubuntu22.04",
466+
kernelVersion: "5.4.0-150-generic",
467+
errorExpected: true,
468+
expectedImage: "",
469+
},
470+
{
471+
description: "repository, image, and version set but image contains a digest",
472+
spec: &GDRCopySpec{
473+
Repository: "nvcr.io/nvidia/cloud-native",
474+
Image: "nvcr.io/nvidia/cloud-native/gdrdrv@sha256:" + testDigest,
475+
Version: "v2.5.2",
476+
},
477+
osVersion: "ubuntu22.04",
478+
kernelVersion: "5.4.0-150-generic",
479+
errorExpected: true,
480+
expectedImage: "",
481+
},
482+
{
483+
description: "missing version",
484+
spec: &GDRCopySpec{
485+
Repository: "nvcr.io/nvidia/cloud-native",
486+
Image: "gdrdrv",
487+
},
488+
osVersion: "ubuntu22.04",
489+
kernelVersion: "5.4.0-150-generic",
490+
errorExpected: true,
491+
expectedImage: "",
492+
},
493+
{
494+
description: "repository, image, and version set; version is a tag",
495+
spec: &GDRCopySpec{
496+
Repository: "nvcr.io/nvidia/cloud-native",
497+
Image: "gdrdrv",
498+
Version: "v2.5.2",
499+
},
500+
osVersion: "ubuntu22.04",
501+
kernelVersion: "5.4.0-150-generic",
502+
expectedImage: "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2-5.4.0-150-generic-ubuntu22.04",
503+
},
504+
{
505+
description: "repository, image, and version set; version is a digest",
506+
spec: &GDRCopySpec{
507+
Repository: "nvcr.io/nvidia/cloud-native",
508+
Image: "gdrdrv",
509+
Version: "sha256:" + testDigest,
510+
},
511+
osVersion: "ubuntu22.04",
512+
kernelVersion: "5.4.0-150-generic",
513+
errorExpected: true,
514+
},
515+
}
516+
517+
for _, tc := range testCases {
518+
t.Run(tc.description, func(t *testing.T) {
519+
image, err := tc.spec.GetPrecompiledImagePath(tc.osVersion, tc.kernelVersion)
520+
if tc.errorExpected {
521+
require.Error(t, err)
522+
} else {
523+
require.NoError(t, err)
524+
}
525+
require.Equal(t, image, tc.expectedImage)
526+
})
527+
}
528+
}

controllers/object_controls_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,3 +2292,62 @@ func TestDriverPrecompiledLibModulesSuse(t *testing.T) {
22922292
})
22932293
}
22942294
}
2295+
2296+
// TestGDRCopyResolveDriverTag tests that resolveDriverTag returns the correct
2297+
// image path for GDRCopy in both non-precompiled and precompiled modes.
2298+
func TestGDRCopyResolveDriverTag(t *testing.T) {
2299+
const (
2300+
repo = "nvcr.io/nvidia/cloud-native"
2301+
image = "gdrdrv"
2302+
version = "v2.5.2"
2303+
kernel = "5.4.0-150-generic"
2304+
osTag = "ubuntu22.04"
2305+
)
2306+
2307+
n := ClusterPolicyController{
2308+
currentKernelVersion: kernel,
2309+
gpuNodeOSTag: osTag,
2310+
singleton: &gpuv1.ClusterPolicy{},
2311+
}
2312+
2313+
t.Run("non-precompiled", func(t *testing.T) {
2314+
spec := &gpuv1.GDRCopySpec{Repository: repo, Image: image, Version: version}
2315+
got, err := resolveDriverTag(n, spec)
2316+
require.NoError(t, err)
2317+
require.Equal(t, repo+"/"+image+":"+version+"-"+osTag, got)
2318+
})
2319+
2320+
t.Run("precompiled", func(t *testing.T) {
2321+
spec := &gpuv1.GDRCopySpec{Repository: repo, Image: image, Version: version, UsePrecompiled: ptr.To(true)}
2322+
got, err := resolveDriverTag(n, spec)
2323+
require.NoError(t, err)
2324+
require.Equal(t, repo+"/"+image+":"+version+"-"+kernel+"-"+osTag, got)
2325+
})
2326+
}
2327+
2328+
// TestGDRCopyPrecompiledDriverIncompatibility tests that enabling precompiled
2329+
// drivers without enabling precompiled GDRCopy returns an error.
2330+
func TestGDRCopyPrecompiledDriverIncompatibility(t *testing.T) {
2331+
cp := getDriverTestInput("precompiled")
2332+
enabled := true
2333+
cp.Spec.GDRCopy = &gpuv1.GDRCopySpec{
2334+
Enabled: &enabled,
2335+
Repository: "nvcr.io/nvidia/cloud-native",
2336+
Image: "gdrdrv",
2337+
Version: "v2.5.2",
2338+
UsePrecompiled: ptr.To(false),
2339+
}
2340+
2341+
err := updateClusterPolicy(&clusterPolicyController, cp)
2342+
require.NoError(t, err)
2343+
2344+
addState(&clusterPolicyController, filepath.Join(cfg.root, driverAssetsPath))
2345+
// step() returns an error without incrementing idx, so the state is still at idx
2346+
defer func() {
2347+
_ = removeState(&clusterPolicyController, clusterPolicyController.idx)
2348+
}()
2349+
2350+
_, err = clusterPolicyController.step()
2351+
require.Error(t, err, "expected error when driver is precompiled but GDRCopy is not")
2352+
require.Contains(t, err.Error(), "GDRCopy is not supported")
2353+
}

0 commit comments

Comments
 (0)