hs-test: log external apps

Type: test

Change-Id: Id2b0d408bd46f20b81422506f9db4eb655feddac
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
This commit is contained in:
Filip Tehlar
2023-09-02 08:54:21 +02:00
committed by Florin Coras
parent a6b1a7d809
commit 4b3598e39a
7 changed files with 97 additions and 94 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
@ -313,3 +315,81 @@ func (s *HstSuite) getTestId() string {
return s.testIds[testName]
}
func (s *HstSuite) startServerApp(running chan error, done chan struct{}, env []string) {
cmd := exec.Command("iperf3", "-4", "-s")
if env != nil {
cmd.Env = env
}
s.log(cmd)
err := cmd.Start()
if err != nil {
msg := fmt.Errorf("failed to start iperf server: %v", err)
running <- msg
return
}
running <- nil
<-done
cmd.Process.Kill()
}
func (s *HstSuite) startClientApp(ipAddress string, env []string, clnCh chan error, clnRes chan string) {
defer func() {
clnCh <- nil
}()
nTries := 0
for {
cmd := exec.Command("iperf3", "-c", ipAddress, "-u", "-l", "1460", "-b", "10g")
if env != nil {
cmd.Env = env
}
s.log(cmd)
o, err := cmd.CombinedOutput()
if err != nil {
if nTries > 5 {
clnCh <- fmt.Errorf("failed to start client app '%s'.\n%s", err, o)
return
}
time.Sleep(1 * time.Second)
nTries++
continue
} else {
clnRes <- fmt.Sprintf("Client output: %s", o)
}
break
}
}
func (s *HstSuite) startHttpServer(running chan struct{}, done chan struct{}, addressPort, netNs string) {
cmd := newCommand([]string{"./http_server", addressPort}, netNs)
err := cmd.Start()
s.log(cmd)
if err != nil {
fmt.Println("Failed to start http server")
return
}
running <- struct{}{}
<-done
cmd.Process.Kill()
}
func (s *HstSuite) startWget(finished chan error, server_ip, port, query, netNs string) {
defer func() {
finished <- errors.New("wget error")
}()
cmd := newCommand([]string{"wget", "--timeout=10", "--no-proxy", "--tries=5", "-O", "/dev/null", server_ip + ":" + port + "/" + query},
netNs)
s.log(cmd)
o, err := cmd.CombinedOutput()
if err != nil {
finished <- fmt.Errorf("wget error: '%v\n\n%s'", err, o)
return
} else if !strings.Contains(string(o), "200 OK") {
finished <- fmt.Errorf("wget error: response not 200 OK")
return
}
finished <- nil
}

View File

@ -17,7 +17,7 @@ func (s *NsSuite) TestHttpTps() {
// configure vpp in the container
container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
go startWget(finished, client_ip, port, "test_file_10M", "client")
go s.startWget(finished, client_ip, port, "test_file_10M", "client")
// wait for client
err := <-finished
s.assertNil(err)
@ -73,7 +73,7 @@ func (s *NoTopoSuite) TestNginxAsServer() {
serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
defer func() { os.Remove(query) }()
go startWget(finished, serverAddress, "80", query, "")
go s.startWget(finished, serverAddress, "80", query, "")
s.assertNil(<-finished)
}

View File

@ -54,7 +54,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
s.log("attaching server to vpp")
srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+serverVclFileName)
go startServerApp(srvCh, stopServerCh, srvEnv)
go s.startServerApp(srvCh, stopServerCh, srvEnv)
err = <-srvCh
s.assertNil(err)
@ -63,7 +63,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
var clnRes = make(chan string, 1)
clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clientVclFileName)
serverVethAddress := s.netInterfaces[serverInterfaceName].ip4AddressString()
go startClientApp(serverVethAddress, clnEnv, clnCh, clnRes)
go s.startClientApp(serverVethAddress, clnEnv, clnCh, clnRes)
s.log(<-clnRes)
// wait for client's result

View File

