Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
Signed-off-by: Hang Yan <yhang@vmware.com>
  • Loading branch information
hangyan committed Feb 18, 2024
1 parent e6f0ee1 commit b45505d
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions test/e2e/packetsampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
)

var (
psNamespace = "default"
psSecretName = "ps-secret"
psNamespace = "default"
psSecretName = "ps-secret"
psNginxPodName = "test-nginx"
psBusyboxPodName = "busybox"
)

type psTestCase struct {
Expand Down Expand Up @@ -90,38 +92,43 @@ func skipIfPacketSamplingDisabled(t *testing.T) {

// testPacketSamplingTCP verifies if PacketSampling can capture tcp packets.
func testPacketSamplingIntraNode(t *testing.T, data *TestData) {
var err error
k8sUtils, err = NewKubernetesUtils(data)
failOnError(err, t)

nodeIdx := 0
if len(clusterInfo.windowsNodes) != 0 {
nodeIdx = clusterInfo.windowsNodes[0]
}
node1 := nodeName(nodeIdx)
node1Pods, _, node1CleanupFn := createTestAgnhostPods(t, data, 3, data.testNamespace, node1)

node1Pods, _, node1CleanupFn := createTestAgnhostPods(t, data, 2, data.testNamespace, node1)
defer node1CleanupFn()
err := data.createNginxPodOnNode(psNginxPodName, data.testNamespace, node1, false)
require.NoError(t, err)
defer deletePodWrapper(t, data, data.testNamespace, psNginxPodName)

err = data.createBusyboxPodOnNode(psBusyboxPodName, data.testNamespace, node1, false)
require.NoError(t, err)
defer deletePodWrapper(t, data, data.testNamespace, psNginxPodName)

// Give a little time for Windows containerd Nodes to setup OVS.
// Containerd configures port asynchronously, which could cause execution time of installing flow longer than docker.
time.Sleep(time.Second * 1)

testcases := []psTestCase{
{
name: "ICMPIPv4",
name: "intraNodePacketSamplingIPv4",
ipVersion: 4,
srcPod: node1Pods[0],
srcPod: psBusyboxPodName,
ps: &crdv1alpha1.PacketSampling{
ObjectMeta: metav1.ObjectMeta{
Name: randName(fmt.Sprintf("%s-%s-to-%s-%s-", data.testNamespace, node1Pods[0], data.testNamespace, node1Pods[1])),
},
Spec: crdv1alpha1.PacketSamplingSpec{
Source: crdv1alpha1.Source{
Namespace: data.testNamespace,
Pod: node1Pods[0],
Pod: psBusyboxPodName,
},
Destination: crdv1alpha1.Destination{
Namespace: data.testNamespace,
Pod: node1Pods[1],
Pod: psNginxPodName,
},
Type: crdv1alpha1.FirstNSampling,
FirstNSamplingConfig: &crdv1alpha1.FirstNSamplingConfig{
Expand All @@ -139,7 +146,12 @@ func testPacketSamplingIntraNode(t *testing.T, data *TestData) {
},
Packet: crdv1alpha1.Packet{
IPHeader: crdv1alpha1.IPHeader{
Protocol: protocolICMP,
Protocol: protocolTCP,
},
TransportHeader: crdv1alpha1.TransportHeader{
TCP: &crdv1alpha1.TCPHeader{
DstPort: 80,
},
},
},
},
Expand Down Expand Up @@ -201,9 +213,20 @@ func runPacketSamplingTest(t *testing.T, data *TestData, tc psTestCase) {
// Give a little time for Nodes to install OVS flows.
time.Sleep(time.Second * 2)
// Send an ICMP echo packet from the source Pod to the destination.
if err := data.RunPingCommandFromTestPod(PodInfo{srcPod, osString, "", ""},
data.testNamespace, dstPodIPs, agnhostContainerName, 10, 0, false); err != nil {
t.Logf("Ping '%s' -> '%v' failed: ERROR (%v)", srcPod, *dstPodIPs, err)
if tc.ps.Spec.Packet.IPHeader.Protocol == protocolICMP {
if err := data.RunPingCommandFromTestPod(PodInfo{srcPod, osString, "", ""},
data.testNamespace, dstPodIPs, agnhostContainerName, 10, 0, false); err != nil {
t.Logf("Ping '%s' -> '%v' failed: ERROR (%v)", srcPod, *dstPodIPs, err)
}
} else if tc.ps.Spec.Packet.IPHeader.Protocol == protocolTCP {
server := dstPodIPs.IPv4.String()
if tc.ipVersion == 6 {
server = dstPodIPs.IPv6.String()
}
url := fmt.Sprintf("%s:%v", server, tc.ps.Spec.Packet.TransportHeader.TCP.DstPort)
if _, _, err := data.runWgetCommandOnBusyboxWithRetry(tc.srcPod, data.testNamespace, url, 3); err != nil {
t.Logf("wget '%s' -> '%v' failed: ERROR (%v)", srcPod, url, err)
}
}

ps, err := data.waitForPacketSampling(t, tc.ps.Name, tc.expectedPhase)
Expand Down

0 comments on commit b45505d

Please sign in to comment.