@@ -19,6 +19,7 @@ package scheduler
1919import (
2020 "fmt"
2121 "reflect"
22+ "strings"
2223 "testing"
2324
2425 "github.com/Project-HAMi/HAMi/pkg/device"
@@ -30,6 +31,7 @@ import (
3031 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
3233 "github.com/Project-HAMi/HAMi/pkg/device"
34+ "github.com/Project-HAMi/HAMi/pkg/device/metax"
3335 "github.com/Project-HAMi/HAMi/pkg/device/nvidia"
3436 "github.com/Project-HAMi/HAMi/pkg/util"
3537)
@@ -332,7 +334,7 @@ func Test_rmNodeDevices(t *testing.T) {
332334
333335func Test_rmDeviceByNodeAnnotation (t * testing.T ) {
334336 id1 := "60151478-4709-4242-a8c1-a944252d194b"
335- id2 := "60151478-4709-4242-a8c1-a944252d194d "
337+ id2 := "33c00a52-72ab-4b61-a7ce-43107588835b "
336338 type args struct {
337339 nodeInfo * device.NodeInfo
338340 }
@@ -342,7 +344,7 @@ func Test_rmDeviceByNodeAnnotation(t *testing.T) {
342344 want []device.DeviceInfo
343345 }{
344346 {
345- name : "Test remove device" ,
347+ name : "Test remove one device" ,
346348 args : args {
347349 nodeInfo : & util.NodeInfo {
348350 Node : & corev1.Node {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {nvidia .GPUNoUseUUID : id1 }}},
@@ -351,6 +353,26 @@ func Test_rmDeviceByNodeAnnotation(t *testing.T) {
351353 },
352354 want : []device.DeviceInfo {},
353355 },
356+ {
357+ name : "Test remove two devices" ,
358+ args : args {
359+ nodeInfo : & util.NodeInfo {
360+ Node : & corev1.Node {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {nvidia .GPUNoUseUUID : strings .Join ([]string {id1 , id2 }, "," )}}},
361+ Devices : []util.DeviceInfo {{DeviceVendor : nvidia .NvidiaGPUDevice , ID : id1 }, {DeviceVendor : nvidia .NvidiaGPUDevice , ID : id2 }},
362+ },
363+ },
364+ want : []util.DeviceInfo {},
365+ },
366+ {
367+ name : "Test remove one device and keep one device" ,
368+ args : args {
369+ nodeInfo : & util.NodeInfo {
370+ Node : & corev1.Node {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {nvidia .GPUNoUseUUID : strings .Join ([]string {id2 }, "," )}}},
371+ Devices : []util.DeviceInfo {{DeviceVendor : nvidia .NvidiaGPUDevice , ID : id1 }, {DeviceVendor : nvidia .NvidiaGPUDevice , ID : id2 }},
372+ },
373+ },
374+ want : []util.DeviceInfo {{DeviceVendor : nvidia .NvidiaGPUDevice , ID : id1 }},
375+ },
354376 {
355377 name : "Test no removing device, case1" ,
356378 args : args {
@@ -371,6 +393,26 @@ func Test_rmDeviceByNodeAnnotation(t *testing.T) {
371393 },
372394 want : []util.DeviceInfo {{DeviceVendor : nvidia .NvidiaGPUDevice , ID : id1 }},
373395 },
396+ {
397+ name : "Test removing metax device, case1" ,
398+ args : args {
399+ nodeInfo : & util.NodeInfo {
400+ Node : & corev1.Node {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {metax .MetaxNoUseUUID : id1 }}},
401+ Devices : []util.DeviceInfo {{DeviceVendor : metax .MetaxGPUDevice , ID : id1 }},
402+ },
403+ },
404+ want : []util.DeviceInfo {},
405+ },
406+ {
407+ name : "Test removing metax device, case2" ,
408+ args : args {
409+ nodeInfo : & util.NodeInfo {
410+ Node : & corev1.Node {ObjectMeta : metav1.ObjectMeta {Annotations : map [string ]string {metax .MetaxNoUseUUID : id1 }}},
411+ Devices : []util.DeviceInfo {{DeviceVendor : metax .MetaxSGPUDevice , ID : id1 }},
412+ },
413+ },
414+ want : []util.DeviceInfo {},
415+ },
374416 }
375417 for _ , tt := range tests {
376418 t .Run (tt .name , func (t * testing.T ) {
0 commit comments