1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
package client
import (
"encoding/json"
"testing"
"github.com/ovn-org/libovsdb/cache"
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
)
var apiTestSchema = []byte(`{
"name": "OVN_Northbound",
"version": "5.31.0",
"cksum": "2352750632 28701",
"tables": {
"Logical_Switch": {
"columns": {
"name": {"type": "string"},
"ports": {"type": {"key": {"type": "uuid",
"refTable": "Logical_Switch_Port",
"refType": "strong"},
"min": 0,
"max": "unlimited"}},
"acls": {"type": {"key": {"type": "uuid",
"refTable": "ACL",
"refType": "strong"},
"min": 0,
"max": "unlimited"}},
"qos_rules": {"type": {"key": {"type": "uuid",
"refTable": "QoS",
"refType": "strong"},
"min": 0,
"max": "unlimited"}},
"load_balancer": {"type": {"key": {"type": "uuid",
"refTable": "Load_Balancer",
"refType": "weak"},
"min": 0,
"max": "unlimited"}},
"dns_records": {"type": {"key": {"type": "uuid",
"refTable": "DNS",
"refType": "weak"},
"min": 0,
"max": "unlimited"}},
"other_config": {
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}},
"external_ids": {
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}},
"forwarding_groups": {
"type": {"key": {"type": "uuid",
"refTable": "Forwarding_Group",
"refType": "strong"},
"min": 0, "max": "unlimited"}}},
"isRoot": true},
"Logical_Switch_Port": {
"columns": {
"name": {"type": "string"},
"type": {"type": "string"},
"options": {
"type": {"key": "string",
"value": "string",
"min": 0,
"max": "unlimited"}},
"parent_name": {"type": {"key": "string", "min": 0, "max": 1}},
"tag_request": {
"type": {"key": {"type": "integer",
"minInteger": 0,
"maxInteger": 4095},
"min": 0, "max": 1}},
"tag": {
"type": {"key": {"type": "integer",
"minInteger": 1,
"maxInteger": 4095},
"min": 0, "max": 1}},
"addresses": {"type": {"key": "string",
"min": 0,
"max": "unlimited"}},
"dynamic_addresses": {"type": {"key": "string",
"min": 0,
"max": 1}},
"port_security": {"type": {"key": "string",
"min": 0,
"max": "unlimited"}},
"up": {"type": {"key": "boolean", "min": 0, "max": 1}},
"enabled": {"type": {"key": "boolean", "min": 0, "max": 1}},
"dhcpv4_options": {"type": {"key": {"type": "uuid",
"refTable": "DHCP_Options",
"refType": "weak"},
"min": 0,
"max": 1}},
"dhcpv6_options": {"type": {"key": {"type": "uuid",
"refTable": "DHCP_Options",
"refType": "weak"},
"min": 0,
"max": 1}},
"ha_chassis_group": {
"type": {"key": {"type": "uuid",
"refTable": "HA_Chassis_Group",
"refType": "strong"},
"min": 0,
"max": 1}},
"external_ids": {
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}}},
"indexes": [["name"]],
"isRoot": false}
}
}`)
type testLogicalSwitch struct {
UUID string `ovsdb:"_uuid"`
Ports []string `ovsdb:"ports"`
ExternalIds map[string]string `ovsdb:"external_ids"`
Name string `ovsdb:"name"`
QosRules []string `ovsdb:"qos_rules"`
LoadBalancer []string `ovsdb:"load_balancer"`
DNSRecords []string `ovsdb:"dns_records"`
OtherConfig map[string]string `ovsdb:"other_config"`
ForwardingGroups []string `ovsdb:"forwarding_groups"`
Acls []string `ovsdb:"acls"`
}
// Table returns the table name. It's part of the Model interface
func (*testLogicalSwitch) Table() string {
return "Logical_Switch"
}
//LogicalSwitchPort struct defines an object in Logical_Switch_Port table
type testLogicalSwitchPort struct {
UUID string `ovsdb:"_uuid"`
Up *bool `ovsdb:"up"`
Dhcpv4Options *string `ovsdb:"dhcpv4_options"`
Name string `ovsdb:"name"`
DynamicAddresses *string `ovsdb:"dynamic_addresses"`
HaChassisGroup *string `ovsdb:"ha_chassis_group"`
Options map[string]string `ovsdb:"options"`
Enabled *bool `ovsdb:"enabled"`
Addresses []string `ovsdb:"addresses"`
Dhcpv6Options *string `ovsdb:"dhcpv6_options"`
TagRequest *int `ovsdb:"tag_request"`
Tag *int `ovsdb:"tag"`
PortSecurity []string `ovsdb:"port_security"`
ExternalIds map[string]string `ovsdb:"external_ids"`
Type string `ovsdb:"type"`
ParentName *string `ovsdb:"parent_name"`
}
// Table returns the table name. It's part of the Model interface
func (*testLogicalSwitchPort) Table() string {
return "Logical_Switch_Port"
}
func apiTestCache(t testing.TB, data map[string]map[string]model.Model) *cache.TableCache {
var schema ovsdb.DatabaseSchema
err := json.Unmarshal(apiTestSchema, &schema)
assert.Nil(t, err)
db, err := model.NewClientDBModel("OVN_Northbound", map[string]model.Model{"Logical_Switch": &testLogicalSwitch{}, "Logical_Switch_Port": &testLogicalSwitchPort{}})
assert.Nil(t, err)
dbModel, errs := model.NewDatabaseModel(schema, db)
assert.Empty(t, errs)
cache, err := cache.NewTableCache(dbModel, data, nil)
assert.Nil(t, err)
return cache
}
|