Skip to content

Commit

Permalink
Support all e2e tests with agent in separate container
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Dec 16, 2020
1 parent 9083ff8 commit 8841c95
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 589 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ BUILD_DIR := .build
endif

export GO111MODULE=on
export DOCKER_BUILDKIT=1

include vpp.env

Expand All @@ -55,6 +56,10 @@ ifeq ($(NOSTRIP),)
LDFLAGS += -w -s
endif

ifeq ($(NOTRIM),)
GO_BUILD_ARGS += -trimpath
endif

ifeq ($(BUILDPIE),y)
GO_BUILD_ARGS += -buildmode=pie
LDFLAGS += -extldflags=-Wl,-z,now,-z,relro
Expand Down Expand Up @@ -177,14 +182,9 @@ integration-tests: test-tools ## Run integration tests
@echo "# running integration tests"
VPP_IMG=$(VPP_IMG) ./tests/integration/run_integration.sh

e2e-tests: test-tools ## Run end-to-end tests
e2e-tests: images test-tools ## Run end-to-end tests
@echo "# running end-to-end tests"
VPP_IMG=$(VPP_IMG) ./tests/e2e/run_e2e.sh

e2e-tests-cover: ## Run end-to-end tests with coverage
@echo "# running end-to-end tests with coverage"
VPP_IMG=$(VPP_IMG) COVER_DIR=$(COVER_DIR) ./tests/e2e/run_e2e.sh
@echo "# coverage report generated into ${COVER_DIR}/e2e-cov.out"
VPP_AGENT=prod_vpp_agent ./tests/e2e/run_e2e.sh

# -------------------------------
# Code generation
Expand Down Expand Up @@ -265,7 +265,7 @@ test-tools: ## install test tools
ifndef gotestsumcmd
go get -v gotest.tools/gotestsum
endif
env CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BUILD_DIR)/test2json cmd/test2json
@env CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BUILD_DIR)/test2json cmd/test2json

LINTER := $(shell command -v gometalinter 2> /dev/null)

Expand Down
10 changes: 3 additions & 7 deletions tests/e2e/012_linux_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ package e2e

