Skip to content

Commit

Permalink
hs-test: containerize ab and wrk
Browse files Browse the repository at this point in the history
Type: test

Signed-off-by: Filip Tehlar <[email protected]>
Change-Id: I66af84257fa0692d9be3445d49b52fb7ca810d27
  • Loading branch information
ftehlar authored and florincoras committed Mar 29, 2023
1 parent 7c11156 commit b41b0af
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 32 deletions.
40 changes: 33 additions & 7 deletions extras/hs-test/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Volume struct {
type Container struct {
suite *HstSuite
isOptional bool
runDetached bool
name string
image string
extraRunningArgs string
Expand Down Expand Up @@ -65,6 +66,12 @@ func newContainer(yamlInput ContainerConfig) (*Container, error) {
container.isOptional = false
}

if runDetached, ok := yamlInput["run-detached"]; ok {
container.runDetached = runDetached.(bool)
} else {
container.runDetached = true
}

if _, ok := yamlInput["volumes"]; ok {
r := strings.NewReplacer("$HST_DIR", workDir)
for _, volu := range yamlInput["volumes"].([]interface{}) {
Expand Down Expand Up @@ -119,7 +126,7 @@ func (c *Container) getContainerWorkDir() (res string) {
}

func (c *Container) getContainerArguments() string {
args := "--cap-add=all --privileged --network host --rm"
args := "--ulimit nofile=90000:90000 --cap-add=all --privileged --network host --rm"
args += c.getVolumesAsCliOption()
args += c.getEnvVarsAsCliOption()
args += " --name " + c.name + " " + c.image
Expand All @@ -139,19 +146,38 @@ func (c *Container) start() error {
return exechelper.Run(cmd)
}

func (c *Container) run() error {
func (c *Container) prepareCommand() (string, error) {
if c.name == "" {
return fmt.Errorf("run container failed: name is blank")
return "", fmt.Errorf("run container failed: name is blank")
}

cmd := "docker run -d " + c.getContainerArguments()
cmd := "docker run "
if c.runDetached {
cmd += " -d"
}
cmd += " " + c.getContainerArguments()

c.suite.log(cmd)
err := exechelper.Run(cmd)
return cmd, nil
}

func (c *Container) combinedOutput() (string, error) {
cmd, err := c.prepareCommand()
if err != nil {
return fmt.Errorf("container run failed: %s", err)
return "", err
}

return nil
byteOutput, err := exechelper.CombinedOutput(cmd)
return string(byteOutput), err
}

func (c *Container) run() error {
cmd, err := c.prepareCommand()
if err != nil {
return err
}

return exechelper.Run(cmd)
}

func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) {
Expand Down
45 changes: 21 additions & 24 deletions extras/hs-test/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"os/exec"
)

func (s *NsSuite) TestHttpTps() {
Expand Down Expand Up @@ -60,39 +59,37 @@ func (s *NoTopoSuite) TestNginxAsServer() {
func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
nRequests := 1000000
nClients := 2000
var args []string
var exeName string

serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()

vpp := s.getContainerByName("vpp").vppInstance

nginxCont := s.getContainerByName("nginx")
s.assertNil(nginxCont.run())
vpp.waitForApp("nginx-", 5)

if ab_or_wrk == "ab" {
args = []string{"-n", fmt.Sprintf("%d", nRequests), "-c",
fmt.Sprintf("%d", nClients)}
abCont := s.getContainerByName("ab")
args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
if mode == "rps" {
args = append(args, "-k")
args += " -k"
} else if mode != "cps" {
return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
}
args = append(args, "http://"+serverAddress+":80/64B.json")
exeName = "ab"
args += " http://" + serverAddress + ":80/64B.json"
abCont.extraRunningArgs = args
o, err := abCont.combinedOutput()
s.log(o, err)
s.assertNil(err)
} else {
args = []string{"-c", fmt.Sprintf("%d", nClients), "-t", "2", "-d", "30",
"http://" + serverAddress + ":80/64B.json"}
exeName = "wrk"
wrkCont := s.getContainerByName("wrk")
args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
serverAddress)
wrkCont.extraRunningArgs = args
o, err := wrkCont.combinedOutput()
s.log(o)
s.assertNil(err)
}

vpp := s.getContainerByName("vpp").vppInstance

nginxCont := s.getContainerByName("nginx")
s.assertNil(nginxCont.run())
vpp.waitForApp("nginx-", 5)

cmd := exec.Command(exeName, args...)
s.log(cmd)
o, err := cmd.CombinedOutput()
s.log(string(o))
s.assertNil(err)
s.assertNotEmpty(o)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions extras/hs-test/resources/nginx/vcl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ vcl {
add-segment-size 4000000000
rx-fifo-size 4000000
tx-fifo-size 4000000
event-queue-size 100000

use-mq-eventfd
app-socket-api /tmp/nginx/var/run/app_ns_sockets/default
Expand Down
8 changes: 8 additions & 0 deletions extras/hs-test/topo-containers/single.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ containers:
is-default-work-dir: true
image: "hs-test/nginx-ldp"
is-optional: true
- name: "ab"
image: "jordi/ab"
is-optional: true
run-detached: false
- name: "wrk"
image: "skandyla/wrk"
is-optional: true
run-detached: false
2 changes: 1 addition & 1 deletion extras/hs-test/vppinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (vpp *VppInstance) createAfPacket(
if err := vpp.apiChannel.SendRequest(createReq).ReceiveReply(createReply); err != nil {
return 0, err
}
veth.index = createReply.SwIfIndex
veth.index = createReply.SwIfIndex

// Set to up
upReq := &interfaces.SwInterfaceSetFlags{
Expand Down

0 comments on commit b41b0af

Please sign in to comment.