@@ -335,8 +335,7 @@ func TestPodControllerRun(t *testing.T) {
335
335
containerNetNS (containerID ),
336
336
interfaceName ,
337
337
defaultMTU ,
338
- // We haven't updated the vfDeviceIDUsageMap, so a different device will be allocated.
339
- sriovDeviceID12 ,
338
+ sriovDeviceID11 ,
340
339
& ipamResult .Result ,
341
340
).Do (func (string , string , string , string , string , int , string , * current.Result ) {
342
341
atomic .AddInt32 (& interfaceConfigured , 1 )
@@ -1144,15 +1143,26 @@ func TestPodControllerAddPod(t *testing.T) {
1144
1143
t .Run ("updating deviceID cache per Pod" , func (t * testing.T ) {
1145
1144
ctrl := gomock .NewController (t )
1146
1145
podController , _ , _ , _ := testPodController (ctrl )
1147
- _ , err := podController .assignUnusedSriovVFDeviceID (podName , testNamespace , sriovResourceName1 , interfaceName )
1148
- _ , exists := podController .vfDeviceIDUsageMap .Load (podKey )
1146
+ tmpPodName := "poda"
1147
+ tmpPodNamespace := "testns"
1148
+ tmpPodKey := podKeyGet (tmpPodName , tmpPodNamespace )
1149
+ _ , err := podController .assignSriovVFDeviceID (tmpPodName , tmpPodNamespace , sriovResourceName1 , interfaceName )
1150
+ vfDeviceIDInfoCache , exists := podController .vfDeviceIDUsageMap .Load (tmpPodKey )
1149
1151
assert .True (t , exists )
1152
+ vfDeviceIDsInfo := vfDeviceIDInfoCache .([]podSriovVFDeviceIDInfo )
1153
+ assert .Equal (t , interfaceName , vfDeviceIDsInfo [0 ].ifName , "incorrect interface name" )
1150
1154
require .NoError (t , err , "error while assigning unused VfDevice ID" )
1151
- podController .releaseSriovVFDeviceID (podName , testNamespace , interfaceName )
1152
- _ , exists = podController .vfDeviceIDUsageMap .Load (podKey )
1155
+ // The second call would get the assigned SR-IOV device ID directly.
1156
+ deviceID , err := podController .assignSriovVFDeviceID (tmpPodName , tmpPodNamespace , sriovResourceName1 , interfaceName )
1157
+ _ , exists = podController .vfDeviceIDUsageMap .Load (tmpPodKey )
1158
+ assert .True (t , exists )
1159
+ assert .Equal (t , sriovDeviceID11 , deviceID , "incorrect device ID" )
1160
+ require .NoError (t , err , "error while getting assigned VfDevice ID" )
1161
+ podController .releaseSriovVFDeviceID (tmpPodName , tmpPodNamespace , interfaceName )
1162
+ _ , exists = podController .vfDeviceIDUsageMap .Load (tmpPodKey )
1153
1163
assert .True (t , exists )
1154
- podController .deleteVFDeviceIDListPerPod (podName , testNamespace )
1155
- _ , exists = podController .vfDeviceIDUsageMap .Load (podKey )
1164
+ podController .deleteVFDeviceIDListPerPod (tmpPodName , tmpPodNamespace )
1165
+ _ , exists = podController .vfDeviceIDUsageMap .Load (tmpPodKey )
1156
1166
assert .False (t , exists )
1157
1167
})
1158
1168
}
0 commit comments