Gosec failure fixes and ci checks ajdustment
Change-Id: I430c3118b585ba924649ed32e8196e0e7e0bc260
diff --git a/.golangci.yml b/.golangci.yml
index 6e45424..fd4cae0 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -15,12 +15,19 @@
run:
modules-download-mode: vendor
+issues:
+ exclude-use-default: false #we should decide ourselves about false positives
+ exclude-rules:
+ - linters:
+ - gosec
+ text: "G103:" #this rule is a false positive as there is no recommendation how to audit unsafe usages
+
linters:
enable:
#- gochecknoglobals
#- gochecknoinits
- #- gocritic
+ - gocritic
- gofmt
- gosec
- #- golint
+ - errcheck
#- unparam
diff --git a/VERSION b/VERSION
index fdd3be6..266146b 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.6.2
+1.6.3
diff --git a/cmd/ofagent/main.go b/cmd/ofagent/main.go
index 8a769be..b2e32fe 100644
--- a/cmd/ofagent/main.go
+++ b/cmd/ofagent/main.go
@@ -100,12 +100,12 @@
}
// Setup default logger - applies for packages that do not have specific logger set
- if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": config.InstanceID}); err != nil {
+ if _, err = log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": config.InstanceID}); err != nil {
logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
// Update all loggers (provisionned via init) with a common field
- if err := log.UpdateAllLoggers(log.Fields{"instanceId": config.InstanceID}); err != nil {
+ if err = log.UpdateAllLoggers(log.Fields{"instanceId": config.InstanceID}); err != nil {
logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
@@ -115,7 +115,7 @@
realMain()
defer func() {
- err := log.CleanUp()
+ err = log.CleanUp()
if err != nil {
logger.Errorw(ctx, "unable-to-flush-any-buffered-log-entries", log.Fields{"error": err})
}
@@ -139,7 +139,12 @@
if err != nil {
logger.Warnw(ctx, "unable-to-initialize-tracing-and-log-correlation-module", log.Fields{"error": err})
} else {
- defer closer.Close()
+ defer func() {
+ err = closer.Close()
+ if err != nil {
+ logger.Errorf(ctx, "failed to close global LFM: %v", err)
+ }
+ }()
}
ofa, err := ofagent.NewOFAgent(ctx, &ofagent.OFAgent{
diff --git a/internal/pkg/ofagent/connection.go b/internal/pkg/ofagent/connection.go
index 6bfd0af..017c00d 100644
--- a/internal/pkg/ofagent/connection.go
+++ b/internal/pkg/ofagent/connection.go
@@ -35,7 +35,10 @@
}
if ofa.volthaConnection != nil {
- ofa.volthaConnection.Close()
+ err := ofa.volthaConnection.Close()
+ if err != nil {
+ logger.Errorw(ctx, "failed-connection-close-proceeding-setting-to-nil", log.Fields{"error": err})
+ }
}
ofa.volthaConnection = nil
diff --git a/internal/pkg/openflow/connection.go b/internal/pkg/openflow/connection.go
index 87a50b3..b9c1c71 100644
--- a/internal/pkg/openflow/connection.go
+++ b/internal/pkg/openflow/connection.go
@@ -72,7 +72,10 @@
if ofc.conn != nil {
logger.Debugw(ctx, "closing-of-connection-to-reconnect",
log.Fields{"device-id": ofc.DeviceID})
- ofc.conn.Close()
+ err := ofc.conn.Close()
+ if err != nil {
+ logger.Errorw(ctx, "failed-connection-close-proceeding-setting-to-nil", log.Fields{"error": err})
+ }
ofc.conn = nil
}
try := 1
@@ -216,7 +219,10 @@
if ofc.conn != nil {
logger.Debugw(ctx, "closing-of-connection",
log.Fields{"device-id": ofc.DeviceID})
- ofc.conn.Close()
+ err := ofc.conn.Close()
+ if err != nil {
+ logger.Errorw(ctx, "closing-of-connection", log.Fields{"error": err})
+ }
ofc.conn = nil
}
logger.Debugw(ctx, "state-machine-finished",
diff --git a/internal/pkg/openflow/stats_test.go b/internal/pkg/openflow/stats_test.go
index cad0352..8c832c2 100644
--- a/internal/pkg/openflow/stats_test.go
+++ b/internal/pkg/openflow/stats_test.go
@@ -124,7 +124,7 @@
flows = append(flows, &flow)
- n = n + 1
+ n++
}
return flows
}
@@ -154,7 +154,7 @@
ports = append(ports, &port)
- n = n + 1
+ n++
}
return ports
}
@@ -229,7 +229,7 @@
t.Fatal("Message size is bigger than 64KB")
}
- entriesCount = entriesCount + len(r.GetEntries())
+ entriesCount += len(r.GetEntries())
n++
}
// make sure all the generate item are included in the responses
@@ -276,7 +276,7 @@
t.Fatal("Message size is bigger than 64KB")
}
- entriesCount = entriesCount + len(r.GetEntries())
+ entriesCount += len(r.GetEntries())
n++
}
@@ -322,7 +322,7 @@
t.Fatal("Message size is bigger than 64KB")
}
- entriesCount = entriesCount + len(r.GetEntries())
+ entriesCount += len(r.GetEntries())
n++
}