Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Feb 2, 2024
1 parent bb4c7a0 commit ca42f2f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
8 changes: 7 additions & 1 deletion cnf-certification-test/networking/icmp/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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++
}
Expand Down
52 changes: 41 additions & 11 deletions cnf-certification-test/networking/icmp/icmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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")
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ca42f2f

Please sign in to comment.