Skip to content

Commit

Permalink
agent: add first fv tests version
Browse files Browse the repository at this point in the history
  • Loading branch information
hedibouattour committed Feb 17, 2023
1 parent e882e15 commit 3b1ff01
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 20 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ run-integration-tests-cni:

.PHONY: run-integration-tests-policy
run-integration-tests-policy:
$(MAKE) -C felix fv-prereqs
cd test/integration-tests;./run-tests.sh policy

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion calico-vpp-agent/cmd/calico_vpp_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import (
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/services"
"github.com/projectcalico/vpp-dataplane/config"

watchdog "github.com/projectcalico/vpp-dataplane/calico-vpp-agent/watch_dog"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/watchers"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/watch_dog"
)

/*
Expand Down
2 changes: 1 addition & 1 deletion calico-vpp-agent/cni/cni_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var _ = Describe("Node-related functionality of CNI", func() {

JustBeforeEach(func() {
test.StartVPP()
vpp, uplinkSwIfIndex = test.ConfigureVPP(log)
vpp, uplinkSwIfIndex = test.ConfigureVPP(log, false)

// setup connectivity server (functionality target of tests)
if ipamStub == nil {
Expand Down
4 changes: 2 additions & 2 deletions calico-vpp-agent/cni/cni_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/vishvananda/netlink"

"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni"
test "github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common_tests"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common"
test "github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common_tests"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/tests/mocks"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/watchers"
"github.com/projectcalico/vpp-dataplane/config"
Expand All @@ -58,7 +58,7 @@ var _ = Describe("Pod-related functionality of CNI", func() {
BeforeEach(func() {
log = logrus.New()
test.StartVPP()
vpp, _ = test.ConfigureVPP(log)
vpp, _ = test.ConfigureVPP(log, false)
// setup connectivity server (functionality target of tests)
if ipamStub == nil {
ipamStub = mocks.NewIpamCacheStub()
Expand Down
71 changes: 55 additions & 16 deletions calico-vpp-agent/common_tests/common_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,46 @@ import (
"github.com/sirupsen/logrus"

"github.com/containernetworking/plugins/pkg/ns"
apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
cniproto "github.com/projectcalico/calico/cni-plugin/pkg/dataplane/grpc/proto"
"github.com/projectcalico/calico/libcalico-go/lib/options"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni/pod_interface"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni/storage"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/connectivity"
cniproto "github.com/projectcalico/calico/cni-plugin/pkg/dataplane/grpc/proto"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/tests/mocks/calico"
"github.com/projectcalico/vpp-dataplane/multinet-monitor/networkAttachmentDefinition"
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/binapi/vppapi/interface_types"
"github.com/projectcalico/vpp-dataplane/vpplink/binapi/vppapi/ip_types"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// PodMockContainerName is used container name for pod container mock
PodMockContainerName = "cni-tests-pod-mock"
// PodMockImage is docker image used for pod mocking
PodMockImage = "calicovpp/vpp-test-pod-mock:latest"
VPPContainerName = "cni-tests-vpp"
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
ThisNodeName = "node1"
UplinkIfName = "uplink"
UplinkIP = "10.0.100.1"
UplinkIPv6 = "A::1:1"
GatewayIP = "10.0.100.254"
GatewayIPv6 = "A::1:254"
ThisNodeIP = UplinkIP
ThisNodeIPv6 = UplinkIPv6
PodMockImage = "calicovpp/vpp-test-pod-mock:latest"
VPPContainerName = "cni-tests-vpp"
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
ThisNodeName = "node1"
UplinkIfName = "uplink"
Uplink2IfName = "uplink2"
UplinkIP = "10.0.100.1"
UplinkIPv6 = "A::1:1"
Uplink2IP = "11.0.100.1"
Uplink2IPv6 = "B::1:1"
GatewayIP = "10.0.100.254"
GatewayIPv6 = "A::1:254"
ThisNodeIP = UplinkIP
ThisNodeIPv6 = UplinkIPv6

AddedNodeName = "node2"
AddedNodeIP = "10.0.200.1"
AddedNodeIPv6 = "A::2:1"
)

var (
// VppImage is the name of docker image containing VPP binary
VppImage string
Expand All @@ -63,6 +68,7 @@ var (
// vppContainerExtraArgs is a list of additionnal cli parameters for the VPP `docker run ...`
VppContainerExtraArgs []string = []string{}
)

func AssertTunInterfaceExistence(vpp *vpplink.VppLink, newPod *cniproto.AddRequest) uint32 {
ifSwIfIndex, err := vpp.SearchInterfaceWithTag(
InterfaceTagForLocalTunTunnel(newPod.InterfaceName, newPod.Netns))
Expand Down Expand Up @@ -289,8 +295,8 @@ func StartVPP() {
vppBinaryConfigArg := `unix {
nodaemon
full-coredump
cli-listen /var/run/vpp/cli2.sock
pidfile /run/vpp/vpp2.pid
cli-listen /var/run/vpp/cli.sock
pidfile /run/vpp/vpp.pid
}
api-trace { on }
cpu {
Expand Down Expand Up @@ -325,7 +331,7 @@ func StartVPP() {
}

// ConfigureVPP connects to VPP and configures it with common configuration needed for tests
func ConfigureVPP(log *logrus.Logger) (vpp *vpplink.VppLink, uplinkSwIfIndex uint32) {
func ConfigureVPP(log *logrus.Logger, additionaluplink bool) (vpp *vpplink.VppLink, uplinkSwIfIndex uint32) {
// connect to VPP
vpp, err := common.CreateVppLinkInRetryLoop("/tmp/"+VPPContainerName+"/vpp-api-test.sock",
log.WithFields(logrus.Fields{"component": "vpp-api"}), 20*time.Second, 100*time.Millisecond)
Expand Down Expand Up @@ -379,6 +385,39 @@ func ConfigureVPP(log *logrus.Logger) (vpp *vpplink.VppLink, uplinkSwIfIndex uin
UplinkIfName, "up").Run()
Expect(err).ToNot(HaveOccurred(), "Failed to set state to UP for host end of tap")

if additionaluplink {
// setup simplified mock version of uplink interface
// Note: for the real configuration of the uplink interface and other related things see
// UplinkDriver.CreateMainVppInterface(...) and VppRunner.configureVpp(...))
uplinkSwIfIndex, err = vpp.CreateTapV2(&types.TapV2{
GenericVppInterface: types.GenericVppInterface{
HostInterfaceName: Uplink2IfName,
HardwareAddr: Mac("aa:bb:cc:dd:ee:03"),
},
Tag: fmt.Sprintf("main-%s", Uplink2IfName),
Flags: types.TapFlagNone,
// Host end of tap (it is located inside docker container)
HostMtu: 1500,
HostMacAddress: *Mac("aa:bb:cc:dd:ee:04"),
})
Expect(err).ToNot(HaveOccurred(), "Error creating mocked Uplink interface")
err = vpp.InterfaceAdminUp(uplinkSwIfIndex)
Expect(err).ToNot(HaveOccurred(), "Error setting state to UP for mocked Uplink interface")
err = vpp.AddInterfaceAddress(uplinkSwIfIndex, IpNet(Uplink2IP+"/24"))
Expect(err).ToNot(HaveOccurred(), "Error adding IPv4 address to data interface")
err = vpp.AddInterfaceAddress(uplinkSwIfIndex, IpNet(Uplink2IPv6+"/16"))
Expect(err).ToNot(HaveOccurred(), "Error adding IPv6 address to data interface")
err = exec.Command("docker", "exec", VPPContainerName, "ip", "address", "add",
GatewayIP+"/24", "dev", Uplink2IfName).Run()
Expect(err).ToNot(HaveOccurred(), "Failed to set IPv4 address for host end of tap")
err = exec.Command("docker", "exec", VPPContainerName, "ip", "address", "add",
GatewayIPv6+"/16", "dev", Uplink2IfName).Run()
Expect(err).ToNot(HaveOccurred(), "Failed to set IPv6 address for host end of tap")
err = exec.Command("docker", "exec", VPPContainerName, "ip", "link", "set",
Uplink2IfName, "up").Run()
Expect(err).ToNot(HaveOccurred(), "Failed to set state to UP for host end of tap")

}
return
}

Expand Down
Loading

0 comments on commit 3b1ff01

Please sign in to comment.