hs-test: add nginx test
Type: test Signed-off-by: Filip Tehlar <ftehlar@cisco.com> Change-Id: Idd5352f254df0d1f36c1270e73440c9287247b81
This commit is contained in:
8
extras/hs-test/Dockerfile.nginx
Normal file
8
extras/hs-test/Dockerfile.nginx
Normal file
@ -0,0 +1,8 @@
|
||||
FROM nginx:1.22.1
|
||||
|
||||
COPY vpp-data/lib/* /usr/lib/
|
||||
COPY resources/nginx/vcl.conf /vcl.conf
|
||||
COPY resources/nginx/nginx.conf /nginx.conf
|
||||
COPY resources/nginx/start.sh /start.sh
|
||||
|
||||
ENTRYPOINT ["/start.sh"]
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/edwarnicke/govpp/binapi/interface_types"
|
||||
ip_types "github.com/edwarnicke/govpp/binapi/ip_types"
|
||||
"github.com/edwarnicke/govpp/binapi/session"
|
||||
"github.com/edwarnicke/govpp/binapi/tapv2"
|
||||
"github.com/edwarnicke/govpp/binapi/vlib"
|
||||
"github.com/edwarnicke/vpphelper"
|
||||
)
|
||||
@ -347,3 +348,62 @@ func (a *Actions) ConfigureHttpTps(args []string) *ActionResult {
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Actions) ConfigureTap(args []string) *ActionResult {
|
||||
var startup Stanza
|
||||
startup.
|
||||
NewStanza("session").
|
||||
Append("enable").
|
||||
Append("use-app-socket-api").Close()
|
||||
|
||||
ctx, cancel := newVppContext()
|
||||
defer cancel()
|
||||
con, vppErrCh := vpphelper.StartAndDialContext(ctx,
|
||||
vpphelper.WithRootDir(workDir),
|
||||
vpphelper.WithVppConfig(configTemplate+startup.ToString()))
|
||||
exitOnErrCh(ctx, cancel, vppErrCh)
|
||||
ifaceClient := interfaces.NewServiceClient(con)
|
||||
|
||||
pref, err := ip_types.ParseIP4Prefix("10.10.10.2/24")
|
||||
if err != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("failed to parse ip4 address"))
|
||||
}
|
||||
createTapReply, err := tapv2.NewServiceClient(con).TapCreateV2(ctx, &tapv2.TapCreateV2{
|
||||
HostIfNameSet: true,
|
||||
HostIfName: "tap0",
|
||||
HostIP4PrefixSet: true,
|
||||
HostIP4Prefix: ip_types.IP4AddressWithPrefix(pref),
|
||||
})
|
||||
if err != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("failed to configure tap"))
|
||||
}
|
||||
ipPrefix, err := ip_types.ParseAddressWithPrefix("10.10.10.1/24")
|
||||
if err != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("parsing ip address failed"))
|
||||
}
|
||||
ipAddress := &interfaces.SwInterfaceAddDelAddress{
|
||||
IsAdd: true,
|
||||
SwIfIndex: createTapReply.SwIfIndex,
|
||||
Prefix: ipPrefix,
|
||||
}
|
||||
_, errx := ifaceClient.SwInterfaceAddDelAddress(ctx, ipAddress)
|
||||
if errx != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("configuring ip address failed"))
|
||||
}
|
||||
_, err = ifaceClient.SwInterfaceSetFlags(ctx, &interfaces.SwInterfaceSetFlags{
|
||||
SwIfIndex: createTapReply.SwIfIndex,
|
||||
Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
|
||||
})
|
||||
if err != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("failed to set interface state"))
|
||||
}
|
||||
_, err = session.NewServiceClient(con).SessionEnableDisable(ctx, &session.SessionEnableDisable{
|
||||
IsEnable: true,
|
||||
})
|
||||
if err != nil {
|
||||
return NewActionResult(err, ActionResultWithDesc("configuration failed"))
|
||||
}
|
||||
writeSyncFile(OkResult())
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
}
|
||||
|
@ -178,3 +178,8 @@ func TestVeths(t *testing.T) {
|
||||
var m VethsSuite
|
||||
suite.Run(t, &m)
|
||||
}
|
||||
|
||||
func TestNoTopo(t *testing.T) {
|
||||
var m NoTopoSuite
|
||||
suite.Run(t, &m)
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *NsSuite) TestHttpTps() {
|
||||
finished := make(chan error, 1)
|
||||
server_ip := "10.0.0.2"
|
||||
@ -13,7 +18,7 @@ func (s *NsSuite) TestHttpTps() {
|
||||
_, err := container.execAction("ConfigureHttpTps")
|
||||
s.assertNil(err)
|
||||
|
||||
go startWget(finished, server_ip, port, "client")
|
||||
go startWget(finished, server_ip, port, "test_file_10M", "client")
|
||||
// wait for client
|
||||
err = <-finished
|
||||
s.assertNil(err)
|
||||
@ -41,3 +46,21 @@ func (s *VethsSuite) TestHttpCli() {
|
||||
|
||||
s.assertContains(o, "<html>", "<html> not found in the result!")
|
||||
}
|
||||
|
||||
func (s *NoTopoSuite) TestNginx() {
|
||||
query := "return_ok"
|
||||
finished := make(chan error, 1)
|
||||
vppCont := s.getContainerByName("vpp")
|
||||
vppInst := NewVppInstance(vppCont)
|
||||
vppInst.actionFuncName = "ConfigureTap"
|
||||
s.assertNil(vppInst.start(), "failed to start vpp")
|
||||
|
||||
nginxCont := s.getContainerByName("nginx")
|
||||
s.assertNil(nginxCont.run())
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
defer func() { os.Remove(query) }()
|
||||
go startWget(finished, "10.10.10.1", "80", query, "")
|
||||
s.assertNil(<-finished)
|
||||
}
|
||||
|
26
extras/hs-test/resources/nginx/nginx.conf
Normal file
26
extras/hs-test/resources/nginx/nginx.conf
Normal file
@ -0,0 +1,26 @@
|
||||
master_process on;
|
||||
worker_rlimit_nofile 10240;
|
||||
worker_processes 2;
|
||||
daemon off;
|
||||
|
||||
events {
|
||||
use epoll;
|
||||
worker_connections 10240;
|
||||
accept_mutex off;
|
||||
multi_accept off;
|
||||
}
|
||||
|
||||
http {
|
||||
keepalive_timeout 300s;
|
||||
keepalive_requests 1000000;
|
||||
sendfile on;
|
||||
server {
|
||||
listen 80;
|
||||
root /usr/share/nginx;
|
||||
index index.html index.htm;
|
||||
location /return_ok
|
||||
{
|
||||
return 200 '';
|
||||
}
|
||||
}
|
||||
}
|
6
extras/hs-test/resources/nginx/start.sh
Executable file
6
extras/hs-test/resources/nginx/start.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
LDP_PATH=/usr/lib/libvcl_ldpreload.so
|
||||
VCL_CFG=/vcl.conf
|
||||
LD_PRELOAD=$LDP_PATH VCL_CONFIG=$VCL_CFG nginx -c /nginx.conf
|
||||
tail -f /dev/null
|
10
extras/hs-test/resources/nginx/vcl.conf
Normal file
10
extras/hs-test/resources/nginx/vcl.conf
Normal file
@ -0,0 +1,10 @@
|
||||
vcl {
|
||||
heapsize 64M
|
||||
segment-size 4000000000
|
||||
add-segment-size 4000000000
|
||||
rx-fifo-size 4000000
|
||||
tx-fifo-size 4000000
|
||||
|
||||
use-mq-eventfd
|
||||
app-socket-api /tmp/nginx/var/run/app_ns_sockets/default
|
||||
}
|
@ -11,3 +11,4 @@ cp ${VPP_WS}/build-root/build-vpp_debug-native/vpp/bin/* ${bin}
|
||||
cp -r ${VPP_WS}/build-root/build-vpp_debug-native/vpp/lib/x86_64-linux-gnu/* ${lib}
|
||||
|
||||
docker build -t hs-test/vpp -f Dockerfile.vpp .
|
||||
docker build -t hs-test/nginx-ldp -f Dockerfile.nginx .
|
||||
|
10
extras/hs-test/suite_no_topo_test.go
Normal file
10
extras/hs-test/suite_no_topo_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
type NoTopoSuite struct {
|
||||
HstSuite
|
||||
}
|
||||
|
||||
func (s *NoTopoSuite) SetupSuite() {
|
||||
s.teardownSuite = func() {}
|
||||
s.loadContainerTopology("single")
|
||||
}
|
17
extras/hs-test/topo-containers/single.yaml
Normal file
17
extras/hs-test/topo-containers/single.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
volumes:
|
||||
- shared-vol
|
||||
|
||||
containers:
|
||||
- name: "vpp"
|
||||
volumes:
|
||||
- host-dir: "shared-vol"
|
||||
container-dir: "/tmp/vpp"
|
||||
is-default-work-dir: true
|
||||
- name: "nginx"
|
||||
volumes:
|
||||
- host-dir: "shared-vol"
|
||||
container-dir: "/tmp/nginx"
|
||||
is-default-work-dir: true
|
||||
image: "hs-test/nginx-ldp"
|
||||
is-optional: true
|
@ -176,17 +176,16 @@ func startHttpServer(running chan struct{}, done chan struct{}, addressPort, net
|
||||
cmd.Process.Kill()
|
||||
}
|
||||
|
||||
func startWget(finished chan error, server_ip, port string, netNs string) {
|
||||
fname := "test_file_10M"
|
||||
func startWget(finished chan error, server_ip, port, query, netNs string) {
|
||||
defer func() {
|
||||
finished <- errors.New("wget error")
|
||||
}()
|
||||
|
||||
cmd := NewCommand([]string{"wget", "--tries=5", "-q", "-O", "/dev/null", server_ip + ":" + port + "/" + fname},
|
||||
cmd := NewCommand([]string{"wget", "--tries=5", "-q", "-O", "/dev/null", server_ip + ":" + port + "/" + query},
|
||||
netNs)
|
||||
o, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
finished <- errors.New(fmt.Sprintf("wget error: '%s'.\n%s", err, o))
|
||||
finished <- fmt.Errorf("wget error: '%v\n\n%s'", err, o)
|
||||
return
|
||||
}
|
||||
finished <- nil
|
||||
|
Reference in New Issue
Block a user