hs-test: simplify KinD deps installation 85/43085/3
authorAdrian Villin <[email protected]>
Thu, 5 Jun 2025 09:06:42 +0000 (11:06 +0200)
committerFlorin Coras <[email protected]>
Thu, 5 Jun 2025 23:27:51 +0000 (23:27 +0000)
Type: test

Change-Id: Icc4eb31fc04dbc2675c4e93b4e99290afb862f36
Signed-off-by: Adrian Villin <[email protected]>
extras/hs-test/Makefile
extras/hs-test/framework_test.go
extras/hs-test/hs_test.sh
extras/hs-test/infra/common/suite_common.go
extras/hs-test/infra/kind/suite_kind.go
extras/hs-test/kind_test.go
extras/hs-test/kubernetes/setupCluster.sh

index bc72171..24026fc 100644 (file)
@@ -172,11 +172,11 @@ test-perf: FORCE_BUILD=false
 test-perf: .deps.ok .build.ok
        @bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
                --test=$(TEST) --vppsrc=$(VPPSRC) --repeat=$(REPEAT) \
-               --skip=$(SKIP) --no_color=$(NO_COLOR) --perf=true; \
+               --skip=$(SKIP) --no_color=$(NO_COLOR) --perf=true --timeout=$(TIMEOUT); \
                ./script/compress.sh $$?
 
 .PHONY: setup-cluster
-setup-cluster:
+setup-cluster: .kind_deps.ok
        @bash ./kubernetes/setupCluster.sh
 
 .PHONY: build-go
@@ -204,9 +204,39 @@ build-debug: .deps.ok build-vpp-debug build-go
 .deps.ok:
        @$(MAKE) install-deps
 
+.kind_deps.ok:
+       @$(MAKE) install-kind-deps
+
+.PHONY: install-kind-deps
+install-kind-deps: .deps.ok
+       @go install sigs.k8s.io/[email protected]
+       -@if which kind > /dev/null 2>&1; then \
+        sudo ln -s $$(which kind) /usr/bin/kind; \
+       fi
+       @if ! command -v kubectl >/dev/null 2>&1; then \
+        echo "kubectl not found. Installing kubectl..."; \
+        sudo -E apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl gnupg; \
+        curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg; \
+        sudo -E chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg; \
+        echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list; \
+        sudo -E chmod 644 /etc/apt/sources.list.d/kubernetes.list; \
+        sudo apt-get update && sudo apt-get install -y kubectl; \
+    else \
+        echo "kubectl is already installed. Skipping installation."; \
+       fi
+       @touch .kind_deps.ok
+
 .PHONY: install-deps
 install-deps:
        @rm -f .deps.ok
+       @if [ -d "/usr/local/go" ]; then \
+        echo "Go is already installed. You may have to update it manually if version < 1.22"; \
+               go version; \
+    else \
+        echo "Installing Go 1.22"; \
+               wget https://go.dev/dl/go1.22.12.linux-amd64.tar.gz -O /tmp/go1.22.12.linux-amd64.tar.gz && sudo tar -C /usr/local -xzf /tmp/go1.22.12.linux-amd64.tar.gz; \
+               sudo ln -s /usr/local/go/bin/go /usr/bin/go ; \
+       fi
        @sudo -E apt-get update
        @sudo -E apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
                bridge-utils gpg
