Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
core:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.24.x]
platform: [ubuntu-latest]
name: Build
runs-on: ${{ matrix.platform }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Generate coverage report
run: make coverage
- name: Upload coverage report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Coverage Report
path: .coverage/coverage.html
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ rights:
@sudo chmod o+rw /run/ovn/ovnsb_db.sock || true

linter:
@golint
@echo "PASS: golint"
@golangci-lint run ./...
@echo "PASS: golangci-lint"

test: covdir linter rights
@go test $(VERBOSE) -coverprofile=.coverage/coverage.out
Expand All @@ -50,7 +50,7 @@ clean:

dep:
@echo "Making dependencies check ..."
@go install golang.org/x/lint/golint@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/kyoh86/richgo@latest
@go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
@go install github.com/greenpau/versioned/cmd/versioned@latest
Expand Down
62 changes: 29 additions & 33 deletions app_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
}
if strings.HasPrefix(line, "Name:") {
parserOn = true
s := strings.TrimLeft(line, "Name: ")
s := strings.TrimPrefix(line, "Name: ")
s = strings.Join(strings.Fields(s), " ")
server.Database = s
continue
Expand All @@ -111,7 +111,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
continue
}
if strings.HasPrefix(line, "Cluster ID:") {
s := strings.TrimLeft(line, "Cluster ID:")
s := strings.TrimPrefix(line, "Cluster ID:")
s = strings.Join(strings.Fields(strings.TrimSpace(s)), " ")
arr := strings.Split(s, " ")
if len(arr) != 2 {
Expand All @@ -124,7 +124,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
}
continue
} else if strings.HasPrefix(line, "Server ID:") {
s := strings.TrimLeft(line, "Server ID:")
s := strings.TrimPrefix(line, "Server ID:")
s = strings.Join(strings.Fields(strings.TrimSpace(s)), " ")
arr := strings.Split(s, " ")
if len(arr) != 2 {
Expand All @@ -137,12 +137,12 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
}
continue
} else if strings.HasPrefix(line, "Address:") {
s := strings.TrimLeft(line, "Address:")
s := strings.TrimPrefix(line, "Address:")
s = strings.Join(strings.Fields(s), " ")
server.Address = s
continue
} else if strings.HasPrefix(line, "Status:") {
s := strings.TrimLeft(line, "Status:")
s := strings.TrimPrefix(line, "Status:")
s = strings.Join(strings.Fields(s), " ")
switch s {
case "cluster member":
Expand All @@ -152,7 +152,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
}
continue
} else if strings.HasPrefix(line, "Role:") {
s := strings.TrimLeft(line, "Role:")
s := strings.TrimPrefix(line, "Role:")
s = strings.Join(strings.Fields(s), " ")
switch s {
case "leader":
Expand All @@ -166,29 +166,29 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
}
continue
} else if strings.HasPrefix(line, "Term:") {
s := strings.TrimLeft(line, "Term:")
s := strings.TrimPrefix(line, "Term:")
s = strings.Join(strings.Fields(s), " ")
if term, err := strconv.ParseUint(s, 10, 64); err == nil {
server.Term = term
}
} else if strings.HasPrefix(line, "Leader:") {
s := strings.TrimLeft(line, "Leader:")
s := strings.TrimPrefix(line, "Leader:")
s = strings.Join(strings.Fields(s), " ")
if s == "self" {
server.IsLeaderSelf = 1
} else {
server.IsLeaderSelf = 0
}
} else if strings.HasPrefix(line, "Vote:") {
s := strings.TrimLeft(line, "Vote:")
s := strings.TrimPrefix(line, "Vote:")
s = strings.Join(strings.Fields(s), " ")
if s == "self" {
server.IsVotedSelf = 1
} else {
server.IsVotedSelf = 0
}
} else if strings.HasPrefix(line, "Log:") {
s := strings.TrimLeft(line, "Log:")
s := strings.TrimPrefix(line, "Log:")
s = strings.Join(strings.Fields(s), " ")
s = strings.TrimLeft(s, "[")
s = strings.TrimRight(s, "]")
Expand All @@ -205,19 +205,19 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
server.Log.High = i
}
} else if strings.HasPrefix(line, "Entries not yet committed:") {
s := strings.TrimLeft(line, "Entries not yet committed:")
s := strings.TrimPrefix(line, "Entries not yet committed:")
s = strings.Join(strings.Fields(s), " ")
if i, err := strconv.ParseUint(s, 10, 64); err == nil {
server.NotCommittedEntries = i
}
} else if strings.HasPrefix(line, "Entries not yet applied:") {
s := strings.TrimLeft(line, "Entries not yet applied:")
s := strings.TrimPrefix(line, "Entries not yet applied:")
s = strings.Join(strings.Fields(s), " ")
if i, err := strconv.ParseUint(s, 10, 64); err == nil {
server.NotAppliedEntries = i
}
} else if strings.HasPrefix(line, "Connections:") {
s := strings.TrimLeft(line, "Connections:")
s := strings.TrimPrefix(line, "Connections:")
s = strings.Join(strings.Fields(s), " ")
conns := strings.Split(strings.Join(strings.Fields(s), " "), " ")
for _, entry := range conns {
Expand Down Expand Up @@ -270,45 +270,41 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
var peerMatchIndex uint64
for _, e := range arr {
if strings.HasPrefix(e, "tcp:") || strings.HasPrefix(e, "ssl:") {
if isSelf != true {
if !isSelf {
peerAddress = strings.TrimRight(e, ")")
}
} else if strings.HasPrefix(e, "next_index=") {
nextIndex := strings.TrimLeft(e, "next_index=")
nextIndex := strings.TrimPrefix(e, "next_index=")
if i, err := strconv.ParseUint(nextIndex, 10, 64); err == nil {
if isSelf == true {
if isSelf {
server.NextIndex = i
} else {
peerNextIndex = i
}
}
} else if strings.HasPrefix(e, "match_index=") {
matchIndex := strings.TrimLeft(e, "match_index=")
matchIndex := strings.TrimPrefix(e, "match_index=")
if i, err := strconv.ParseUint(matchIndex, 10, 64); err == nil {
if isSelf == true {
if isSelf {
server.MatchIndex = i
} else {
peerMatchIndex = i
}
}
} else {
// do nothing
}
}
if isSelf != true {
if _, exists := server.Peers[peerID]; !exists {
peer := ClusterPeer{}
peer.ID = peerID
server.Peers[peerID] = &peer
if !isSelf {
if _, exists := server.Peers[peerID]; !exists {
peer := ClusterPeer{}
peer.ID = peerID
server.Peers[peerID] = &peer
}
peer := server.Peers[peerID]
peer.NextIndex = peerNextIndex
peer.MatchIndex = peerMatchIndex
peer.Address = peerAddress
}
peer := server.Peers[peerID]
peer.NextIndex = peerNextIndex
peer.MatchIndex = peerMatchIndex
peer.Address = peerAddress
continue
}
continue
} else {
// do nothing
}
}
//spew.Dump(server)
Expand Down
33 changes: 15 additions & 18 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ovsdb
import (
"encoding/json"
"fmt"

//"github.com/davecgh/go-spew/spew"
"io"
//"math/rand"
Expand Down Expand Up @@ -58,7 +59,7 @@ func NewClient(s string, t int) (Client, error) {
cli.errQueue = make(chan error, 1)
go ovsdbMessenger(cli.Endpoint, cli.Timeout, cli.txQueue, cli.rxQueue, cli.errQueue)
err := <-cli.errQueue
return cli, err
return cli, err //nolint:govet
}

// Close TODO
Expand All @@ -82,7 +83,7 @@ func (cli *Client) query(method string, param interface{}) (*Response, error) {
Params: param,
}
for {
if cli.closed == false {
if !cli.closed {
cli.txQueue <- req
select {
case err := <-cli.errQueue:
Expand Down Expand Up @@ -114,7 +115,6 @@ func (cli *Client) query(method string, param interface{}) (*Response, error) {
retryAttempts--
}
}
return nil, fmt.Errorf("%s", errMsgs)
}

func (cli *Client) getColumns(db, table string) (map[string]string, error) {
Expand Down Expand Up @@ -266,20 +266,18 @@ func ovsdbMessenger(s string, t int, rxQueue <-chan Request, txQueue chan<- Resp
errQueue <- nil
cli := newClientCodec(conn)
for {
select {
case reqMsg := <-rxQueue:
var req rpc.Request
if reqMsg.Method == "shutdown" {
cli.Close()
errQueue <- nil
return
}
req.ServiceMethod = reqMsg.Method
req.Seq = counter
if err := cli.WriteRequest(&req, reqMsg.Params); err != nil {
errQueue <- err
return
}
reqMsg := <-rxQueue
var req rpc.Request
if reqMsg.Method == "shutdown" {
cli.Close()
errQueue <- nil
return
}
req.ServiceMethod = reqMsg.Method
req.Seq = counter
if err := cli.WriteRequest(&req, reqMsg.Params); err != nil {
errQueue <- err
return
}
if err := cli.ReadResponseHeader(&resp); err != nil {
errQueue <- err
Expand Down Expand Up @@ -319,5 +317,4 @@ func ovsdbMessenger(s string, t int, rxQueue <-chan Request, txQueue chan<- Resp
}
txQueue <- respMsg
}
return
}
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type OvsDatabase struct {
Schema struct {
Version string
}
connected bool
connected bool //nolint:unused
}

// Databases - DOCS-TBD
Expand Down
11 changes: 9 additions & 2 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ func TestListDatabasesMethod(t *testing.T) {
t.Fatalf("FAIL: expected to find a single database, but found: %d", len(databases))
}
dbName := "Open_vSwitch"
if databases[0] != dbName {
t.Fatalf("FAIL: expected to find '%s' database, but found: %s", dbName, databases[0])
found := false
for _, db := range databases {
if db == dbName {
found = true
break
}
}
if !found {
t.Fatalf("FAIL: expected to find '%s' database in %v", dbName, databases)
}
t.Logf("PASS: 'list_dbs' method completed successfully")
}
Expand Down
2 changes: 1 addition & 1 deletion echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Client) Echo(s string) error {
method := "echo"
js, err := encodeString(s)
if err != nil {
fmt.Errorf("'%s' method failed: %v", method, err)
_ = fmt.Errorf("'%s' method failed: %v", method, err)
}
response, err := c.query(method, js)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var methods = map[string]method{
"get_schema": {Name: "get_schema"},
"transact": {Name: "transact"},
"list-commands": {Name: "list-commands"},
"version": {Name: "version"},
"coverage/show": {Name: "coverage/show"},
"memory/show": {Name: "memory/show"},
"cluster/status": {Name: "cluster/status"},
Expand All @@ -56,7 +57,7 @@ func newOvsdbEncoder(w io.Writer) *ovsdbEncoder {
// An encodeState encodes JSON into a bytes.Buffer.
type encodeState struct {
bytes.Buffer // accumulated output
scratch [64]byte
scratch [64]byte //nolint:unused
}

var encodeStatePool sync.Pool
Expand Down Expand Up @@ -111,6 +112,7 @@ func (enc *ovsdbEncoder) Encode(v interface{}) error {
e.WriteString(s)
// e.WriteString("\"Open_vSwitch\",{\"op\":\"select\",\"table\":\"Open_vSwitch\",\"where\":[]}")
case "list-commands":
case "version":
case "coverage/show":
case "memory/show":
case "dpif/show":
Expand Down
Loading