forked from eBay/go-ovn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chassis_test.go
150 lines (136 loc) · 3.97 KB
/
chassis_test.go
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
/**
* Copyright (c) 2020 eBay Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package goovn
import (
"testing"
)
const (
CHASSIS_HOSTNAME = "fakehost"
CHASSIS_NAME = "fakechassis"
IP = "10.0.0.11"
CHASSIS2_HOSTNAME = "fakehost2"
CHASSIS2_NAME = "fakechassis2"
IP2 = "10.0.0.12"
)
// can be one or many encap_types similar to chassis-add of sbctl
var ENCAP_TYPES = []string{"stt", "geneve", "vxlan"}
func TestChassis(t *testing.T) {
ovndbapi := getOVNClient(DBSB)
t.Logf("Adding Chassis to OVN SB DB")
ocmd, err := ovndbapi.ChassisAdd(CHASSIS_NAME, CHASSIS_HOSTNAME, ENCAP_TYPES, IP, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Adding Chassis to OVN failed with err %v", err)
}
t.Logf("Adding Chassis to OVN Done")
t.Logf("Adding second Chassis to OVN SB DB")
ocmd, err = ovndbapi.ChassisAdd(CHASSIS2_NAME, CHASSIS2_HOSTNAME, ENCAP_TYPES, IP2, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Adding second Chassis to OVN failed with err %v", err)
}
t.Logf("Adding second Chassis to OVN Done")
t.Logf("Listing all the Chassis in OVN SB")
chassis, err := ovndbapi.ChassisList()
if err != nil {
t.Fatal(err)
}
if len(chassis) != 2 {
t.Fatalf("err listing chassis, total:%v", len(chassis))
}
t.Logf("Two Chassis found: %+v", chassis)
t.Logf("Gettting Chassis by hostname")
chassis, err = ovndbapi.ChassisGet(CHASSIS_HOSTNAME)
if err != nil {
t.Fatal(err)
}
if len(chassis) != 1 {
t.Fatalf("err getting chassis, total:%v", len(chassis))
}
chName := chassis[0].Name
t.Logf("Chassis found:%+v", chName)
t.Logf("Deleting Chassis:%v", chName)
ocmds := make([]*OvnCommand, 0, 2)
ocmd, err = ovndbapi.ChassisDel(chName)
if err != nil && err != ErrorNotFound {
t.Fatal(err)
}
ocmds = append(ocmds, ocmd)
ocmd, err = ovndbapi.ChassisDel(CHASSIS2_NAME)
if err != nil && err != ErrorNotFound {
t.Fatal(err)
}
ocmds = append(ocmds, ocmd)
err = ovndbapi.Execute(ocmds...)
if err != nil {
t.Fatalf("err executing commands %v: %v", ocmds, err)
}
// Verify deletion
chassis, err = ovndbapi.ChassisGet(CHASSIS_HOSTNAME)
if err != nil {
t.Fatal(err)
}
if len(chassis) != 0 {
t.Fatalf("error: Chassis deletion not done, total:%v", len(chassis))
}
t.Logf("Chassis %s deleted", chName)
t.Logf("Adding Chassis with empty hostname to OVN SB DB")
ocmd, err = ovndbapi.ChassisAdd(CHASSIS_NAME, "", ENCAP_TYPES, IP, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Adding Chassis with empty hostname failed with err %v", err)
}
t.Logf("Adding Chassis with empty hostname to OVN Done")
// verify addition
t.Logf("Gettting Chassis by name")
chassis, err = ovndbapi.ChassisGet(CHASSIS_NAME)
if err != nil {
t.Fatal(err)
}
if len(chassis) != 1 {
t.Fatalf("err getting chassis, total:%v", len(chassis))
}
chName = chassis[0].Name
t.Logf("Chassis found:%+v", chName)
// delete chassis
t.Logf("Deleting Chassis:%v", chName)
ocmd, err = ovndbapi.ChassisDel(chName)
if err != nil && err != ErrorNotFound {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("err executing command:%v", err)
}
//verify deletion
chassis, err = ovndbapi.ChassisGet(CHASSIS_NAME)
if err != nil {
t.Fatal(err)
}
if len(chassis) != 0 {
t.Fatalf("error: Chassis deletion not done, total:%v", len(chassis))
}
t.Logf("Chassis %s deleted", chName)
}