Skip to content

Commit

Permalink
Remove usage of RunCommandOnNode for multicast e2e tests (#5709)
Browse files Browse the repository at this point in the history
RunCommandOnNode should be avoided as much as possible, as it tends to
make assumptions about software available on Nodes. In this case, we can
run the same commands from the Antrea Agent Pod.

With this change, we can also remove some Kind-specific code.

Signed-off-by: Antonin Bas <[email protected]>
Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Dec 13, 2023
1 parent 4e77a4d commit cfd7b86
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions test/e2e/multicast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,25 +600,49 @@ func runTestMulticastBetweenPods(t *testing.T, data *TestData, mc multicastTestc
data.RunCommandFromPod(data.testNamespace, senderName, mcjoinContainerName, sendMulticastCommand)
}()

runCmdWithOutputFilters := func(nodeName string, cmd []string, outputFilters ...string) ([]string, error) {
stdout, _, err := data.RunCommandFromAntreaPodOnNode(nodeName, cmd)
if err != nil {
return nil, err
}
res := make([]string, 0)
outer:
for _, line := range strings.Split(stdout, "\n") {
for _, f := range outputFilters {
if !strings.Contains(line, f) {
continue outer
}
}
res = append(res, line)
}
return res, nil
}

getMroutes := func(nodeName string, iface string, outputFilters ...string) ([]string, error) {
cmd := []string{"ip", "mroute", "show", "iif", iface}
return runCmdWithOutputFilters(nodeName, cmd, outputFilters...)
}

getMaddrs := func(nodeName string, iface string, outputFilters ...string) ([]string, error) {
cmd := []string{"ip", "maddr", "show", "dev", iface}
return runCmdWithOutputFilters(nodeName, cmd, outputFilters...)
}

readyReceivers := sets.New[int]()
senderReady := false
if err := wait.Poll(3*time.Second, defaultTimeout, func() (bool, error) {
if !senderReady {
// Sender pods should add an outbound multicast route except running as HostNetwork.
cmd := fmt.Sprintf("ip mroute show iif %s | grep %s | grep '%s'", gatewayInterface, mc.group.String(), strings.Join(nodeMulticastInterfaces[mc.senderConfig.nodeIdx], " "))
if testOptions.providerName == "kind" {
cmd = "/bin/sh -c " + cmd
}
_, mrouteResult, _, err := data.RunCommandOnNode(nodeName(mc.senderConfig.nodeIdx), cmd)
// Sender pods should add an outbound multicast route except when running as HostNetwork.
mRoutesResult, err := getMroutes(nodeName(mc.senderConfig.nodeIdx), gatewayInterface, mc.group.String(), strings.Join(nodeMulticastInterfaces[mc.senderConfig.nodeIdx], " "))
if err != nil {
return false, err
}
if !mc.senderConfig.isHostNetwork {
if len(mrouteResult) == 0 {
if len(mRoutesResult) == 0 {
return false, nil
}
} else {
if len(mrouteResult) != 0 {
if len(mRoutesResult) != 0 {
return false, nil
}
}
Expand All @@ -632,43 +656,35 @@ func runTestMulticastBetweenPods(t *testing.T, data *TestData, mc multicastTestc
}
for _, receiverMulticastInterface := range nodeMulticastInterfaces[receiver.nodeIdx] {
if checkReceiverRoute {
cmd := fmt.Sprintf("ip mroute show iif %s | grep %s", receiverMulticastInterface, mc.group.String())
if testOptions.providerName == "kind" {
cmd = "/bin/sh -c " + cmd
}
_, mRouteResult, _, err := data.RunCommandOnNode(nodeName(receiver.nodeIdx), cmd)
mRoutesResult, err := getMroutes(nodeName(receiver.nodeIdx), receiverMulticastInterface, mc.group.String())
if err != nil {
return false, err
}
// If multicast traffic is sent from non-HostNetwork pods and senders-receivers are located in different nodes,
// the receivers should configure corresponding inbound multicast routes.
if mc.senderConfig.nodeIdx != receiver.nodeIdx && !receiver.isHostNetwork {
if len(mRouteResult) == 0 {
if len(mRoutesResult) == 0 {
return false, nil
}
} else {
if len(mRouteResult) != 0 {
if len(mRoutesResult) != 0 {
return false, nil
}
}
}
cmd := fmt.Sprintf("ip maddr show %s | grep %s", receiverMulticastInterface, mc.group.String())
if testOptions.providerName == "kind" {
cmd = "/bin/sh -c " + cmd
}
_, mAddrResult, _, err := data.RunCommandOnNode(nodeName(receiver.nodeIdx), cmd)
mAddrsResult, err := getMaddrs(nodeName(receiver.nodeIdx), receiverMulticastInterface, mc.group.String())
if err != nil {
return false, err
}
// The receivers should also join multicast group.
// Note that in HostNetwork mode, the "join multicast" action is taken by mcjoin,
// which will not persist after mcjoin exits.
if !receiver.isHostNetwork {
if len(mAddrResult) == 0 {
if len(mAddrsResult) == 0 {
return false, nil
}
} else {
if len(mAddrResult) != 0 {
if len(mAddrsResult) != 0 {
return false, nil
}
}
Expand Down

0 comments on commit cfd7b86

Please sign in to comment.