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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
// Suite for VPP proxy testing
//
// The topology consists of 3 containers: curl (client), VPP (proxy), nginx (target HTTP server).
// VPP has 2 tap interfaces configured, one for client network and second for server/target network.
package hst
import (
"fmt"
"reflect"
"runtime"
"strings"
. "github.com/onsi/ginkgo/v2"
)
// These correspond to names used in yaml config
const (
VppProxyContainerName = "vpp-proxy"
ClientTapInterfaceName = "hstcln"
ServerTapInterfaceName = "hstsrv"
CurlContainerTestFile = "/tmp/testFile"
)
type VppProxySuite struct {
HstSuite
nginxPort uint16
maxTimeout int
}
var vppProxyTests = map[string][]func(s *VppProxySuite){}
var vppProxySoloTests = map[string][]func(s *VppProxySuite){}
func RegisterVppProxyTests(tests ...func(s *VppProxySuite)) {
vppProxyTests[getTestFilename()] = tests
}
func RegisterVppProxySoloTests(tests ...func(s *VppProxySuite)) {
vppProxySoloTests[getTestFilename()] = tests
}
func (s *VppProxySuite) SetupSuite() {
s.HstSuite.SetupSuite()
s.LoadNetworkTopology("2taps")
s.LoadContainerTopology("vppProxy")
if *IsVppDebug {
s.maxTimeout = 600
} else {
s.maxTimeout = 60
}
}
func (s *VppProxySuite) SetupTest() {
s.HstSuite.SetupTest()
// VPP HTTP connect-proxy
vppContainer := s.GetContainerByName(VppProxyContainerName)
vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus)
s.AssertNotNil(vpp, fmt.Sprint(err))
clientInterface := s.GetInterfaceByName(ClientTapInterfaceName)
serverInterface := s.GetInterfaceByName(ServerTapInterfaceName)
// nginx HTTP server
nginxContainer := s.GetTransientContainerByName(NginxServerContainerName)
s.AssertNil(nginxContainer.Create())
s.nginxPort = 80
nginxSettings := struct {
LogPrefix string
Address string
Port uint16
Timeout int
}{
LogPrefix: nginxContainer.Name,
Address: serverInterface.Ip4AddressString(),
Port: s.nginxPort,
Timeout: s.maxTimeout,
}
nginxContainer.CreateConfigFromTemplate(
"/nginx.conf",
"./resources/nginx/nginx_server.conf",
nginxSettings,
)
s.AssertNil(nginxContainer.Start())
s.AssertNil(vpp.Start())
s.AssertNil(vpp.createTap(clientInterface, 1))
s.AssertNil(vpp.createTap(serverInterface, 2))
if *DryRun {
s.LogStartedContainers()
s.Skip("Dry run mode = true")
}
}
func (s *VppProxySuite) TearDownTest() {
vpp := s.GetContainerByName(VppProxyContainerName).VppInstance
if CurrentSpecReport().Failed() {
s.Log(vpp.Vppctl("show session verbose 2"))
s.Log(vpp.Vppctl("show error"))
s.CollectNginxLogs(NginxServerContainerName)
}
s.HstSuite.TearDownTest()
}
func (s *VppProxySuite) NginxPort() uint16 {
return s.nginxPort
}
func (s *VppProxySuite) NginxAddr() string {
return s.GetInterfaceByName(ServerTapInterfaceName).Ip4AddressString()
}
func (s *VppProxySuite) VppProxyAddr() string {
return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString()
}
func (s *VppProxySuite) CurlRequest(targetUri string) (string, string) {
args := fmt.Sprintf("--insecure --noproxy '*' %s", targetUri)
body, log := s.RunCurlContainer(args)
return body, log
}
func (s *VppProxySuite) CurlRequestViaTunnel(targetUri string, proxyUri string) (string, string) {
args := fmt.Sprintf("--max-time %d --insecure -p -x %s %s", s.maxTimeout, proxyUri, targetUri)
body, log := s.RunCurlContainer(args)
return body, log
}
func (s *VppProxySuite) CurlDownloadResource(uri string) {
args := fmt.Sprintf("-w @/tmp/write_out_download --max-time %d --insecure --noproxy '*' --remote-name --output-dir /tmp %s", s.maxTimeout, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "GET response code: 200")
s.AssertNotContains(log, "bytes remaining to read")
s.AssertNotContains(log, "Operation timed out")
}
func (s *VppProxySuite) CurlUploadResource(uri, file string) {
args := fmt.Sprintf("-w @/tmp/write_out_upload --max-time %d --insecure --noproxy '*' -T %s %s", s.maxTimeout, file, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "PUT response code: 201")
s.AssertNotContains(log, "Operation timed out")
}
func (s *VppProxySuite) CurlDownloadResourceViaTunnel(uri string, proxyUri string) {
args := fmt.Sprintf("-w @/tmp/write_out_download_connect --max-time %d --insecure -p -x %s --remote-name --output-dir /tmp %s", s.maxTimeout, proxyUri, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "CONNECT response code: 200")
s.AssertContains(writeOut, "GET response code: 200")
s.AssertNotContains(log, "bytes remaining to read")
s.AssertNotContains(log, "Operation timed out")
}
func (s *VppProxySuite) CurlUploadResourceViaTunnel(uri, proxyUri, file string) {
args := fmt.Sprintf("-w @/tmp/write_out_upload_connect --max-time %d --insecure -p -x %s -T %s %s", s.maxTimeout, proxyUri, file, uri)
writeOut, log := s.RunCurlContainer(args)
s.AssertContains(writeOut, "CONNECT response code: 200")
s.AssertContains(writeOut, "PUT response code: 201")
s.AssertNotContains(log, "Operation timed out")
}
var _ = Describe("VppProxySuite", Ordered, ContinueOnFailure, func() {
var s VppProxySuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
for filename, tests := range vppProxyTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(TestTimeout))
}
}
})
var _ = Describe("VppProxySuiteSolo", Ordered, ContinueOnFailure, func() {
var s VppProxySuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
for filename, tests := range vppProxySoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(TestTimeout))
}
}
})
|