diff --git a/ci/jenkins/test.sh b/ci/jenkins/test.sh index 02f02def582..255f67960c2 100755 --- a/ci/jenkins/test.sh +++ b/ci/jenkins/test.sh @@ -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 diff --git a/test/e2e/traceflow_test.go b/test/e2e/traceflow_test.go index 0b174057153..910098ca92e 100644 --- a/test/e2e/traceflow_test.go +++ b/test/e2e/traceflow_test.go @@ -15,6 +15,7 @@ package e2e import ( + "antrea.io/antrea/pkg/apis/controlplane/v1beta2" "context" "fmt" "net" @@ -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", @@ -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: