Skip to content

Commit 32dd526

Browse files
author
Franck Rupin
committed
Rename symbols for more clarity
- The review identified few ambiguities in symbol names. - This commit try to fix these ambiguities after discussion out of band.
1 parent 908ac8d commit 32dd526

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

ovs/datapath.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ var (
3030
errWrongZoneArgument = errors.New("wrong argument while setting zone ct limits")
3131
)
3232

33-
// Zone defines the type used to store a zone as it is returned
33+
// CTLimit defines the type used to store a zone as it is returned
3434
// by ovs-dpctl ct-*-limits commands
35-
type Zone map[string]uint64
35+
type CTLimit map[string]uint64
3636

37-
// ConnTrackOutput is a type defined to store the output
37+
// ConntrackOutput is a type defined to store the output
3838
// of ovs-dpctl ct-*-limits commands. For example it stores
3939
// such a cli output:
4040
// # ovs-dpctl ct-get-limits system@ovs-system zone=2,3
4141
// default limit=0
4242
// zone=2,limit=0,count=0
4343
// zone=3,limit=0,count=0
44-
type ConnTrackOutput struct {
45-
// defaulCT is used to store the global setting: default
46-
defaultLimit Zone
44+
type ConntrackOutput struct {
45+
// defaultLimit is used to store the global setting: default
46+
defaultLimit CTLimit
4747
// zones stores all remaning zone's settings
48-
zones []Zone
48+
zoneLimits []CTLimit
4949
}
5050

5151
// DataPathReader is the interface defining the read operations
@@ -72,7 +72,7 @@ type DataPathWriter interface {
7272
type ConnTrackReader interface {
7373
// GetCTLimits is the method used to querying conntrack limits for a
7474
// datapath on a switch
75-
GetCTLimits(string, []uint64) (ConnTrackOutput, error)
75+
GetCTLimits(string, []uint64) (ConntrackOutput, error)
7676
}
7777

7878
// ConnTrackWriter is the interface defining the write operations
@@ -149,7 +149,7 @@ func (dp *DataPathService) DelDataPath(dpName string) error {
149149

150150
// GetCTLimits returns the conntrack limits for a given datapath
151151
// equivalent to running: 'sudo ovs-dpctl ct-get-limits <datapath_name> zone=<#1>,<#2>,...'
152-
func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrackOutput, error) {
152+
func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConntrackOutput, error) {
153153
// Start by building the args
154154
if dpName == "" {
155155
return nil, errMissingMandatoryDataPathName
@@ -170,7 +170,7 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
170170

171171
// Process the results
172172
entries := strings.Split(string(results), "\n")
173-
ctOut := &ConnTrackOutput{}
173+
ctOut := &ConntrackOutput{}
174174

175175
r, err := regexp.Compile(`default`)
176176
if err != nil {
@@ -181,7 +181,7 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
181181
// If found the default value is removed from the entries
182182
for i, entry := range entries {
183183
if r.MatchString(entry) {
184-
ctOut.defaultLimit = make(Zone)
184+
ctOut.defaultLimit = make(CTLimit)
185185
limit, err := strconv.Atoi(strings.Split(entry, "=")[1])
186186
if err != nil {
187187
return nil, err
@@ -195,13 +195,13 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
195195
// Now process the zones setup
196196
for _, entry := range entries {
197197
fields := strings.Split(entry, ",")
198-
z := make(Zone)
198+
z := make(CTLimit)
199199
for _, field := range fields {
200200
buf := strings.Split(field, "=")
201201
val, _ := strconv.Atoi(buf[1])
202202
z[buf[0]] = uint64(val)
203203
}
204-
ctOut.zones = append(ctOut.zones, z)
204+
ctOut.zoneLimits = append(ctOut.zoneLimits, z)
205205
}
206206

207207
return ctOut, nil

ovs/datapath_test.go

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,30 @@ func TestDelDataPath(t *testing.T) {
179179
}
180180

181181
func TestGetCTLimits(t *testing.T) {
182-
z0 := make(Zone)
183-
z0["default"] = 0
184-
z1 := make(Zone)
182+
d := make(CTLimit)
183+
d["default"] = 0
184+
z1 := make(CTLimit)
185185
z1["zone"] = 2
186186
z1["count"] = 0
187187
z1["limit"] = 1000000
188-
z2 := make(Zone)
188+
z2 := make(CTLimit)
189189
z2["zone"] = 3
190190
z2["count"] = 0
191191
z2["limit"] = 1000000
192-
zones := make([]Zone, 0)
192+
zones := make([]CTLimit, 0)
193193
zones = append(zones, z1)
194194
zones = append(zones, z2)
195-
out := &ConnTrackOutput{
196-
defaultLimit: z0,
197-
zones: zones,
195+
out := &ConntrackOutput{
196+
defaultLimit: d,
197+
zoneLimits: zones,
198198
}
199199

200200
var tests = []struct {
201201
desc string
202202
dp *DataPathService
203203
dpName string
204204
zones []uint64
205-
want *ConnTrackOutput
205+
want *ConntrackOutput
206206
err string
207207
testCase uint8
208208
}{
@@ -258,9 +258,9 @@ func TestGetCTLimits(t *testing.T) {
258258
if tt.want.defaultLimit["default"] != results.defaultLimit["default"] {
259259
t.Errorf("mismatched values, want %q but got %q", tt.want.defaultLimit["default"], results.defaultLimit["default"])
260260
}
261-
for i, z := range results.zones {
262-
if tt.want.zones[i]["zone"] != z["zone"] {
263-
t.Errorf("mismatched values, want %q but got %q", tt.want.zones[i]["zone"], z["zone"])
261+
for i, z := range results.zoneLimits {
262+
if tt.want.zoneLimits[i]["zone"] != z["zone"] {
263+
t.Errorf("mismatched values, want %q but got %q", tt.want.zoneLimits[i]["zone"], z["zone"])
264264
}
265265
}
266266
case handleError:
@@ -282,44 +282,32 @@ func TestGetCTLimitsWithBinary(t *testing.T) {
282282
t.Skip("skipping test in short mode.")
283283
}
284284

285-
z0 := make(Zone)
286-
z0["default"] = 200
287-
z1 := make(Zone)
285+
d := make(CTLimit)
286+
d["default"] = 200
287+
z1 := make(CTLimit)
288288
z1["zone"] = 2
289289
z1["count"] = 0
290290
z1["limit"] = 200
291-
z2 := make(Zone)
292-
z2["zone"] = 3
293-
z2["count"] = 0
294-
z2["limit"] = 200
295-
zones1 := make([]Zone, 0)
291+
zones1 := make([]CTLimit, 0)
296292
zones1 = append(zones1, z1)
297-
zones1 = append(zones1, z2)
298-
out := &ConnTrackOutput{
299-
defaultLimit: z0,
300-
zones: zones1,
301-
}
302-
zones2 := make([]Zone, 0)
303-
zones2 = append(zones2, z2)
304-
outTest2 := &ConnTrackOutput{
305-
defaultLimit: z0,
306-
zones: zones2,
293+
out := &ConntrackOutput{
294+
defaultLimit: d,
295+
zoneLimits: zones1,
307296
}
308-
309297
var tests = []struct {
310298
desc string
311299
dp *DataPathService
312300
dpName string
313301
zones []uint64
314-
want *ConnTrackOutput
302+
want *ConntrackOutput
315303
err string
316304
testCase uint8
317305
}{
318306
{
319307
desc: "Test valid ovs-dpctl ct-get-limits system@ovs-system zone=2,3 ",
320308
dp: NewDataPathService(),
321309
dpName: "ovs-system",
322-
zones: []uint64{2, 3},
310+
zones: []uint64{2},
323311
want: out,
324312
err: "",
325313
testCase: validTest,
@@ -329,7 +317,7 @@ func TestGetCTLimitsWithBinary(t *testing.T) {
329317
dp: NewDataPathService(),
330318
dpName: "ovs-system",
331319
zones: []uint64{},
332-
want: outTest2,
320+
want: out,
333321
err: "",
334322
testCase: validTest,
335323
},
@@ -351,9 +339,9 @@ func TestGetCTLimitsWithBinary(t *testing.T) {
351339
if tt.want.defaultLimit["default"] != results.defaultLimit["default"] {
352340
t.Errorf("mismatched values, want %q but got %q", tt.want.defaultLimit["default"], results.defaultLimit["default"])
353341
}
354-
for i, z := range results.zones {
355-
if tt.want.zones[i]["zone"] != z["zone"] {
356-
t.Errorf("mismatched values, want %q but got %q", tt.want.zones[i]["zone"], z["zone"])
342+
for i, z := range results.zoneLimits {
343+
if tt.want.zoneLimits[i]["zone"] != z["zone"] {
344+
t.Errorf("mismatched values, want %q but got %q", tt.want.zoneLimits[i]["zone"], z["zone"])
357345
}
358346
}
359347
case handleError:

0 commit comments

Comments
 (0)