@ -9,13 +9,13 @@ func (s *TapSuite) TestLinuxIperf() {
stopServerCh <- struct{}{}
}()
go startServerApp(srvCh, stopServerCh, nil)
go s.startServerApp(srvCh, stopServerCh, nil)
err := <-srvCh
s.assertNil(err)
s.log("server running")
ipAddress := s.netInterfaces[tapInterfaceName].ip4AddressString()
go startClientApp(ipAddress, nil, clnCh, clnRes)
go s.startClientApp(ipAddress, nil, clnCh, clnRes)
s.log("client running")
s.log(<-clnRes)
err = <-clnCh

View File

@ -20,7 +20,7 @@ func testProxyHttpTcp(s *NsSuite) error {
s.log("test file created...")
go startHttpServer(serverRunning, stopServer, ":666", "server")
go s.startHttpServer(serverRunning, stopServer, ":666", "server")
// TODO better error handling and recovery
<-serverRunning

View File

@ -1,25 +1,12 @@
package main
import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"
)
const vclTemplate = `vcl {
app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s
app-scope-global
app-scope-local
namespace-id %[2]s
namespace-secret %[2]s
use-mq-eventfd
}
`
const networkTopologyDir string = "topo-network/"
const containerTopologyDir string = "topo-containers/"
@ -42,50 +29,6 @@ type JsonResult struct {
StdOutput string
}
func startServerApp(running chan error, done chan struct{}, env []string) {
cmd := exec.Command("iperf3", "-4", "-s")
if env != nil {
cmd.Env = env
}
err := cmd.Start()
if err != nil {
msg := fmt.Errorf("failed to start iperf server: %v", err)
running <- msg
return
}
running <- nil
<-done
cmd.Process.Kill()
}
func startClientApp(ipAddress string, env []string, clnCh chan error, clnRes chan string) {
defer func() {
clnCh <- nil
}()
nTries := 0
for {
cmd := exec.Command("iperf3", "-c", ipAddress, "-u", "-l", "1460", "-b", "10g")
if env != nil {
cmd.Env = env
}
o, err := cmd.CombinedOutput()
if err != nil {
if nTries > 5 {
clnCh <- fmt.Errorf("failed to start client app '%s'.\n%s", err, o)
return
}
time.Sleep(1 * time.Second)
nTries++
continue
} else {
clnRes <- fmt.Sprintf("Client output: %s", o)
}
break
}
}
func assertFileSize(f1, f2 string) error {
fi1, err := os.Stat(f1)
if err != nil {
@ -103,36 +46,6 @@ func assertFileSize(f1, f2 string) error {
return nil
}
func startHttpServer(running chan struct{}, done chan struct{}, addressPort, netNs string) {
cmd := newCommand([]string{"./http_server", addressPort}, netNs)
err := cmd.Start()
if err != nil {
fmt.Println("Failed to start http server")
return
}
running <- struct{}{}
<-done
cmd.Process.Kill()
}
func startWget(finished chan error, server_ip, port, query, netNs string) {
defer func() {
finished <- errors.New("wget error")
}()
cmd := newCommand([]string{"wget", "--timeout=10", "--no-proxy", "--tries=5", "-O", "/dev/null", server_ip + ":" + port + "/" + query},
netNs)
o, err := cmd.CombinedOutput()
if err != nil {
finished <- fmt.Errorf("wget error: '%v\n\n%s'", err, o)
return
} else if !strings.Contains(string(o), "200 OK") {
finished <- fmt.Errorf("wget error: response not 200 OK")
return
}
finished <- nil
}
func (c *Stanza) newStanza(name string) *Stanza {
c.append("\n" + name + " {")
c.pad += 2

View File

@ -5,6 +5,16 @@ import (
"time"
)
const vclTemplate = `vcl {
app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s
app-scope-global
app-scope-local
namespace-id %[2]s
namespace-secret %[2]s
use-mq-eventfd
}
`
func (s *VethsSuite) testVclEcho(proto string) {
port := "12345"
srvVppCont := s.getContainerByName("server-vpp")