Skip to content

Commit

Permalink
Merge pull request #7 from amorenoz/ci
Browse files Browse the repository at this point in the history
Add extremely basic CI
  • Loading branch information
amorenoz authored Jun 11, 2021
2 parents 73d4486 + 15ecfea commit e4ffb7b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ovnmon-ci

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build & Unit Test
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.16
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: make

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.1

17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gocyclo
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ clean:
@rm -rf $(BIN_PATH)

$(MODEL_GEN):
go install github.com/ovn-org/libovsdb/cmd/modelgen
@go install github.com/ovn-org/libovsdb/cmd/modelgen

$(BIN_PATH)/$(BINARY_NAME): $(MODEL_GEN)
PATH="$${PATH}:$${GOPATH}/bin" go generate ./...
go build -o $@ $(BINARY_MOD)
@export PATH="$${PATH}:$${GOPATH}/bin"; go generate ./...
@go build -o $@ $(BINARY_MOD)



13 changes: 5 additions & 8 deletions cmd/ovnmon/ovnmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ const (
)

var (
ovs *client.OvsdbClient
db = flag.String("db", "", "Database connection. Default: unix:/${OVS_RUNDIR}/ovnnb_db.sock")
auto = flag.Bool("auto", false, "Autostart: If set to true, it will start monitoring from the begining")
auto = flag.Bool("auto", false, "Autostart: If set to true, it will start monitoring from the beginning")
)

type ormSignal struct{}

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s [FLAGS] [COMMAND] \n", os.Args[0])
Expand All @@ -39,11 +36,11 @@ func main() {
if *db != "" {
addr = *db
} else {
var ovs_rundir = os.Getenv("OVS_RUNDIR")
if ovs_rundir == "" {
ovs_rundir = "/var/run/openvswitch"
var ovsRundir = os.Getenv("OVS_RUNDIR")
if ovsRundir == "" {
ovsRundir = "/var/run/openvswitch"
}
addr = "unix:" + ovs_rundir + "/" + ovnnbSocket
addr = "unix:" + ovsRundir + "/" + ovnnbSocket
}

dbModel, err := model.FullDatabaseModel()
Expand Down
16 changes: 11 additions & 5 deletions cmd/ovnmon/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *OvnShell) Run(ovs *client.OvsdbClient, args ...string) {
Name: "start",
Help: "Start monitoring activity of the OVN DB",
Func: func(c *ishell.Context) {
ovnShell := c.Get("ovnShell")
ovnShell := c.Get("ovnnShell")
if ovnShell == nil {
c.Println("Error: No context")
}
Expand Down Expand Up @@ -234,10 +234,15 @@ func (s *OvnShell) Run(ovs *client.OvsdbClient, args ...string) {
}

// Render the result table
printer.Append(reflect.Indirect(valueList).Interface())
err = printer.Append(reflect.Indirect(valueList).Interface())
if err != nil {
c.Println(err)
}
printer.Render()
// Print the result table through shell so it can be paged
c.ShowPaged(buffer.String())
if err := c.ShowPaged(buffer.String()); err != nil {
panic(err)
}
},
Completer: func(args []string) []string {
return tableFields[tableName]
Expand All @@ -249,8 +254,9 @@ func (s *OvnShell) Run(ovs *client.OvsdbClient, args ...string) {

// If we have arguments, just run them and exit
if len(args) > 0 {
shell.Process(args...)
return
if err := shell.Process(args...); err != nil {
panic(err)
}
}
shell.Run()
}
Expand Down
1 change: 0 additions & 1 deletion cmd/ovnmon/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func NewStructPrinter(writer io.Writer, stype reflect.Type, fieldSel ...string)
}
}
cols = fieldSel
cols = fieldSel
} else {
for i := 0; i < stype.NumField(); i++ {
field := stype.Field(i).Name
Expand Down

0 comments on commit e4ffb7b

Please sign in to comment.