import (
"context"
. "github.com/onsi/gomega"
"testing"
"time"

"go.ligato.io/cn-infra/v2/logging"
. "github.com/onsi/gomega"

"go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin/linuxcalls"
"go.ligato.io/vpp-agent/v3/plugins/netalloc/utils"
"go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler"
linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
Expand Down Expand Up @@ -130,8 +128,7 @@ func TestExistingInterface(t *testing.T) {
HostIfName: ifaceHostName,
}

ifHandler := linuxcalls.NewNetLinkHandler(
nil, nil, "", 0, logging.DefaultLogger)
ifHandler := ctx.vppAgent.LinuxInterfaceHandler()

hasIP := func(ifName, ipAddr string) bool {
addrs, err := ifHandler.GetAddressList(ifName)
Expand Down Expand Up @@ -229,8 +226,7 @@ func TestExistingLinkOnlyInterface(t *testing.T) {
LinkOnly: true, // <- agent does not configure IP addresses (they are also "existing")
}

ifHandler := linuxcalls.NewNetLinkHandler(
nil, nil, "", 0, logging.DefaultLogger)
ifHandler := ctx.vppAgent.LinuxInterfaceHandler()

hasIP := func(ifName, ipAddr string) bool {
addrs, err := ifHandler.GetAddressList(ifName)
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/080_vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ package e2e

import (
"context"
. "github.com/onsi/gomega"
"os"
"testing"
"time"

"go.ligato.io/cn-infra/v2/logging"
. "github.com/onsi/gomega"

kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api"
"go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin/linuxcalls"
"go.ligato.io/vpp-agent/v3/plugins/netalloc/utils"
"go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler"
linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
Expand Down Expand Up @@ -538,8 +536,9 @@ func TestExistingLinuxVRF(t *testing.T) {
Expect(ctx.GetValueState(iface2)).To(Equal(kvscheduler.ValueState_CONFIGURED)) // created but not in VRF yet
Expect(ctx.GetDerivedValueState(iface2, iface2InVrfKey)).To(Equal(kvscheduler.ValueState_PENDING))

ifHandler := ctx.vppAgent.LinuxInterfaceHandler()

// create referenced VRF using netlink (without the interface inside it for now)
ifHandler := linuxcalls.NewNetLinkHandler(nil, nil, "", 0, logging.DefaultLogger)
err = ifHandler.AddVRFDevice(vrfHostName, vrfRT)
Expect(err).To(BeNil())
err = ifHandler.SetInterfaceUp(vrfHostName)
Expand Down
36 changes: 17 additions & 19 deletions tests/e2e/100_agentctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func TestAgentCtlCommands(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
stdout, stderr, err = ctx.ExecCmd("/agentctl", strings.Split(test.cmd, " ")...)
// we need to register again for each subtest
// TODO: remove this after migration to NewWithT
RegisterTestingT(t)

stdout, stderr, err = ctx.ExecCmd("agentctl", strings.Split(test.cmd, " ")...)

if test.expectErr {
Expect(err).To(Not(BeNil()),
Expand Down Expand Up @@ -329,40 +333,34 @@ func TestAgentCtlSecureGrpc(t *testing.T) {
// to establish connection because it's not configured for this
// secure case.

t.Log("Replacing `GRPC_CONFIG` value with /etc/grpc-secure.conf")
t.Log("Replacing `GRPC_CONFIG` value with /testdata/grpc-secure.conf")
defer func(oldVal string) {
t.Logf("Setting `GRPC_CONFIG` back to %q", oldVal)
os.Setenv("GRPC_CONFIG", oldVal)
}(os.Getenv("GRPC_CONFIG"))
os.Setenv("GRPC_CONFIG", "/etc/grpc-secure.conf")
os.Setenv("GRPC_CONFIG", "/testdata/grpc-secure.conf")

ctx := Setup(t)
defer ctx.Teardown()

ctx.ExecCmd("bash", "-c", "set -x; ls /testdata; cat /testdata/agentctl.conf")

t.Log("Try without any TLS")
_, stderr, err := ctx.ExecCmd(
"/agentctl", "--debug", "dump", "vpp.interfaces",
)
"agentctl", "--debug", "dump", "vpp.interfaces")
Expect(err).To(Not(BeNil()))
Expect(stderr).To(ContainSubstring("rpc error"),
"Expected string not found in stderr")
Expect(stderr).To(ContainSubstring("rpc error"), "Expected string not found in stderr")

t.Log("Try with TLS enabled via flag --insecure-tls. Should work because server is not configured to check client certs.")
stdout, stderr, err := ctx.ExecCmd(
"/agentctl", "--debug", "--insecure-tls", "dump", "vpp.interfaces",
)
Expect(err).To(BeNil(),
"Should not fail. Got err: %v\nStderr:\n%s\n", err, stderr,
)
"agentctl", "--debug", "--insecure-tls", "dump", "vpp.interfaces")
Expect(err).To(BeNil(), "Should not fail. Got err: %v\nStderr:\n%s\n", err, stderr)
Expect(len(stdout)).To(Not(BeZero()))

t.Log("Try with fully configured TLS via config file")
stdout, stderr, err = ctx.ExecCmd(
"/agentctl", "--debug", "--config-dir=/etc/.agentctl", "dump", "vpp.interfaces",
)
Expect(err).To(BeNil(),
"Should not fail. Got err: %v\nStderr:\n%s\n", err, stderr,
)
"agentctl", "--debug", "--config=/testdata/agentctl.conf", "dump", "vpp.interfaces")
Expect(err).To(BeNil(), "Should not fail. Got err: %v\nStderr:\n%s\n", err, stderr)
Expect(stdout).ToNot(BeEmpty())
}

Expand All @@ -374,13 +372,13 @@ func TestAgentCtlSecureETCD(t *testing.T) {

// test without any TLS
t.Run("no TLS", func(t *testing.T) {
_, _, err := ctx.ExecCmd("/agentctl", "--debug", "kvdb", "list")
_, _, err := ctx.ExecCmd("agentctl", "--debug", "kvdb", "list")
Expect(err).To(Not(BeNil()))
})

// test with TLS enabled via flag --insecure-tls, but without cert and key (note: server configured to check those files)
t.Run("insecure TLS", func(t *testing.T) {
_, _, err := ctx.ExecCmd("/agentctl", "--debug", "--insecure-tls", "kvdb", "list")
_, _, err := ctx.ExecCmd("agentctl", "--debug", "--insecure-tls", "kvdb", "list")
Expect(err).To(Not(BeNil()))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/101_rest_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestInfoVersionHandler(t *testing.T) {
ctx := Setup(t)
defer ctx.Teardown()

version, err := ctx.agentctl.AgentVersion(context.Background())
version, err := ctx.agentClient.AgentVersion(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(version.App).ToNot(BeEmpty())
Expect(version.Version).ToNot(BeEmpty())
Expand Down
18 changes: 2 additions & 16 deletions tests/e2e/Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
ARG VPP_IMG=ligato/vpp-base

FROM golang:1.15 as build

RUN env CGO_ENABLED=0 \
go build -ldflags='-s -w -extldflags "-static"' -o /test2json cmd/test2json

FROM ${VPP_IMG}
FROM ubuntu:20.04

RUN apt-get update && apt-get install -yq \
curl \
Expand All @@ -22,9 +20,6 @@ RUN apt-get update && apt-get install -yq \
# - test2json
# - gotestsum

#RUN env CGO_ENABLED=0 \
# go build -ldflags='-s -w -extldflags "-static"' -o /usr/local/bin/test2json cmd/test2json

COPY --from=build /test2json /usr/local/bin/test2json

ARG GOTESTSUM_VERSION=0.6.0
Expand All @@ -34,16 +29,7 @@ RUN set -eux; \
mv gotestsum /usr/local/bin/gotestsum; \
rm gotestsum.tar.gz

COPY resources/certs/* /etc/certs/
COPY resources/grpc.conf /etc/
COPY resources/grpc-secure.conf /etc/
COPY resources/grpc-secure-full.conf /etc/
COPY resources/agentctl.conf /etc/.agentctl/config.yml

ENV GRPC_CONFIG /etc/grpc.conf

COPY agentctl.test /agentctl
COPY vpp-agent.test /vpp-agent
COPY agentctl.test /usr/local/bin/agentctl
COPY e2e.test /

COPY entrypoint.sh /entrypoint.sh
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func simpleUDPServer(ctx context.Context, ms *microservice, addr string, expReqM
func simpleTCPClient(ms *microservice, addr string, reqMsg, expRespMsg string, timeout time.Duration, done chan<- error) {
// try to connect with the server
newConn := make(chan connectionRequest, 1)

go func() {
// move to the network namespace from which the connection should be initiated
exitNetNs := ms.enterNetNs()
Expand All @@ -182,6 +183,7 @@ func simpleTCPClient(ms *microservice, addr string, reqMsg, expRespMsg string, t
func simpleUDPClient(ms *microservice, addr string, reqMsg, expRespMsg string, timeout time.Duration, done chan<- error) {
// try to connect with the server
newConn := make(chan connectionRequest, 1)

go func() {
// move to the network namespace from which the connection should be initiated
exitNetNs := ms.enterNetNs()
Expand Down Expand Up @@ -228,6 +230,7 @@ func simpleTCPOrUDPClient(newConn chan connectionRequest, addr, reqMsg, expRespM
commRv := make(chan error, 1)
go func() {
defer close(commRv)

// send message to the server
_, err := cr.conn.Write([]byte(reqMsg + "\n"))
if err != nil {
Expand Down Expand Up @@ -256,6 +259,7 @@ func simpleTCPOrUDPClient(newConn chan connectionRequest, addr, reqMsg, expRespM
message, expRespMsg)
return
}

commRv <- nil
}()

Expand Down
Loading

0 comments on commit 8841c95

Please sign in to comment.