Merge pull request #4270 from ElvinEfendi/e2e-test-refactor

GetLbAlgorithm helper func for e2e
This commit is contained in:
Kubernetes Prow Robot 2019-07-03 06:04:32 -07:00 committed by GitHub
commit a653e329aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View file

@ -18,6 +18,7 @@ package framework
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"io" "io"
"os/exec" "os/exec"
@ -28,6 +29,30 @@ import (
corev1 "k8s.io/api/core/v1" 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 // ExecIngressPod executes a command inside the first container in ingress controller running pod
func (f *Framework) ExecIngressPod(command string) (string, error) { func (f *Framework) ExecIngressPod(command string) (string, error) {
pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet) pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet)

View file

@ -17,7 +17,6 @@ limitations under the License.
package loadbalance package loadbalance
import ( import (
"encoding/json"
"strings" "strings"
"time" "time"
@ -53,20 +52,8 @@ var _ = framework.IngressNginxDescribe("Load Balance - Configmap value", func()
}) })
time.Sleep(waitForLuaSync) time.Sleep(waitForLuaSync)
getCmd := "/dbg backends all" algorithm, err := f.GetLbAlgorithm("http-svc", 80)
output, err := f.ExecIngressPod(getCmd)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
Expect(algorithm).Should(Equal("ewma"))
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"))
}
}
}) })
}) })