Skip to content

Commit

Permalink
rename model.Model interface's Table func name, avoid conflict with sb
Browse files Browse the repository at this point in the history
  • Loading branch information
halfcrazy committed Oct 7, 2023
1 parent 50f2203 commit da639d7
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 43 deletions.
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ Temporary Items
*.cov
example/vswitchd/ovs.ovsschema
example/vswitchd/*.go
!example/vswitchd/gen.go
!example/vswitchd/gen.go
example/vtep/vtep.ovsschema
example/vtep/*.go
!example/vtep/gen.go
example/nb/ovn-nb.ovsschema
example/nb/*.go
!example/nb/gen.go
example/sb/ovn-sb.ovsschema
example/sb/*.go
!example/sb/gen.go
example/icnb/ovn-ic-nb.ovsschema
example/icnb/*.go
!example/icnb/gen.go
example/icsb/ovn-ic-sb.ovsschema
example/icsb/*.go
!example/icsb/gen.go
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OVS_VERSION ?= v2.16.0
OVS_VERSION ?= v2.17.7
OVN_VERSION ?= v22.03.4

.PHONY: all
all: lint build test integration-test coverage
Expand All @@ -9,12 +10,12 @@ modelgen:
@go build -v -o ./bin ./cmd/modelgen

.PHONY: prebuild
prebuild: modelgen ovsdb/serverdb/_server.ovsschema example/vswitchd/ovs.ovsschema
prebuild: modelgen ovsdb/serverdb/_server.ovsschema example/vswitchd/ovs.ovsschema example/vtep/vtep.ovsschema example/nb/ovn-nb.ovsschema example/sb/ovn-sb.ovsschema example/icnb/ovn-ic-nb.ovsschema example/icsb/ovn-ic-sb.ovsschema
@echo "+ $@"
@go generate -v ./...

.PHONY: build
build: prebuild
build: prebuild
@echo "+ $@"
@go build -v ./...

Expand Down Expand Up @@ -56,3 +57,18 @@ ovsdb/serverdb/_server.ovsschema:

example/vswitchd/ovs.ovsschema:
@curl -sSL https://raw.githubusercontent.com/openvswitch/ovs/${OVS_VERSION}/vswitchd/vswitch.ovsschema -o $@

example/vtep/vtep.ovsschema:
@curl -sSL https://raw.githubusercontent.com/openvswitch/ovs/${OVS_VERSION}/vtep/vtep.ovsschema -o $@

example/nb/ovn-nb.ovsschema:
@curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/${OVN_VERSION}/ovn-nb.ovsschema -o $@

example/sb/ovn-sb.ovsschema:
@curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/${OVN_VERSION}/ovn-sb.ovsschema -o $@

example/icnb/ovn-ic-nb.ovsschema:
@curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/${OVN_VERSION}/ovn-ic-nb.ovsschema -o $@

example/icsb/ovn-ic-sb.ovsschema:
@curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/${OVN_VERSION}/ovn-ic-sb.ovsschema -o $@
16 changes: 8 additions & 8 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type testModel struct {
Datapath *string `ovsdb:"datapath"`
}

func (t *testModel) Table() string {
func (t *testModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -379,7 +379,7 @@ type testModel1 struct {
Bar map[string]string `ovsdb:"bar"`
}

func (t *testModel1) Table() string {
func (t *testModel1) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -807,7 +807,7 @@ type testModel2 struct {
Baz string `ovsdb:"baz"`
}

func (t *testModel2) Table() string {
func (t *testModel2) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -1058,7 +1058,7 @@ type testModel3 struct {
Bar map[string]string `ovsdb:"bar"`
}

func (t *testModel3) Table() string {
func (t *testModel3) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -1922,7 +1922,7 @@ type badModel struct {
Baz string `ovsdb:"baz"`
}

func (b *badModel) Table() string {
func (b *badModel) GetTableName() string {
return "bad"
}

Expand Down Expand Up @@ -2156,7 +2156,7 @@ type testModel4 struct {
Baz map[string]string `ovsdb:"baz"`
}

func (t *testModel4) Table() string {
func (t *testModel4) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -2331,7 +2331,7 @@ type rowsByConditionTestModel struct {
Empty string `ovsdb:"empty"`
}

func (r *rowsByConditionTestModel) Table() string {
func (r *rowsByConditionTestModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -2747,7 +2747,7 @@ type testDBModel struct {
Set []string `ovsdb:"set"`
}

func (t *testDBModel) Table() string {
func (t *testDBModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down
2 changes: 1 addition & 1 deletion client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (a api) Wait(untilConFun ovsdb.WaitCondition, timeout *int, model model.Mod
// getTableFromModel returns the table name from a Model object after performing
// type verifications on the model
func (a api) getTableFromModel(m model.Model) (string, error) {
table := m.Table()
table := m.GetTableName()
_, found := a.cache.DatabaseModel().Types()[table]
if table == "" || !found {
return "", &ErrWrongType{reflect.TypeOf(m), "Model not found in Database Model"}
Expand Down
10 changes: 5 additions & 5 deletions client/api_test_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ type testLogicalSwitch struct {
Acls []string `ovsdb:"acls"`
}

// Table returns the table name. It's part of the Model interface
func (*testLogicalSwitch) Table() string {
// GetTableName returns the table name. It's part of the Model interface
func (*testLogicalSwitch) GetTableName() string {
return "Logical_Switch"
}

//LogicalSwitchPort struct defines an object in Logical_Switch_Port table
// LogicalSwitchPort struct defines an object in Logical_Switch_Port table
type testLogicalSwitchPort struct {
UUID string `ovsdb:"_uuid"`
Up *bool `ovsdb:"up"`
Expand All @@ -148,8 +148,8 @@ type testLogicalSwitchPort struct {
ParentName *string `ovsdb:"parent_name"`
}

// Table returns the table name. It's part of the Model interface
func (*testLogicalSwitchPort) Table() string {
// GetTableName returns the table name. It's part of the Model interface
func (*testLogicalSwitchPort) GetTableName() string {
return "Logical_Switch_Port"
}

Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Bridge struct {
STPEnable bool `ovsdb:"stp_enable"`
}

func (b *Bridge) Table() string {
func (b *Bridge) GetTableName() string {
return "Bridge"
}

Expand All @@ -107,7 +107,7 @@ type OpenvSwitch struct {
SystemVersion *string `ovsdb:"system_version"`
}

func (o *OpenvSwitch) Table() string {
func (o *OpenvSwitch) GetTableName() string {
return "Open_vSwitch"
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/stress/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type bridgeType struct {
Status map[string]string `ovsdb:"status"`
}

func (b *bridgeType) Table() string {
func (b *bridgeType) GetTableName() string {
return "Bridge"
}

Expand All @@ -39,7 +39,7 @@ type ovsType struct {
Bridges []string `ovsdb:"bridges"`
}

func (o *ovsType) Table() string {
func (o *ovsType) GetTableName() string {
return "Open_vSwitch"
}

Expand Down
3 changes: 3 additions & 0 deletions example/icnb/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package icnb

//go:generate ../../bin/modelgen --extended -p icnb -o . ovn-ic-nb.ovsschema
3 changes: 3 additions & 0 deletions example/icsb/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package icsb

//go:generate ../../bin/modelgen --extended -p icsb -o . ovn-ic-sb.ovsschema
3 changes: 3 additions & 0 deletions example/nb/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package nb

//go:generate ../../bin/modelgen --extended -p nb -o . ovn-nb.ovsschema
3 changes: 3 additions & 0 deletions example/sb/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package sb

//go:generate ../../bin/modelgen --extended -p sb -o . ovn-sb.ovsschema
3 changes: 3 additions & 0 deletions example/vtep/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package vtep

//go:generate ../../bin/modelgen --extended -p vtep -o . vtep.ovsschema
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// LoadBalancers []string `ovsdb:"load_balancer"`
// }
type Model interface {
Table() string
GetTableName() string
}

type CloneableModel interface {
Expand Down
17 changes: 13 additions & 4 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type modelA struct {
UUID string `ovsdb:"_uuid"`
}

func (m *modelA) Table() string {
func (m *modelA) GetTableName() string {
return "A"
}

Expand All @@ -24,15 +24,15 @@ type modelB struct {
Bar string `ovsdb:"baz"`
}

func (m *modelB) Table() string {
func (m *modelB) GetTableName() string {
return "B"
}

type modelInvalid struct {
Foo string
}

func (m *modelInvalid) Table() string {
func (m *modelInvalid) GetTableName() string {
return "Invalid"
}

Expand Down Expand Up @@ -107,7 +107,7 @@ type testTable struct {
AMap map[string]string `ovsdb:"aMap"`
}

func (t *testTable) Table() string {
func (t *testTable) GetTableName() string {
return "TestTable"
}

Expand Down Expand Up @@ -454,3 +454,12 @@ func TestEqualViaComparable(t *testing.T) {
a.UID = "baz"
assert.False(t, Equal(a, b))
}

func TestGetTableName(t *testing.T) {
a := &testTable{}
func(a interface{}) {
m, ok := a.(Model)
assert.True(t, ok, "is not a model")
assert.Equal(t, m.GetTableName(), "TestTable")
}(a)
}
2 changes: 1 addition & 1 deletion modelgen/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ type {{ index . "StructName" }} struct {
{{ end }}
{{ template "extraFields" . }}
}
func (a *{{ index . "StructName" }}) Table() string {
func (a *{{ index . "StructName" }}) GetTableName() string {
return {{ index . "StructName" }}Table
}
{{ template "postStructDefinitions" . }}
Expand Down
Loading

0 comments on commit da639d7

Please sign in to comment.