From da639d785db2bd278f827f13f3a779f2c18f7b3f Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Wed, 27 Sep 2023 19:45:21 +0800 Subject: [PATCH] rename model.Model interface's Table func name, avoid conflict with sb https://github.com/ovn-org/ovn/blob/686caaf66d5be811c655ea2938b082564d5f5f75/ovn-sb.ovsschema#L383 Signed-off-by: Yan Zhu --- .gitignore | 17 +++++++- Makefile | 22 ++++++++-- cache/cache_test.go | 16 +++---- client/api.go | 2 +- client/api_test_model.go | 10 ++--- client/client_test.go | 4 +- cmd/stress/stress.go | 4 +- example/icnb/gen.go | 3 ++ example/icsb/gen.go | 3 ++ example/nb/gen.go | 3 ++ example/sb/gen.go | 3 ++ example/vtep/gen.go | 3 ++ model/model.go | 2 +- model/model_test.go | 17 ++++++-- modelgen/table.go | 2 +- modelgen/table_test.go | 73 +++++++++++++++++++++++++++++--- ovsdb/serverdb/database.go | 2 +- test/ovs/ovs_integration_test.go | 8 ++-- test/test_data.go | 6 +-- 19 files changed, 157 insertions(+), 43 deletions(-) create mode 100644 example/icnb/gen.go create mode 100644 example/icsb/gen.go create mode 100644 example/nb/gen.go create mode 100644 example/sb/gen.go create mode 100644 example/vtep/gen.go diff --git a/.gitignore b/.gitignore index b64d0470..0c14df28 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,19 @@ Temporary Items *.cov example/vswitchd/ovs.ovsschema example/vswitchd/*.go -!example/vswitchd/gen.go \ No newline at end of file +!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 diff --git a/Makefile b/Makefile index af63e7db..37f31fc4 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ./... @@ -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 $@ diff --git a/cache/cache_test.go b/cache/cache_test.go index 1b56e14d..d87344fc 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -24,7 +24,7 @@ type testModel struct { Datapath *string `ovsdb:"datapath"` } -func (t *testModel) Table() string { +func (t *testModel) GetTableName() string { return "Open_vSwitch" } @@ -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" } @@ -807,7 +807,7 @@ type testModel2 struct { Baz string `ovsdb:"baz"` } -func (t *testModel2) Table() string { +func (t *testModel2) GetTableName() string { return "Open_vSwitch" } @@ -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" } @@ -1922,7 +1922,7 @@ type badModel struct { Baz string `ovsdb:"baz"` } -func (b *badModel) Table() string { +func (b *badModel) GetTableName() string { return "bad" } @@ -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" } @@ -2331,7 +2331,7 @@ type rowsByConditionTestModel struct { Empty string `ovsdb:"empty"` } -func (r *rowsByConditionTestModel) Table() string { +func (r *rowsByConditionTestModel) GetTableName() string { return "Open_vSwitch" } @@ -2747,7 +2747,7 @@ type testDBModel struct { Set []string `ovsdb:"set"` } -func (t *testDBModel) Table() string { +func (t *testDBModel) GetTableName() string { return "Open_vSwitch" } diff --git a/client/api.go b/client/api.go index 1a427c9b..b8cfd210 100644 --- a/client/api.go +++ b/client/api.go @@ -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"} diff --git a/client/api_test_model.go b/client/api_test_model.go index 36ea476e..677761e6 100644 --- a/client/api_test_model.go +++ b/client/api_test_model.go @@ -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"` @@ -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" } diff --git a/client/client_test.go b/client/client_test.go index 23ac2da9..9eeec738 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -81,7 +81,7 @@ type Bridge struct { STPEnable bool `ovsdb:"stp_enable"` } -func (b *Bridge) Table() string { +func (b *Bridge) GetTableName() string { return "Bridge" } @@ -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" } diff --git a/cmd/stress/stress.go b/cmd/stress/stress.go index e333be0e..c2948b73 100644 --- a/cmd/stress/stress.go +++ b/cmd/stress/stress.go @@ -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" } @@ -39,7 +39,7 @@ type ovsType struct { Bridges []string `ovsdb:"bridges"` } -func (o *ovsType) Table() string { +func (o *ovsType) GetTableName() string { return "Open_vSwitch" } diff --git a/example/icnb/gen.go b/example/icnb/gen.go new file mode 100644 index 00000000..11a89ee8 --- /dev/null +++ b/example/icnb/gen.go @@ -0,0 +1,3 @@ +package icnb + +//go:generate ../../bin/modelgen --extended -p icnb -o . ovn-ic-nb.ovsschema diff --git a/example/icsb/gen.go b/example/icsb/gen.go new file mode 100644 index 00000000..5eea84c8 --- /dev/null +++ b/example/icsb/gen.go @@ -0,0 +1,3 @@ +package icsb + +//go:generate ../../bin/modelgen --extended -p icsb -o . ovn-ic-sb.ovsschema diff --git a/example/nb/gen.go b/example/nb/gen.go new file mode 100644 index 00000000..136ce7ef --- /dev/null +++ b/example/nb/gen.go @@ -0,0 +1,3 @@ +package nb + +//go:generate ../../bin/modelgen --extended -p nb -o . ovn-nb.ovsschema diff --git a/example/sb/gen.go b/example/sb/gen.go new file mode 100644 index 00000000..f5b5798b --- /dev/null +++ b/example/sb/gen.go @@ -0,0 +1,3 @@ +package sb + +//go:generate ../../bin/modelgen --extended -p sb -o . ovn-sb.ovsschema diff --git a/example/vtep/gen.go b/example/vtep/gen.go new file mode 100644 index 00000000..038afbd7 --- /dev/null +++ b/example/vtep/gen.go @@ -0,0 +1,3 @@ +package vtep + +//go:generate ../../bin/modelgen --extended -p vtep -o . vtep.ovsschema diff --git a/model/model.go b/model/model.go index 57eb9db5..cfe5fb05 100644 --- a/model/model.go +++ b/model/model.go @@ -24,7 +24,7 @@ import ( // LoadBalancers []string `ovsdb:"load_balancer"` // } type Model interface { - Table() string + GetTableName() string } type CloneableModel interface { diff --git a/model/model_test.go b/model/model_test.go index 2e40daf8..390d4144 100644 --- a/model/model_test.go +++ b/model/model_test.go @@ -14,7 +14,7 @@ type modelA struct { UUID string `ovsdb:"_uuid"` } -func (m *modelA) Table() string { +func (m *modelA) GetTableName() string { return "A" } @@ -24,7 +24,7 @@ type modelB struct { Bar string `ovsdb:"baz"` } -func (m *modelB) Table() string { +func (m *modelB) GetTableName() string { return "B" } @@ -32,7 +32,7 @@ type modelInvalid struct { Foo string } -func (m *modelInvalid) Table() string { +func (m *modelInvalid) GetTableName() string { return "Invalid" } @@ -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" } @@ -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) +} diff --git a/modelgen/table.go b/modelgen/table.go index a7cc1854..3b9c7f94 100644 --- a/modelgen/table.go +++ b/modelgen/table.go @@ -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" . }} diff --git a/modelgen/table_test.go b/modelgen/table_test.go index b3e38111..f69194b5 100644 --- a/modelgen/table_test.go +++ b/modelgen/table_test.go @@ -8,7 +8,12 @@ import ( "text/template" "github.com/google/uuid" + "github.com/ovn-org/libovsdb/example/icnb" + "github.com/ovn-org/libovsdb/example/icsb" + "github.com/ovn-org/libovsdb/example/nb" + "github.com/ovn-org/libovsdb/example/sb" "github.com/ovn-org/libovsdb/example/vswitchd" + "github.com/ovn-org/libovsdb/example/vtep" "github.com/ovn-org/libovsdb/model" "github.com/ovn-org/libovsdb/ovsdb" "github.com/stretchr/testify/assert" @@ -81,7 +86,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -108,7 +113,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -160,7 +165,7 @@ type AtomicTable struct { OtherStr string } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -201,7 +206,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -370,7 +375,7 @@ type AtomicTable struct { OtherStr string } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -503,7 +508,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -630,7 +635,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -1020,3 +1025,57 @@ func BenchmarkDeepEqual(b *testing.B) { }) } } + +func TestVswitchedGetTableName(t *testing.T) { + bridge := &vswitchd.Bridge{} + func(bridge interface{}) { + m, ok := bridge.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), vswitchd.BridgeTable) + }(bridge) +} + +func TestVtepGetTableName(t *testing.T) { + sw := &vtep.LogicalSwitch{} + func(sw interface{}) { + m, ok := sw.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), vtep.LogicalSwitchTable) + }(sw) +} + +func TestNBGetTableName(t *testing.T) { + sw := &nb.LogicalSwitch{} + func(sw interface{}) { + m, ok := sw.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), nb.LogicalSwitchTable) + }(sw) +} + +func TestSBGetTableName(t *testing.T) { + p := &sb.RBACPermission{} + func(p interface{}) { + m, ok := p.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), sb.RBACPermissionTable) + }(p) +} + +func TestICNBGetTableName(t *testing.T) { + sw := &icnb.TransitSwitch{} + func(sw interface{}) { + m, ok := sw.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), icnb.TransitSwitchTable) + }(sw) +} + +func TestICSBGetTableName(t *testing.T) { + gw := &icsb.Gateway{} + func(gw interface{}) { + m, ok := gw.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), icsb.GatewayTable) + }(gw) +} diff --git a/ovsdb/serverdb/database.go b/ovsdb/serverdb/database.go index 8d6f4ad7..52b948c5 100644 --- a/ovsdb/serverdb/database.go +++ b/ovsdb/serverdb/database.go @@ -30,7 +30,7 @@ type Database struct { Sid *string `ovsdb:"sid"` } -func (a *Database) Table() string { +func (a *Database) GetTableName() string { return DatabaseTable } diff --git a/test/ovs/ovs_integration_test.go b/test/ovs/ovs_integration_test.go index a3621a3d..b74869ce 100644 --- a/test/ovs/ovs_integration_test.go +++ b/test/ovs/ovs_integration_test.go @@ -166,7 +166,7 @@ type bridgeType struct { DatapathID *string `ovsdb:"datapath_id"` } -func (b *bridgeType) Table() string { +func (b *bridgeType) GetTableName() string { return "Bridge" } @@ -192,7 +192,7 @@ type ovsType struct { SystemVersion *string `ovsdb:"system_version"` } -func (o *ovsType) Table() string { +func (o *ovsType) GetTableName() string { return "Open_vSwitch" } @@ -202,7 +202,7 @@ type ipfixType struct { Targets []string `ovsdb:"targets"` } -func (i *ipfixType) Table() string { +func (i *ipfixType) GetTableName() string { return "IPFIX" } @@ -212,7 +212,7 @@ type queueType struct { DSCP *int `ovsdb:"dscp"` } -func (q *queueType) Table() string { +func (q *queueType) GetTableName() string { return "Queue" } diff --git a/test/test_data.go b/test/test_data.go index 55a8b105..857d0d5e 100644 --- a/test/test_data.go +++ b/test/test_data.go @@ -144,7 +144,7 @@ type BridgeType struct { Status map[string]string `ovsdb:"status"` } -func (b *BridgeType) Table() string { +func (b *BridgeType) GetTableName() string { return "Bridge" } @@ -154,7 +154,7 @@ type OvsType struct { Bridges []string `ovsdb:"bridges"` } -func (o *OvsType) Table() string { +func (o *OvsType) GetTableName() string { return "Open_vSwitch" } @@ -166,7 +166,7 @@ type FlowSampleCollectorSetType struct { IPFIX *string // `ovsdb:"ipfix"` } -func (f *FlowSampleCollectorSetType) Table() string { +func (f *FlowSampleCollectorSetType) GetTableName() string { return "FlowSampleCollectorSet" }