-
Notifications
You must be signed in to change notification settings - Fork 61
/
load_balancer_test.go
99 lines (90 loc) · 2.48 KB
/
load_balancer_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
/**
* Copyright (c) 2017 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 LB1 = "lb1"
func TestLoadBalancer(t *testing.T) {
ovndbapi := getOVNClient(DBNB)
t.Logf("Adding LB to OVN")
ocmd, err := ovndbapi.LBAdd(LB1, "192.168.0.19:80", "tcp", []string{"10.0.0.11:80", "10.0.0.12:80"})
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Adding LB OVN failed with err %v", err)
}
t.Logf("Adding LB to OVN Done")
t.Logf("Updating LB to OVN")
ocmd, err = ovndbapi.LBUpdate(LB1, "192.168.0.10:80", "tcp", []string{"10.10.10.127:8080", "10.10.10.120:8080"})
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Updating LB OVN failed with err %v", err)
}
t.Logf("Updating LB to OVN done")
ocmd, err = ovndbapi.LBSetSelectionFields(LB1, "ip_src")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("Setting LB OVN selection fields failed with err %v", err)
}
t.Logf("Setting LB selection_fields to OVN done")
t.Logf("Gettting LB by name")
lb, err := ovndbapi.LBGet(LB1)
if err != nil {
t.Fatal(err)
}
if len(lb) != 1 {
t.Fatalf("err getting lbs, total:%v", len(lb))
}
// Tessting LBlist()
lbList, err := ovndbapi.LBList()
if err != nil {
t.Fatal(err)
}
if len(lbList) != 1 {
t.Fatalf("err getting lbList, total: %v", len(lbList))
}
if lb[0].SelectionFields != "ip_src" {
t.Fatalf("err setting lbs selection fields, expected: ip_src received:%v", lb[0].SelectionFields)
}
t.Logf("Lb found:%+v", lb[0])
t.Logf("Deleting LB")
ocmd, err = ovndbapi.LBDel(LB1)
if err != nil && err != ErrorNotFound {
t.Fatal(err)
}
err = ovndbapi.Execute(ocmd)
if err != nil {
t.Fatalf("err executing command:%v", err)
}
// Verify deletion
lb, err = ovndbapi.LBGet(LB1)
if err != nil {
t.Fatal(err)
}
if len(lb) != 0 {
t.Fatalf("error: lb deletion not done, total:%v", len(lb))
}
t.Logf("LB deletion done")
}