open-nomad/client/devicemanager/testing.go
Alex Dadgar 4ee603c382 Device hook and devices affect computed node class
This PR introduces a device hook that retrieves the device mount
information for an allocation. It also updates the computed node class
computation to take into account devices.

TODO Fix the task runner unit test. The environment variable is being
lost even though it is being properly set in the prestart hook.
2018-11-27 17:25:33 -08:00

49 lines
1.4 KiB
Go

package devicemanager
import (
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/device"
)
type ReserveFn func(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error)
type AllStatsFn func() []*device.DeviceGroupStats
type DeviceStatsFn func(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error)
func NoopReserve(*structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
return nil, nil
}
func NoopAllStats() []*device.DeviceGroupStats {
return nil
}
func NoopDeviceStats(*structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
return nil, nil
}
func NoopMockManager() *MockManager {
return &MockManager{
ReserveF: NoopReserve,
AllStatsF: NoopAllStats,
DeviceStatsF: NoopDeviceStats,
}
}
type MockManager struct {
ReserveF ReserveFn
AllStatsF AllStatsFn
DeviceStatsF DeviceStatsFn
}
func (m *MockManager) Run() {}
func (m *MockManager) Shutdown() {}
func (m *MockManager) AllStats() []*device.DeviceGroupStats { return m.AllStatsF() }
func (m *MockManager) Reserve(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
return m.ReserveF(d)
}
func (m *MockManager) DeviceStats(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
return m.DeviceStatsF(d)
}