-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e882e15
commit 051dfe9
Showing
7 changed files
with
267 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
// Copyright (c) 2022 Cisco and/or its affiliates. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package policy_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
felixconfig "github.com/projectcalico/calico/felix/config" | ||
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/cni" | ||
"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/policy" | ||
watchdog "github.com/projectcalico/vpp-dataplane/calico-vpp-agent/watch_dog" | ||
"github.com/projectcalico/vpp-dataplane/config" | ||
agentConf "github.com/projectcalico/vpp-dataplane/config" | ||
"github.com/projectcalico/vpp-dataplane/vpplink" | ||
"github.com/projectcalico/vpp-dataplane/vpplink/types" | ||
"github.com/sirupsen/logrus" | ||
tomb "gopkg.in/tomb.v2" | ||
) | ||
|
||
// Names of integration tests arguments | ||
const ( | ||
IntegrationTestEnableArgName = "INTEGRATION_TEST" | ||
VppImageArgName = "VPP_IMAGE" | ||
VppBinaryArgName = "VPP_BINARY" | ||
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS" | ||
) | ||
|
||
var t tomb.Tomb | ||
|
||
// TestCniIntegration runs all the ginkgo integration test inside CNI package | ||
func TestCniIntegration(t *testing.T) { | ||
// skip test if test run is not integration test run (prevent accidental run of integration tests using go test ./...) | ||
_, isIntegrationTestRun := os.LookupEnv(IntegrationTestEnableArgName) | ||
if !isIntegrationTestRun { | ||
t.Skip("skipping CNI integration tests (set INTEGRATION_TEST env variable to run these tests)") | ||
} | ||
|
||
// integrate gomega and ginkgo -> register all CNI integration tests | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "CNI Integration Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
// extract common input for CNI integration tests | ||
var found bool | ||
test.VppImage, found = os.LookupEnv(VppImageArgName) | ||
if !found { | ||
Expect(test.VppImage).ToNot(BeEmpty(), fmt.Sprintf("Please specify docker image containing "+ | ||
"VPP binary using %s environment variable.", VppImageArgName)) | ||
} | ||
test.VppBinary, found = os.LookupEnv(VppBinaryArgName) | ||
if !found { | ||
Expect(test.VppBinary).ToNot(BeEmpty(), fmt.Sprintf("Please specify VPP binary (full path) "+ | ||
"inside docker image %s using %s environment variable.", test.VppImage, VppBinaryArgName)) | ||
} | ||
|
||
vppContainerExtraArgsList, found := os.LookupEnv(VppContainerExtraArgsName) | ||
if found { | ||
test.VppContainerExtraArgs = append(test.VppContainerExtraArgs, strings.Split(vppContainerExtraArgsList, ",")...) | ||
} | ||
|
||
}) | ||
|
||
var _ = Describe("Functionality of policy server using felix", func() { | ||
var ( | ||
log *logrus.Logger | ||
vpp *vpplink.VppLink | ||
policyServer *policy.Server | ||
err error | ||
cniServer *cni.Server | ||
) | ||
BeforeEach(func() { | ||
log = logrus.New() | ||
common.ThePubSub = common.NewPubSub(log.WithFields(logrus.Fields{"component": "pubsub"})) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
test.StartVPP() | ||
var uplinkSwIfIndex uint32 | ||
vpp, _ = test.ConfigureVPP(log) | ||
// Additional configuration specific to policies test: add tap for host endpoints | ||
uplinkSwIfIndex, err = vpp.CreateTapV2(&types.TapV2{ | ||
GenericVppInterface: types.GenericVppInterface{ | ||
HostInterfaceName: test.UplinkIfName, | ||
HardwareAddr: test.Mac("aa:bb:cc:dd:ee:01"), | ||
}, | ||
Tag: fmt.Sprintf("host-%s", test.UplinkIfName), | ||
Flags: types.TapFlagNone, | ||
// Host end of tap (it is located inside docker container) | ||
HostMtu: 1500, | ||
HostMacAddress: *test.Mac("aa:bb:cc:dd:ee:02"), | ||
}) | ||
Expect(err).ToNot(HaveOccurred(), "Error creating mocked tap interface") | ||
log.Infof("tap swifindex: %+v", uplinkSwIfIndex) | ||
|
||
config.GetCalicoVppDebug().PoliciesEnabled = &config.True | ||
common.VppManagerInfo = &agentConf.VppManagerInfo{UplinkStatuses: []agentConf.UplinkStatus{{IsMain: true, SwIfIndex: 1}}} | ||
policyServer, err = policy.NewPolicyServer(vpp, log.WithFields(logrus.Fields{"component": "policy"}), false) | ||
Expect(err).ToNot(HaveOccurred(), "Failed to create policy server") | ||
cniServer = cni.NewCNIServer(vpp, policyServer, log.WithFields(logrus.Fields{"component": "cni"})) | ||
Go(policyServer.ServePolicy) | ||
log.Info("WAITING FOR FELIX CONFIG... please run felix") | ||
|
||
/*cmd := exec.Command("./run-batches") | ||
cmd.Env = os.Environ() | ||
cmd.Dir = "/home/ubuntu/vpp-dataplane/felix/fv" | ||
cmd.Env = append(cmd.Env, | ||
"FV_FELIXIMAGE=felix:latest-amd64", | ||
"FV_ETCDIMAGE=quay.io/coreos/etcd:v3.5.1", | ||
"FV_TYPHAIMAGE=felix-test/typha:latest-amd64", | ||
"FV_K8SIMAGE=calico/go-build:v0.78", | ||
"FV_NUM_BATCHES=1", | ||
"FV_BATCHES_TO_RUN=\"1\"", | ||
"FV_FELIX_LOG_LEVEL=\"\"", | ||
"CERTS_PATH=/home/ubuntu/calico/hack/test/certs", | ||
"PRIVATE_KEY=/home/ubuntu/vpp-dataplane/felix/fv/private.key", | ||
"GINKGO_ARGS=''", | ||
"GINKGO_FOCUS=", | ||
"FELIX_FV_ENABLE_BPF=\"\"", | ||
"FV_RACE_DETECTOR_ENABLED=true", | ||
"FV_BINARY=/home/ubuntu/vpp-dataplane/felix/fv/bin/calico-felix-race-amd64", | ||
"FELIX_FV_WIREGUARD_AVAILABLE=`./wireguard-available >/dev/null && echo true || echo false`", | ||
) | ||
out, err := cmd.Output() | ||
log.Infof("OOOOO %s -- %+v", out, err) | ||
Expect(err).Should(BeNil(), "Failed to start felix %+v", err)*/ | ||
|
||
// now run felix leveraging fv tests from calico | ||
cmd := exec.Command("make", "fv") | ||
cmd.Env = os.Environ() | ||
cmd.Dir = "../../felix" | ||
cmd.Env = append(cmd.Env, "GINKGO_FOCUS=should create a host endpoint with a policy") | ||
err := cmd.Run() | ||
|
||
Expect(err).Should(BeNil(), "Failed to start felix %+v", err) | ||
|
||
watchDog := watchdog.NewWatchDog(log.WithFields(logrus.Fields{"component": "watchDog"}), &t) | ||
felixConfig := watchDog.Wait(policyServer.FelixConfigChan, "Waiting for FelixConfig to be provided by the calico pod") | ||
|
||
//stopped here until the felix config is sent | ||
log.Info("WAITING FOR FELIX CONFIG... please run felix") | ||
|
||
cniServer.SetFelixConfig(felixConfig.(*felixconfig.Config)) | ||
cniServer.FetchBufferConfig() | ||
|
||
}) | ||
|
||
Describe("Addition of a policy on a pod", func() { | ||
Context("With creation of the pod in cni server", func() { | ||
/*It("should create pod", func() { | ||
test.CreatePod() | ||
const ( | ||
ipAddress = "1.2.3.44" | ||
interfaceName = "newInterface" | ||
) | ||
By("Getting Pod mock container's PID") | ||
containerPidOutput, err := exec.Command("docker", "inspect", "-f", "{{.State.Pid}}", | ||
test.PodMockContainerName).Output() | ||
Expect(err).Should(BeNil(), "Failed to get pod mock container's PID string") | ||
containerPidStr := strings.ReplaceAll(string(containerPidOutput), "\n", "") | ||
By("Adding pod using CNI server") | ||
newPod := &proto.AddRequest{ | ||
InterfaceName: interfaceName, | ||
Netns: fmt.Sprintf("/proc/%s/ns/net", containerPidStr), // expecting mount of "/proc" from host | ||
ContainerIps: []*proto.IPConfig{{Address: ipAddress + "/24"}}, | ||
Workload: &proto.WorkloadIDs{ | ||
Annotations: map[string]string{ | ||
"cni.projectcalico.org/AllowedSourcePrefixes": "[\"172.16.104.7\", \"3.4.5.6\"]", | ||
}, | ||
}, | ||
} | ||
reply, err := cniServer.Add(context.Background(), newPod) | ||
Expect(err).ToNot(HaveOccurred(), "Pod addition failed") | ||
Expect(reply.Successful).To(BeTrue(), | ||
fmt.Sprintf("Pod addition failed due to: %s", reply.ErrorMessage)) | ||
By("Checking existence (and IP address) of interface tunnel at added pod's end") | ||
interfaceDetails, err := exec.Command("docker", "exec", test.PodMockContainerName, | ||
"ip", "address", "show", "dev", interfaceName).Output() | ||
time.Sleep(time.Second * 300) | ||
log.Infof("%+v", interfaceDetails) | ||
})*/ | ||
|
||
}) | ||
}) | ||
Describe("Addition of a policy on a host", func() { | ||
It("should configure host endpoint", func() { | ||
time.Sleep(time.Second * 10) | ||
policiesStr, err := vpp.RunCli("show capo int") | ||
Expect(err).ToNot(HaveOccurred(), "failed to get policies on interfaces") | ||
Expect(policiesStr).To(ContainSubstring("1.9.9.1")) | ||
time.Sleep(time.Second * 5) | ||
|
||
}) | ||
}) | ||
|
||
AfterEach(func() { | ||
test.TeardownVPP() | ||
}) | ||
}) | ||
|
||
func Go(f func(t *tomb.Tomb) error) { | ||
t.Go(func() error { | ||
defer GinkgoRecover() | ||
err := f(&t) | ||
if err != nil { | ||
Expect(err).Should(BeNil(), "Tomb function errored with %s", err) | ||
} | ||
return err | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
.PHONY: fv | ||
fv: | ||
cd calico/felix && make fv-no-prereqs | ||
|
||
.PHONY: fv-prereqs | ||
fv-prereqs: | ||
sudo mkdir -p /var/run/calico | ||
git clone https://github.com/calico-vpp/calico 2> /dev/null || echo | ||
(cd calico/ ; git checkout origin/feature/wip-fv-tests-vpp) | ||
cd calico/felix && make fv-prereqs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
### Prerequisits for running integration tests for policy server using felix fv tests: | ||
* docker buildx plugin installed | ||
* |