Skip to content

Commit

Permalink
Fix antctl trace-packet arguments missing issue
Browse files Browse the repository at this point in the history
Fix the following error when running `antctl trace-packet`, which is
caused by missing arguments for ovs-appctl command.

```
syntax error at br-int (or the bridge name was omitted)
ovs-appctl: /var/run/openvswitch/ovs-vswitchd.103.ctl: server returned an error
```

Signed-off-by: Lan Luo <[email protected]>
  • Loading branch information
luolanzone committed Jan 4, 2024
1 parent 48c1646 commit 30c7219
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/agent/apiserver/handlers/ovstracing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/ovs/ovsctl/appctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/antctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"}).
Expand Down

0 comments on commit 30c7219

Please sign in to comment.