From 964a484b2fd51ec31d3ad592bd9bc9f83e451999 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Tue, 2 Jul 2019 23:50:30 -0400 Subject: [PATCH] GetLbAlgorithm helper func for e2e --- test/e2e/framework/exec.go | 25 +++++++++++++++++++++++++ test/e2e/loadbalance/configmap.go | 17 ++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/test/e2e/framework/exec.go b/test/e2e/framework/exec.go index cf6b55cbdb..6027c24203 100644 --- a/test/e2e/framework/exec.go +++ b/test/e2e/framework/exec.go @@ -18,6 +18,7 @@ package framework import ( "bytes" + "encoding/json" "fmt" "io" "os/exec" @@ -28,6 +29,30 @@ import ( corev1 "k8s.io/api/core/v1" ) +// GetLbAlgorithm returns algorithm identifier for the given backend +func (f *Framework) GetLbAlgorithm(serviceName string, servicePort int) (string, error) { + backendName := fmt.Sprintf("%s-%s-%v", f.Namespace, serviceName, servicePort) + cmd := fmt.Sprintf("/dbg backends get %s", backendName) + + output, err := f.ExecIngressPod(cmd) + if err != nil { + return "", err + } + + var backend map[string]interface{} + err = json.Unmarshal([]byte(output), &backend) + if err != nil { + return "", err + } + + algorithm, ok := backend["load-balance"].(string) + if !ok { + return "", fmt.Errorf("error while accessing load-balance field of backend") + } + + return algorithm, nil +} + // ExecIngressPod executes a command inside the first container in ingress controller running pod func (f *Framework) ExecIngressPod(command string) (string, error) { pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet) diff --git a/test/e2e/loadbalance/configmap.go b/test/e2e/loadbalance/configmap.go index abd4c500a3..fbc8c0c7c7 100644 --- a/test/e2e/loadbalance/configmap.go +++ b/test/e2e/loadbalance/configmap.go @@ -17,7 +17,6 @@ limitations under the License. package loadbalance import ( - "encoding/json" "strings" "time" @@ -53,20 +52,8 @@ var _ = framework.IngressNginxDescribe("Load Balance - Configmap value", func() }) time.Sleep(waitForLuaSync) - getCmd := "/dbg backends all" - output, err := f.ExecIngressPod(getCmd) + algorithm, err := f.GetLbAlgorithm("http-svc", 80) Expect(err).Should(BeNil()) - - var backends []map[string]interface{} - unmarshalErr := json.Unmarshal([]byte(output), &backends) - Expect(unmarshalErr).Should(BeNil()) - - for _, backend := range backends { - if backend["name"].(string) != "upstream-default-backend" { - lb, ok := backend["load-balance"].(string) - Expect(ok).Should(Equal(true)) - Expect(lb).Should(Equal("ewma")) - } - } + Expect(algorithm).Should(Equal("ewma")) }) })