Skip to content

Commit

Permalink
antctl test
Browse files Browse the repository at this point in the history
  • Loading branch information
gran-vmv committed May 6, 2022
1 parent fe1f257 commit 2f15b65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ci/jenkins/test.sh
Expand Up @@ -532,7 +532,7 @@ function run_e2e {
if [[ $FLEXIBLE_IPAM == true ]]; then
go test -v antrea.io/antrea/test/e2e --logs-export-dir `pwd`/antrea-test-logs --provider remote -timeout=100m --prometheus --antrea-ipam
else
go test -v antrea.io/antrea/test/e2e --logs-export-dir `pwd`/antrea-test-logs --provider remote -timeout=100m --prometheus
go test -v -run=TestTraceflow antrea.io/antrea/test/e2e --logs-export-dir `pwd`/antrea-test-logs --provider remote -timeout=100m --prometheus
fi
if [[ "$?" != "0" ]]; then
TEST_FAILURE=true
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/traceflow_test.go
Expand Up @@ -15,6 +15,7 @@
package e2e

import (
"antrea.io/antrea/pkg/apis/controlplane/v1beta2"
"context"
"fmt"
"net"
Expand Down Expand Up @@ -1201,6 +1202,14 @@ func testTraceflowInterNode(t *testing.T, data *TestData) {
}
}()

antreaPod, err := data.getAntreaPodOnNode(node2)
if err = data.waitForNetworkpolicyRealized(antreaPod, allowAllEgressName, v1beta2.K8sNetworkPolicy); err != nil {
t.Fatal(err)
}
if err = data.waitForNetworkpolicyRealized(antreaPod, denyAllIngressName, v1beta2.K8sNetworkPolicy); err != nil {
t.Fatal(err)
}

testcases := []testcase{
{
name: "interNodeTraceflowIPv4",
Expand Down Expand Up @@ -2165,6 +2174,27 @@ func (data *TestData) createNPAllowAllEgress(name string) (*networkingv1.Network
return data.createNetworkPolicy(name, spec)
}

// waitForNetworkpolicyRealized waits for the NetworkPolicy to be realized by the antrea-agent Pod.
func (data *TestData) waitForNetworkpolicyRealized(pod string, networkpolicy string, npType v1beta2.NetworkPolicyType) error {
npOption := "K8sNP"
if npType == v1beta2.AntreaNetworkPolicy {
npOption = "ANP"
}
if err := wait.Poll(200*time.Millisecond, 5*time.Second, func() (bool, error) {
cmds := []string{"antctl", "get", "networkpolicy", "-S", networkpolicy, "-n", testNamespace, "-T", npOption}
stdout, stderr, err := runAntctl(pod, cmds, data)
if err != nil {
return false, fmt.Errorf("Error when executing antctl get NetworkPolicy, stdout: %s, stderr: %s, err: %v", stdout, stderr, err)
}
return strings.Contains(stdout, fmt.Sprintf("%s:%s/%s", npType, testNamespace, networkpolicy)), nil
}); err == wait.ErrWaitTimeout {
return fmt.Errorf("NetworkPolicy %s isn't realized in time", networkpolicy)
} else if err != nil {
return err
}
return nil
}

func runTestTraceflow(t *testing.T, data *TestData, tc testcase) {
switch tc.ipVersion {
case 4:
Expand Down

0 comments on commit 2f15b65

Please sign in to comment.