Skip to content

Commit

Permalink
multiple-pools: fixup test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Nov 15, 2023
1 parent 6ec1b90 commit d3106ed
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/deviceplugin/poolManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (pm *PoolManager) Allocate(ctx context.Context,
}

envVar := constants.Devices.EnvVarList + strings.ToUpper(pm.Name)
envs[envVar] = strings.Join(crqt.DevicesIDs[:], " ")
envs[envVar] = strings.Join(crqt.DevicesIDs, " ")
envsPrint, err := tools.PrettyString(envs)
if err != nil {
logging.Errorf("Error printing container environment variables: %v", err)
Expand Down
67 changes: 47 additions & 20 deletions internal/deviceplugin/poolManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package deviceplugin
import (
"context"
"encoding/json"
"strings"
"testing"

"github.com/intel/afxdp-plugins-for-kubernetes/constants"
Expand Down Expand Up @@ -57,6 +58,8 @@ func TestAllocate(t *testing.T) {
pm.ServerFactory = udsserver.NewFakeServerFactory()
pm.BpfHandler = bpf.NewFakeHandler()

envVar := constants.Devices.EnvVarList + strings.ToUpper(pm.Name)

testCases := []struct {
name string
containerRequests []*pluginapi.ContainerAllocateRequest
Expand All @@ -69,10 +72,10 @@ func TestAllocate(t *testing.T) {
},
expContainerResponses: []*pluginapi.ContainerAllocateResponse{
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_1"},
Envs: map[string]string{envVar: "dev_1"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_1" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -90,10 +93,20 @@ func TestAllocate(t *testing.T) {
},
expContainerResponses: []*pluginapi.ContainerAllocateResponse{
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_1 dev_2 dev_3"},
Envs: map[string]string{envVar: "dev_1 dev_2 dev_3"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_1" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_2" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_3" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -112,10 +125,10 @@ func TestAllocate(t *testing.T) {
},
expContainerResponses: []*pluginapi.ContainerAllocateResponse{
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_1"},
Envs: map[string]string{envVar: "dev_1"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_1" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -124,10 +137,10 @@ func TestAllocate(t *testing.T) {
Annotations: map[string]string{},
},
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_2"},
Envs: map[string]string{envVar: "dev_2"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_2" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -146,10 +159,20 @@ func TestAllocate(t *testing.T) {
},
expContainerResponses: []*pluginapi.ContainerAllocateResponse{
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_1 dev_2 dev_3"},
Envs: map[string]string{envVar: "dev_1 dev_2 dev_3"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_1" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_2" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_3" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -158,10 +181,20 @@ func TestAllocate(t *testing.T) {
Annotations: map[string]string{},
},
{
Envs: map[string]string{constants.Devices.EnvVarList: "dev_4 dev_5 dev_6"},
Envs: map[string]string{envVar: "dev_4 dev_5 dev_6"},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
ContainerPath: constants.Uds.PodPath + "dev_4" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_5" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
{
ContainerPath: constants.Uds.PodPath + "dev_6" + constants.Uds.SockName,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
Expand All @@ -179,14 +212,8 @@ func TestAllocate(t *testing.T) {
},
expContainerResponses: []*pluginapi.ContainerAllocateResponse{
{
Envs: map[string]string{constants.Devices.EnvVarList: ""},
Mounts: []*pluginapi.Mount{
{
ContainerPath: constants.Uds.PodPath,
HostPath: "/tmp/fake-socket.sock",
ReadOnly: false,
},
},
Envs: map[string]string{envVar: ""},
Mounts: []*pluginapi.Mount{},
Devices: []*pluginapi.DeviceSpec{},
Annotations: map[string]string{},
},
Expand Down

0 comments on commit d3106ed

Please sign in to comment.