mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-12-01 16:52:54 +00:00
62d88e7c95
This change adds .cdi and .legacy mode-specific runtimes the list of runtimes supported by the operator. These are also installed as part of the NVIDIA Container Toolkit. Signed-off-by: Evan Lezar <elezar@nvidia.com>
208 lines
5.5 KiB
Go
208 lines
5.5 KiB
Go
/**
|
|
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
*/
|
|
|
|
package operator
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestOptions(t *testing.T) {
|
|
testCases := []struct {
|
|
setAsDefault bool
|
|
nvidiaRuntimeName string
|
|
root string
|
|
expectedDefaultRuntime string
|
|
expectedRuntimes Runtimes
|
|
}{
|
|
{
|
|
expectedRuntimes: Runtimes{
|
|
"nvidia": Runtime{
|
|
name: "nvidia",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: true,
|
|
expectedDefaultRuntime: "nvidia",
|
|
expectedRuntimes: Runtimes{
|
|
"nvidia": Runtime{
|
|
name: "nvidia",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
SetAsDefault: true,
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: true,
|
|
nvidiaRuntimeName: "nvidia",
|
|
expectedDefaultRuntime: "nvidia",
|
|
expectedRuntimes: Runtimes{
|
|
"nvidia": Runtime{
|
|
name: "nvidia",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
SetAsDefault: true,
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: true,
|
|
nvidiaRuntimeName: "NAME",
|
|
expectedDefaultRuntime: "NAME",
|
|
expectedRuntimes: Runtimes{
|
|
"NAME": Runtime{
|
|
name: "NAME",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
SetAsDefault: true,
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: false,
|
|
nvidiaRuntimeName: "NAME",
|
|
expectedRuntimes: Runtimes{
|
|
"NAME": Runtime{
|
|
name: "NAME",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: true,
|
|
nvidiaRuntimeName: "nvidia-experimental",
|
|
expectedDefaultRuntime: "nvidia-experimental",
|
|
expectedRuntimes: Runtimes{
|
|
"nvidia": Runtime{
|
|
name: "nvidia",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
SetAsDefault: true,
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
setAsDefault: false,
|
|
nvidiaRuntimeName: "nvidia-experimental",
|
|
expectedRuntimes: Runtimes{
|
|
"nvidia": Runtime{
|
|
name: "nvidia",
|
|
Path: "/usr/bin/nvidia-container-runtime",
|
|
},
|
|
"nvidia-experimental": Runtime{
|
|
name: "nvidia-experimental",
|
|
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
|
},
|
|
"nvidia-cdi": Runtime{
|
|
name: "nvidia-cdi",
|
|
Path: "/usr/bin/nvidia-container-runtime.cdi",
|
|
},
|
|
"nvidia-legacy": Runtime{
|
|
name: "nvidia-legacy",
|
|
Path: "/usr/bin/nvidia-container-runtime.legacy",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
|
runtimes := GetRuntimes(
|
|
WithNvidiaRuntimeName(tc.nvidiaRuntimeName),
|
|
WithSetAsDefault(tc.setAsDefault),
|
|
WithRoot(tc.root),
|
|
)
|
|
|
|
require.EqualValues(t, tc.expectedRuntimes, runtimes)
|
|
require.Equal(t, tc.expectedDefaultRuntime, runtimes.DefaultRuntimeName())
|
|
})
|
|
}
|
|
}
|