index f75f949..67aab3f 100644 (file)
@@ -28,7 +28,7 @@ var _ = ReportAfterSuite("VPP version under test", func(report Report) {
 func TestHst(t *testing.T) {
        // if we're debugging/running a coverage build and timeout isn't overridden,
        // set test timeout to 30 minutes. Also impacts AssertChannelClosed()
-       if (*IsVppDebug || *IsCoverage) && *Timeout == 5 {
+       if (*IsVppDebug || *IsCoverage || *PerfTesting) && *Timeout == 5 {
                TestTimeout = time.Minute * 30
                fmt.Printf("[Debugging or coverage build, TestTimeout is set to %s]\n", TestTimeout.String())
        } else {
index 37556fe..8be73a2 100644 (file)
@@ -114,6 +114,7 @@ case "${i}" in
         ;;
     --perf=*)
         perf="${i#*=}"
+        args="$args -perf"
         ;;
     --timeout=*)
         args="$args -timeout ${i#*=}"
index c15b016..97dd691 100644 (file)
@@ -23,6 +23,7 @@ var ParallelTotal = flag.Lookup("ginkgo.parallel.total")
 var IsVppDebug = flag.Bool("debug", false, "attach gdb to vpp")
 var DryRun = flag.Bool("dryrun", false, "set up containers but don't run tests")
 var Timeout = flag.Int("timeout", 5, "test timeout override (in minutes)")
+var PerfTesting = flag.Bool("perf", false, "perf test flag")
 var NumaAwareCpuAlloc bool
 var TestTimeout time.Duration
 var RunningInCi bool
@@ -175,8 +176,8 @@ func (s *HstCommon) AssertHttpBody(resp *http.Response, expectedBody string, msg
 // Coverage builds take longer to finish -> assert timeout is set to 'TestTimeout - 30 seconds' to let the test finish properly
 func (s *HstCommon) AssertChannelClosed(timeout time.Duration, channel chan error) {
        if *IsCoverage && timeout > time.Second*30 {
-               s.Log("Coverage build, assert timeout is set to %s", timeout.String())
                timeout = TestTimeout - time.Second*30
+               s.Log("Coverage build, assert timeout is set to %s", timeout.String())
        }
        EventuallyWithOffset(2, channel).WithTimeout(timeout).Should(BeClosed())
 }
index ffbd830..2095b7f 100644 (file)
@@ -1,8 +1,10 @@
 package hst_kind
 
 import (
+       "fmt"
        "os"
        "reflect"
+       "regexp"
        "runtime"
        "strings"
        "text/template"
@@ -78,10 +80,38 @@ func (s *KindSuite) TeardownTest() {
 }
 
 func (s *KindSuite) TeardownSuite() {
+       s.HstCommon.TeardownSuite()
        s.Log("   %s", s.Namespace)
        s.AssertNil(s.deleteNamespace(s.Namespace))
 }
 
+// Quick and dirty fix for now. Runs 'ldd /usr/lib/libvcl_ldpreload.so'
+// and searches for the first version string, then creates symlinks.
+func (s *KindSuite) FixVersionNumber(pods ...*Pod) {
+       regex := regexp.MustCompile(`lib.*\.so\.([0-9]+\.[0-9]+)`)
+       o, _ := s.Exec(s.Pods.ServerGeneric, []string{"/bin/bash", "-c",
+               "ldd /usr/lib/libvcl_ldpreload.so"})
+       match := regex.FindStringSubmatch(o)
+
+       if len(match) > 1 {
+               version := match[1]
+               s.Log("Found version: %s", version)
+               cmd := fmt.Sprintf("for file in /usr/lib/*.so; do\n"+
+                       "if [ -e \"$file\" ]; then\n"+
+                       "base=$(basename \"$file\")\n"+
+                       "newlink=\"/usr/lib/${base}.%s\"\n"+
+                       "ln -s \"$file\" \"$newlink\"\n"+
+                       "fi\n"+
+                       "done", version)
+               for _, pod := range pods {
+                       s.Exec(pod, []string{"/bin/bash", "-c", cmd})
+               }
+
+       } else {
+               s.Log("Couldn't find version.")
+       }
+}
+
 func (s *KindSuite) CreateConfigFromTemplate(targetConfigName string, templateName string, values any) {
        template := template.Must(template.ParseFiles(templateName))
 
@@ -101,8 +131,10 @@ func (s *KindSuite) CreateConfigFromTemplate(targetConfigName string, templateNa
 func (s *KindSuite) CreateNginxConfig() {
        values := struct {
                Workers uint8
+               Port    uint16
        }{
                Workers: 1,
+               Port:    8081,
        }
        s.CreateConfigFromTemplate(
                "/nginx.conf",
index b1e2d23..05841b6 100644 (file)
@@ -11,22 +11,13 @@ func init() {
        RegisterKindTests(KindIperfVclTest, NginxRpsTest)
 }
 
+const vcl string = "VCL_CONFIG=/vcl.conf"
+const ldp string = "LD_PRELOAD=/usr/lib/libvcl_ldpreload.so"
+
 func KindIperfVclTest(s *KindSuite) {
        s.DeployPod(s.Pods.ClientGeneric)
        s.DeployPod(s.Pods.ServerGeneric)
 
-       vclPath := "/vcl.conf"
-       ldpPath := "/usr/lib/libvcl_ldpreload.so"
-
-       // temporary workaround
-       symLink := "for file in /usr/lib/*.so; do\n" +
-               "if [ -e \"$file\" ]; then\n" +
-               "base=$(basename \"$file\")\n" +
-               "newlink=\"/usr/lib/${base}.25.06\"\n" +
-               "ln -s \"$file\" \"$newlink\"\n" +
-               "fi\n" +
-               "done"
-
        vclConf := "echo \"vcl {\n" +
                "rx-fifo-size 4000000\n" +
                "tx-fifo-size 4000000\n" +
@@ -35,19 +26,18 @@ func KindIperfVclTest(s *KindSuite) {
                "app-socket-api abstract:vpp/session\n" +
                "}\" > /vcl.conf"
 
-       s.Exec(s.Pods.ClientGeneric, []string{"/bin/bash", "-c", symLink})
-       s.Exec(s.Pods.ServerGeneric, []string{"/bin/bash", "-c", symLink})
-
        _, err := s.Exec(s.Pods.ClientGeneric, []string{"/bin/bash", "-c", vclConf})
        s.AssertNil(err)
        _, err = s.Exec(s.Pods.ServerGeneric, []string{"/bin/bash", "-c", vclConf})
        s.AssertNil(err)
 
-       _, err = s.Exec(s.Pods.ServerGeneric, []string{"/bin/bash", "-c",
-               "VCL_CONFIG=" + vclPath + " LD_PRELOAD=" + ldpPath + " iperf3 -s -D -4"})
-       s.AssertNil(err)
+       s.FixVersionNumber(s.Pods.ClientGeneric, s.Pods.ServerGeneric)
+
+       o, err := s.Exec(s.Pods.ServerGeneric, []string{"/bin/bash", "-c",
+               vcl + " " + ldp + " iperf3 -s -D -4"})
+       s.AssertNil(err, o)
        output, err := s.Exec(s.Pods.ClientGeneric, []string{"/bin/bash", "-c",
-               "VCL_CONFIG=" + vclPath + " LD_PRELOAD=" + ldpPath + " iperf3 -c " + s.Pods.ServerGeneric.IpAddress})
+               vcl + " " + ldp + " iperf3 -c " + s.Pods.ServerGeneric.IpAddress})
        s.Log(output)
        s.AssertNil(err)
 }
@@ -56,17 +46,6 @@ func NginxRpsTest(s *KindSuite) {
        s.DeployPod(s.Pods.Nginx)
        s.DeployPod(s.Pods.Ab)
        s.CreateNginxConfig()
-       vcl := "VCL_CONFIG=/vcl.conf"
-       ldp := "LD_PRELOAD=/usr/lib/libvcl_ldpreload.so"
-
-       // temporary workaround
-       symLink := "for file in /usr/lib/*.so; do\n" +
-               "if [ -e \"$file\" ]; then\n" +
-               "base=$(basename \"$file\")\n" +
-               "newlink=\"/usr/lib/${base}.25.06\"\n" +
-               "ln -s \"$file\" \"$newlink\"\n" +
-               "fi\n" +
-               "done"
 
        vclConf := "echo \"vcl {\n" +
                "heapsize 64M\n" +
@@ -79,10 +58,7 @@ func NginxRpsTest(s *KindSuite) {
                "app-socket-api abstract:vpp/session\n" +
                "}\" > /vcl.conf"
 
-       out, err := s.Exec(s.Pods.Nginx, []string{"/bin/bash", "-c", symLink})
-       s.AssertNil(err, out)
-
-       out, err = s.Exec(s.Pods.Nginx, []string{"/bin/bash", "-c", vclConf})
+       out, err := s.Exec(s.Pods.Nginx, []string{"/bin/bash", "-c", vclConf})
        s.AssertNil(err, out)
 
        go func() {
@@ -93,7 +69,7 @@ func NginxRpsTest(s *KindSuite) {
 
        // wait for nginx to start up
        time.Sleep(time.Second * 2)
-       out, err = s.Exec(s.Pods.Ab, []string{"ab", "-k", "-r", "-n", "1000000", "-c", "1000", "http://" + s.Pods.Nginx.IpAddress + ":80/64B.json"})
+       out, err = s.Exec(s.Pods.Ab, []string{"ab", "-k", "-r", "-n", "1000000", "-c", "1000", "http://" + s.Pods.Nginx.IpAddress + ":8081/64B.json"})
        s.Log(out)
        s.AssertNil(err)
 }
index 9cd92a1..4cbc991 100755 (executable)
@@ -1,18 +1,8 @@
 #!/usr/bin/env bash
 set -e
 
-if [ "$EUID" -eq 0 ]; then
-    echo "********"
-    echo "Do not run as root. Exiting."
-    echo "********"
-    exit 1
-fi
-
 echo "********"
 echo "Performance tests only work on Ubuntu 22.04 for now."
-echo "Do not run as root (untested) and make sure you have KinD and Kubectl installed!"
-echo "https://kind.sigs.k8s.io/"
-echo "https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management"
 echo "********"
 
 kind create cluster --config kubernetes/kind-config.yaml