From 2a9c1fd149e5400bd7d4db93feeb94fd59d367a8 Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Thu, 1 Feb 2024 12:19:09 -0600 Subject: [PATCH] Fix unit tests --- .../networking/icmp/icmp.go | 8 ++- .../networking/icmp/icmp_test.go | 52 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/cnf-certification-test/networking/icmp/icmp.go b/cnf-certification-test/networking/icmp/icmp.go index 299d54db6e..e477034a21 100644 --- a/cnf-certification-test/networking/icmp/icmp.go +++ b/cnf-certification-test/networking/icmp/icmp.go @@ -63,7 +63,10 @@ func BuildNetTestContext(pods []*provider.Pod, aIPVersion netcommons.IPVersion, } for netKey, multusNetworkInterface := range put.MultusNetworkInterfaces { // The first container is used to get the network namespace - processContainerIpsPerNet(put.Containers[0], netKey, multusNetworkInterface[0].IPs, multusNetworkInterface[0].Interface, netsUnderTest, aIPVersion, logger) + // Loop through all the network interfaces and their IPs + for _, networkInterface := range multusNetworkInterface { + processContainerIpsPerNet(put.Containers[0], netKey, networkInterface.IPs, networkInterface.Interface, netsUnderTest, aIPVersion, logger) + } } continue } @@ -104,6 +107,9 @@ func processContainerIpsPerNet(containerID *provider.Container, entry.TesterSource.ContainerIdentifier = containerID // if multiple interfaces are present for this network on this container/pod, pick the first one as the tester source ip entry.TesterSource.IP = ipAddressesFiltered[firstIPIndex] + if ifName != "" { + entry.TesterSource.InterfaceName = ifName + } // do no include tester's IP in the list of destination IPs to ping firstIPIndex++ } diff --git a/cnf-certification-test/networking/icmp/icmp_test.go b/cnf-certification-test/networking/icmp/icmp_test.go index b2e7c0d6af..fb1e3c7485 100644 --- a/cnf-certification-test/networking/icmp/icmp_test.go +++ b/cnf-certification-test/networking/icmp/icmp_test.go @@ -408,7 +408,8 @@ func TestBuildNetTestContext(t *testing.T) { wantNetsUnderTest: map[string]netcommons.NetTestContext{ "tnf/mynet-ipv4-0": { TesterSource: netcommons.ContainerIP{ - IP: "192.168.0.3", + IP: "192.168.0.3", + InterfaceName: "net1", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test1", @@ -422,7 +423,8 @@ func TestBuildNetTestContext(t *testing.T) { }, DestTargets: []netcommons.ContainerIP{ { - IP: "192.168.0.4", + IP: "192.168.0.4", + InterfaceName: "net1", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test2", @@ -439,7 +441,8 @@ func TestBuildNetTestContext(t *testing.T) { "tnf/mynet-ipv4-1": { TesterContainerNodeName: "", TesterSource: netcommons.ContainerIP{ - IP: "192.168.1.3", + IP: "192.168.1.3", + InterfaceName: "net2", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test1", @@ -453,7 +456,8 @@ func TestBuildNetTestContext(t *testing.T) { }, DestTargets: []netcommons.ContainerIP{ { - IP: "192.168.1.4", + IP: "192.168.1.4", + InterfaceName: "net2", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test2", @@ -478,7 +482,8 @@ func TestBuildNetTestContext(t *testing.T) { wantNetsUnderTest: map[string]netcommons.NetTestContext{ "tnf/mynet-ipv4-0": { TesterSource: netcommons.ContainerIP{ - IP: "192.168.0.3", + IP: "192.168.0.3", + InterfaceName: "net1", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test1", @@ -495,7 +500,8 @@ func TestBuildNetTestContext(t *testing.T) { "tnf/mynet-ipv4-1": { TesterContainerNodeName: "", TesterSource: netcommons.ContainerIP{ - IP: "192.168.1.3", + IP: "192.168.1.3", + InterfaceName: "net2", ContainerIdentifier: &provider.Container{ Container: &corev1.Container{ Name: "test1", @@ -519,9 +525,7 @@ func TestBuildNetTestContext(t *testing.T) { for idx := range tt.args.pods { tt.args.pods[idx].MultusNetworkInterfaces = make(map[string][]provider.CniNetworkInterface) var err error - tt.args.pods[idx].MultusNetworkInterfaces, err = provider.GetPodIPsPerNet( - tt.args.pods[idx].GetAnnotations()[provider.CniNetworksStatusKey], - ) + tt.args.pods[idx].MultusNetworkInterfaces, err = provider.GetPodIPsPerNet(tt.args.pods[idx].GetAnnotations()[provider.CniNetworksStatusKey]) if err != nil { fmt.Printf("Could not decode networks-status annotation") } @@ -569,7 +573,20 @@ var ( }, }, MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{ - "": {}, + "tnf/mynet-ipv4-0": { + { + Interface: "net1", + Name: "mynet-ipv4-0", + IPs: []string{"192.168.0.3"}, + }, + }, + "tnf/mynet-ipv4-1": { + { + Interface: "net2", + Name: "mynet-ipv4-1", + IPs: []string{"192.168.1.3"}, + }, + }, }, SkipNetTests: false, SkipMultusNetTests: false, @@ -607,7 +624,20 @@ var ( }, }, MultusNetworkInterfaces: map[string][]provider.CniNetworkInterface{ - "": {}, + "tnf/mynet-ipv4-0": { + { + Interface: "net1", + Name: "mynet-ipv4-0", + IPs: []string{"192.168.0.4"}, + }, + }, + "tnf/mynet-ipv4-1": { + { + Interface: "net2", + Name: "mynet-ipv4-1", + IPs: []string{"192.168.1.4"}, + }, + }, }, SkipNetTests: false, SkipMultusNetTests: false,