Skip to content

Commit e00d3f0

Browse files
committed
Address comments after code review
- Update GeVfRepresentorSmartNIC() parameter vfIndex to be string to allow greater flexibility - Minor typo fixes - Adjust tests to new changes Signed-off-by: Adrian Chiris <[email protected]>
1 parent 3eaa53d commit e00d3f0

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

sriovnet_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func TestIntegrationGetPfPciFromVfPci(t *testing.T) {
228228

229229
func TestIntegrationGetVfRepresentorSmartNIC(t *testing.T) {
230230
pfID := "0"
231-
vfIdx := 2
231+
vfIdx := "2"
232232
t.Log("GetVfRepresentorSmartNIC ", "PF ID: ", pfID, "VF Index: ", vfIdx)
233233
rep, err := GetVfRepresentorSmartNIC(pfID, vfIdx)
234234
if err != nil {

sriovnet_switchdev.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,18 @@ func getNetDevPhysPortName(netDev string) (string, error) {
131131
}
132132

133133
// GetVfRepresentorSmartNIC returns VF representor on Smart-NIC for a host VF identified by pfID and vfIndex
134-
func GetVfRepresentorSmartNIC(pfID string, vfIndex int) (string, error) {
134+
func GetVfRepresentorSmartNIC(pfID, vfIndex string) (string, error) {
135135
// TODO(Adrianc): This method should change to get switchID and vfIndex as input, then common logic can
136136
// be shared with GetVfRepresentor, backward compatibility should be preserved when this happens.
137137

138138
// pfID should be 0 or 1
139139
if pfID != "0" && pfID != "1" {
140-
return "", fmt.Errorf("unexpected pfID(%s). should be 0 or 1", pfID)
140+
return "", fmt.Errorf("unexpected pfID(%s). It should be 0 or 1", pfID)
141+
}
142+
143+
// vfIndex should be an unsinged integer provided as a decimal number
144+
if _, err := strconv.ParseUint(vfIndex, 10, 32); err != nil {
145+
return "", fmt.Errorf("unexpected vfIndex(%s). It should be an unsigned decimal number", vfIndex)
141146
}
142147

143148
netdevs, err := utilfs.Fs.ReadDir(NetSysDir)
@@ -148,8 +153,8 @@ func GetVfRepresentorSmartNIC(pfID string, vfIndex int) (string, error) {
148153
// map for easy search of expected VF rep port name.
149154
// Note: no supoport for Multi-Chassis Smart-NICs
150155
expectedPhysPortNames := map[string]interface{}{
151-
fmt.Sprintf("pf%svf%d", pfID, vfIndex): nil,
152-
fmt.Sprintf("c0pf%svf%d", pfID, vfIndex): nil,
156+
fmt.Sprintf("pf%svf%s", pfID, vfIndex): nil,
157+
fmt.Sprintf("c0pf%svf%s", pfID, vfIndex): nil,
153158
}
154159

155160
// iterate all net devs and get phys port name
@@ -166,5 +171,5 @@ func GetVfRepresentorSmartNIC(pfID string, vfIndex int) (string, error) {
166171
return netdevName, nil
167172
}
168173
}
169-
return "", fmt.Errorf("vf representor for pfID:%s, vfIndex: %d not found", pfID, vfIndex)
174+
return "", fmt.Errorf("vf representor for pfID:%s, vfIndex: %s not found", pfID, vfIndex)
170175
}

sriovnet_switchdev_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestGetVfRepresentorSmartNIC(t *testing.T) {
196196
teardown := setupRepresentorEnv(t, "", vfReps)
197197
defer teardown()
198198

199-
vfRep, err := GetVfRepresentorSmartNIC("0", 2)
199+
vfRep, err := GetVfRepresentorSmartNIC("0", "2")
200200
assert.NoError(t, err)
201201
assert.Equal(t, "eth2", vfRep)
202202
}
@@ -217,13 +217,19 @@ func TestGetVfRepresentorSmartNICNoRep(t *testing.T) {
217217
teardown := setupRepresentorEnv(t, "", vfReps)
218218
defer teardown()
219219

220-
vfRep, err := GetVfRepresentorSmartNIC("1", 2)
220+
vfRep, err := GetVfRepresentorSmartNIC("1", "2")
221221
assert.Error(t, err)
222222
assert.Equal(t, "", vfRep)
223223
}
224224

225-
func TestGetVfRepresentorInvalidPfID(t *testing.T) {
226-
vfRep, err := GetVfRepresentorSmartNIC("invalid", 2)
225+
func TestGetVfRepresentorSmartNICInvalidPfID(t *testing.T) {
226+
vfRep, err := GetVfRepresentorSmartNIC("invalid", "2")
227+
assert.Error(t, err)
228+
assert.Equal(t, "", vfRep)
229+
}
230+
231+
func TestGetVfRepresentorSmartNICInvalidVfIndex(t *testing.T) {
232+
vfRep, err := GetVfRepresentorSmartNIC("1", "invalid")
227233
assert.Error(t, err)
228234
assert.Equal(t, "", vfRep)
229235
}

0 commit comments

Comments
 (0)