diff --git a/pkg/agent/apiserver/handlers/ovstracing/handler.go b/pkg/agent/apiserver/handlers/ovstracing/handler.go index ea29f4cf4ad..4544e08c832 100644 --- a/pkg/agent/apiserver/handlers/ovstracing/handler.go +++ b/pkg/agent/apiserver/handlers/ovstracing/handler.go @@ -356,7 +356,7 @@ func validateRequest(r *http.Request) (*request, *handlers.HandlerError) { return &request, nil } -// HandleFunc returns the function which can handle API requests to "/ovsflows". +// HandleFunc returns the function which can handle API requests to "/ovstracing". func HandleFunc(aq querier.AgentQuerier) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var traceReq *ovsctl.TracingRequest diff --git a/pkg/ovs/ovsctl/appctl.go b/pkg/ovs/ovsctl/appctl.go index 3b0232ee03d..41c88153e32 100644 --- a/pkg/ovs/ovsctl/appctl.go +++ b/pkg/ovs/ovsctl/appctl.go @@ -38,6 +38,7 @@ func (r *ovsAppctlRunner) RunAppctlCmd(cmd string, needsBridge bool, args ...str if needsBridge { cmdArgs = append(cmdArgs, r.bridge) } + cmdArgs = append(cmdArgs, args...) ovsCmd := exec.CommandContext(context.TODO(), "ovs-appctl", cmdArgs...) out, err := ovsCmd.CombinedOutput() if err != nil { diff --git a/test/e2e/antctl_test.go b/test/e2e/antctl_test.go index ae7936c0f10..b7ac4be9976 100644 --- a/test/e2e/antctl_test.go +++ b/test/e2e/antctl_test.go @@ -67,6 +67,7 @@ func TestAntctl(t *testing.T) { t.Run("testAntctlAgentLocalAccess", func(t *testing.T) { testAntctlAgentLocalAccess(t, data) + testAntctlAgentTracePacket(t, data) }) t.Run("testAntctlControllerRemoteAccess", func(t *testing.T) { testAntctlControllerRemoteAccess(t, data, antctlServiceAccountName, antreaImage) @@ -159,6 +160,30 @@ func testAntctlAgentLocalAccess(t *testing.T, data *TestData) { } } +// testAntctlAgentTracePacket ensures antctl trace-packet is runnable in an agent Pod. +func testAntctlAgentTracePacket(t *testing.T, data *TestData) { + podName, err := data.getAntreaPodOnNode(controlPlaneNodeName()) + if err != nil { + t.Fatalf("Error when getting antrea-agent pod name: %v", err) + } + var args []string + if testOptions.enableCoverage { + antctlCovArgs := antctlCoverageArgs("antctl-coverage", "") + args = append(antctlCovArgs, "trace-packet") + } else { + args = []string{"antctl", "trace-packet"} + } + t.Logf("args: %s", args) + + cmd := strings.Join(args, " ") + t.Run(cmd, func(t *testing.T) { + stdout, stderr, err := runAntctl(podName, args, data) + if err != nil && !strings.Contains(stderr, "not enabled\n") { + t.Fatalf("Error when running `antctl trace-packet` from %s: %v\n%s", podName, err, antctlOutput(stdout, stderr)) + } + }) +} + func runAntctlPod(t *testing.T, data *TestData, podName string, antctlServiceAccountName string, antctlImage string, covDir string) { b := NewPodBuilder(podName, data.testNamespace, antctlImage).WithServiceAccountName(antctlServiceAccountName). WithContainerName("antctl").WithCommand([]string{"sleep", "3600"}).