@@ -16,12 +16,20 @@ package ovs
16
16
17
17
import (
18
18
"errors"
19
- "fmt"
20
19
"regexp"
21
20
"strconv"
22
21
"strings"
23
22
)
24
23
24
+ var (
25
+ errMissingDataPathName = errors .New ("datapath name argument is mandatory" )
26
+ errUninitializedClient = errors .New ("client unitialized" )
27
+ errMissingMandatoryZone = errors .New ("at least 1 zone is mandatory" )
28
+ errWrongArgumentNumber = errors .New ("missing or too much arguments to setup ct limits" )
29
+ errWrongDefaultArgument = errors .New ("wrong argument while setting default ct limits" )
30
+ errWrongZoneArgument = errors .New ("wrong argument while setting zone ct limits" )
31
+ )
32
+
25
33
// Zone defines the type used to store a zone as it is returned
26
34
// by ovs-dpctl ct-*-limits commands
27
35
type Zone map [string ]uint64
@@ -84,10 +92,10 @@ type CLI interface {
84
92
Exec (args ... string ) ([]byte , error )
85
93
}
86
94
87
- // DataPathService defines the conrete type used for DataPath operations
95
+ // DataPathService defines the concrete type used for DataPath operations
88
96
// supported by the ovs-dpctl command
89
97
type DataPathService struct {
90
- // We define here a CLI interface making easier to mock pvs -dpctl command
98
+ // We define here a CLI interface making easier to mock ovs -dpctl command
91
99
// as in github.com/digitalocean/go-openvswitch/ovs/datapath_test.go
92
100
CLI
93
101
}
@@ -133,7 +141,7 @@ func (dp *DataPathService) AddDataPath(dpName string) ([]byte, error) {
133
141
return dp .CLI .Exec (args ... )
134
142
}
135
143
136
- // DelDataPath create a Datapath with the command 'ovs-dpctl add -dp <DP>'
144
+ // DelDataPath create a Datapath with the command 'ovs-dpctl del -dp <DP>'
137
145
// It takes one argument, the required DataPath Name and returns an error
138
146
// if it failed
139
147
func (dp * DataPathService ) DelDataPath (dpName string ) ([]byte , error ) {
@@ -148,7 +156,7 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
148
156
// Start by building the args
149
157
args := []string {"ct-get-limits" }
150
158
if dpName == "" {
151
- return nil , errors . New ( "datapath name argument is mandatory" )
159
+ return nil , errMissingDataPathName
152
160
}
153
161
154
162
args = append (args , dpName )
@@ -170,7 +178,6 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
170
178
171
179
r , err := regexp .Compile (`default` )
172
180
if err != nil {
173
- fmt .Println (err .Error ())
174
181
return nil , err
175
182
}
176
183
@@ -212,7 +219,7 @@ func (dp *DataPathService) GetCTLimits(dpName string, zones []uint64) (*ConnTrac
212
219
func (dp * DataPathService ) SetCTLimits (dpName string , zone map [string ]uint64 ) (string , error ) {
213
220
// Sanitize the input
214
221
if dpName == "" {
215
- return "" , errors . New ( "datapath name is required" )
222
+ return "" , errMissingDataPathName
216
223
}
217
224
argsStr , err := ctSetLimitsArgsToString (zone )
218
225
if err != nil {
@@ -230,10 +237,10 @@ func (dp *DataPathService) SetCTLimits(dpName string, zone map[string]uint64) (s
230
237
// sudo ovs-dpctl ct-del-limits system@ovs-system zone=40,4
231
238
func (dp * DataPathService ) DelCTLimits (dpName string , zones []uint64 ) (string , error ) {
232
239
if dpName == "" {
233
- return "" , errors . New ( "datapath name is missing" )
240
+ return "" , errMissingDataPathName
234
241
}
235
242
if len (zones ) < 1 {
236
- return "" , errors . New ( "at least 1 zone is mandatory" )
243
+ return "" , errMissingMandatoryZone
237
244
}
238
245
239
246
var firstZone uint64
@@ -268,18 +275,18 @@ func ctSetLimitsArgsToString(zone map[string]uint64) (string, error) {
268
275
269
276
// We need at most 2 arguments and at least 1
270
277
if len (args ) == 0 || len (args ) > 2 {
271
- return "" , errors . New ( "missing or too much arguments to setup ct limits" )
278
+ return "" , errWrongArgumentNumber
272
279
273
280
}
274
281
// if we setup the default global setting we only need a single parameter
275
282
// like "default=100000" and nothing else
276
283
if defaultSetup && len (args ) != 1 {
277
- return "" , errors . New ( "wrong argument while setting default ct limits" )
284
+ return "" , errWrongDefaultArgument
278
285
}
279
286
// if we setup a limit for dedicated zone we need 2 params like
280
287
// "zone=3" and "limit=50000"
281
288
if ! defaultSetup && len (args ) != 2 {
282
- return "" , errors . New ( "wrong argument while setting zone ct limits" )
289
+ return "" , errWrongZoneArgument
283
290
}
284
291
285
292
var argsStr string
@@ -328,7 +335,7 @@ type OvsCLI struct {
328
335
// Exec executes 'ovs-dpctl' + args passed in argument
329
336
func (cli * OvsCLI ) Exec (args ... string ) ([]byte , error ) {
330
337
if cli .c == nil {
331
- return nil , errors . New ( "client unitialized" )
338
+ return nil , errUninitializedClient
332
339
}
333
340
334
341
return cli .c .exec ("ovs-dpctl" , args ... )
0 commit comments