diff --git a/test/e2e/antreapolicy_test.go b/test/e2e/antreapolicy_test.go index ac1bc654429..4c465cefc2c 100644 --- a/test/e2e/antreapolicy_test.go +++ b/test/e2e/antreapolicy_test.go @@ -3704,6 +3704,8 @@ sleep 3600 t.Fatalf("Failed to create client Pod: %v", err) } defer data.deletePodAndWait(defaultTimeout, clientName, data.testNamespace) + err := data.podWaitForRunning(defaultTimeout, clientName, data.testNamespace) + failOnError(err, t) ips, err := data.podWaitForIPs(defaultTimeout, clientName, data.testNamespace) failOnError(err, t) @@ -3761,7 +3763,20 @@ sleep 3600 failOnError(waitForResourceReady(t, timeout, acnp), t) for _, tc := range testcases { log.Tracef("Probing: %s -> %s:%d", cidr, tc.destAddr, tc.destPort) - connectivity, err := k8sUtils.ProbeAddr(tc.clientPod.Namespace(), "antrea-e2e", tc.clientPod.PodName(), tc.destAddr, tc.destPort, ProtocolTCP) + // Connect to NodePort in the fake external network. + cmd = fmt.Sprintf("for i in $(seq 1 3); do ip netns exec %s /agnhost connect %s:%d --timeout=1s --protocol=tcp; done;", testNetns, tc.destAddr, tc.destPort) + stdout, stderr, err := data.RunCommandFromPod(data.testNamespace, clientName, agnhostContainerName, []string{"sh", "-c", cmd}) + connectivity := Connected + if err != nil || stderr != "" { + // log this error as trace since may be an expected failure + log.Tracef("%s -> %s: error when running command: err - %v /// stdout - %s /// stderr - %s", cidr, tc.destAddr, err, stdout, stderr) + // If err != nil and stderr == "", then it means this probe failed because of + // the command instead of connectivity. For example, container name doesn't exist. + if stderr == "" { + connectivity = Error + } + connectivity = DecideProbeResult(stderr, 3) + } if err != nil { t.Errorf("failure -- could not complete probe: %v", err) }