|
|
@@ -103,6 +103,7 @@ func TestDevicePluginReRegistration(t *testing.T) {
|
|
|
|
{ID: "Dev3", Health: pluginapi.Healthy},
|
|
|
|
{ID: "Dev3", Health: pluginapi.Healthy},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, preStartContainerFlag := range []bool{false, true} {
|
|
|
|
for _, preStartContainerFlag := range []bool{false, true} {
|
|
|
|
|
|
|
|
for _, getPreferredAllocationFlag := range []bool{false, true} {
|
|
|
|
m, ch, p1 := setup(t, devs, nil, socketName, pluginSocketName)
|
|
|
|
m, ch, p1 := setup(t, devs, nil, socketName, pluginSocketName)
|
|
|
|
p1.Register(socketName, testResourceName, "")
|
|
|
|
p1.Register(socketName, testResourceName, "")
|
|
|
|
|
|
|
|
|
|
|
@@ -117,7 +118,7 @@ func TestDevicePluginReRegistration(t *testing.T) {
|
|
|
|
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
|
|
|
|
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
|
|
|
|
|
|
|
|
p2 := NewDevicePluginStub(devs, pluginSocketName+".new", testResourceName, preStartContainerFlag)
|
|
|
|
p2 := NewDevicePluginStub(devs, pluginSocketName+".new", testResourceName, preStartContainerFlag, getPreferredAllocationFlag)
|
|
|
|
err = p2.Start()
|
|
|
|
err = p2.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
p2.Register(socketName, testResourceName, "")
|
|
|
|
p2.Register(socketName, testResourceName, "")
|
|
|
@@ -134,7 +135,7 @@ func TestDevicePluginReRegistration(t *testing.T) {
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices shouldn't change.")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices shouldn't change.")
|
|
|
|
|
|
|
|
|
|
|
|
// Test the scenario that a plugin re-registers with different devices.
|
|
|
|
// Test the scenario that a plugin re-registers with different devices.
|
|
|
|
p3 := NewDevicePluginStub(devsForRegistration, pluginSocketName+".third", testResourceName, preStartContainerFlag)
|
|
|
|
p3 := NewDevicePluginStub(devsForRegistration, pluginSocketName+".third", testResourceName, preStartContainerFlag, getPreferredAllocationFlag)
|
|
|
|
err = p3.Start()
|
|
|
|
err = p3.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
p3.Register(socketName, testResourceName, "")
|
|
|
|
p3.Register(socketName, testResourceName, "")
|
|
|
@@ -153,6 +154,7 @@ func TestDevicePluginReRegistration(t *testing.T) {
|
|
|
|
p3.Stop()
|
|
|
|
p3.Stop()
|
|
|
|
cleanup(t, m, p1)
|
|
|
|
cleanup(t, m, p1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Tests that the device plugin manager correctly handles registration and re-registration by
|
|
|
|
// Tests that the device plugin manager correctly handles registration and re-registration by
|
|
|
@@ -186,7 +188,7 @@ func TestDevicePluginReRegistrationProbeMode(t *testing.T) {
|
|
|
|
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
|
|
|
|
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
|
|
|
|
|
|
|
|
p2 := NewDevicePluginStub(devs, pluginSocketName+".new", testResourceName, false)
|
|
|
|
p2 := NewDevicePluginStub(devs, pluginSocketName+".new", testResourceName, false, false)
|
|
|
|
err = p2.Start()
|
|
|
|
err = p2.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// Wait for the second callback to be issued.
|
|
|
|
// Wait for the second callback to be issued.
|
|
|
@@ -203,7 +205,7 @@ func TestDevicePluginReRegistrationProbeMode(t *testing.T) {
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
|
|
|
|
|
|
|
|
|
|
|
|
// Test the scenario that a plugin re-registers with different devices.
|
|
|
|
// Test the scenario that a plugin re-registers with different devices.
|
|
|
|
p3 := NewDevicePluginStub(devsForRegistration, pluginSocketName+".third", testResourceName, false)
|
|
|
|
p3 := NewDevicePluginStub(devsForRegistration, pluginSocketName+".third", testResourceName, false, false)
|
|
|
|
err = p3.Start()
|
|
|
|
err = p3.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// Wait for the third callback to be issued.
|
|
|
|
// Wait for the third callback to be issued.
|
|
|
@@ -249,7 +251,7 @@ func setupDeviceManager(t *testing.T, devs []*pluginapi.Device, callback monitor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func setupDevicePlugin(t *testing.T, devs []*pluginapi.Device, pluginSocketName string) *Stub {
|
|
|
|
func setupDevicePlugin(t *testing.T, devs []*pluginapi.Device, pluginSocketName string) *Stub {
|
|
|
|
p := NewDevicePluginStub(devs, pluginSocketName, testResourceName, false)
|
|
|
|
p := NewDevicePluginStub(devs, pluginSocketName, testResourceName, false, false)
|
|
|
|
err := p.Start()
|
|
|
|
err := p.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return p
|
|
|
|
return p
|
|
|
@@ -549,6 +551,7 @@ func (a *activePodsStub) updateActivePods(newPods []*v1.Pod) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type MockEndpoint struct {
|
|
|
|
type MockEndpoint struct {
|
|
|
|
|
|
|
|
getPreferredAllocationFunc func(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error)
|
|
|
|
allocateFunc func(devs []string) (*pluginapi.AllocateResponse, error)
|
|
|
|
allocateFunc func(devs []string) (*pluginapi.AllocateResponse, error)
|
|
|
|
initChan chan []string
|
|
|
|
initChan chan []string
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -563,6 +566,13 @@ func (m *MockEndpoint) preStartContainer(devs []string) (*pluginapi.PreStartCont
|
|
|
|
return &pluginapi.PreStartContainerResponse{}, nil
|
|
|
|
return &pluginapi.PreStartContainerResponse{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MockEndpoint) getPreferredAllocation(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error) {
|
|
|
|
|
|
|
|
if m.getPreferredAllocationFunc != nil {
|
|
|
|
|
|
|
|
return m.getPreferredAllocationFunc(available, mustInclude, size)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MockEndpoint) allocate(devs []string) (*pluginapi.AllocateResponse, error) {
|
|
|
|
func (m *MockEndpoint) allocate(devs []string) (*pluginapi.AllocateResponse, error) {
|
|
|
|
if m.allocateFunc != nil {
|
|
|
|
if m.allocateFunc != nil {
|
|
|
|
return m.allocateFunc(devs)
|
|
|
|
return m.allocateFunc(devs)
|
|
|
|