1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// +build linux
package main
import (
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types/current"
"ovn4nfv-k8s-plugin/cmd/ovn4nfvk8s-cni/app"
"testing"
)
func TestAddMultipleInterfaces(t *testing.T) {
oldConfigureInterface := app.ConfigureInterface
// as we are exiting, revert ConfigureInterface back at end of function
defer func() { app.ConfigureInterface = oldConfigureInterface }()
app.ConfigureInterface = func(args *skel.CmdArgs, namespace, podName, macAddress, ipAddress, gatewayIP, interfaceName, defaultGateway string, mtu int) ([]*current.Interface, error) {
return []*current.Interface{
{
Name: "pod",
Mac: "0a:00:00:00:00:0c",
Sandbox: "102103104",
}}, nil
}
args := &skel.CmdArgs{"102103104", "default", "eth0", "", "", nil}
ovnAnnotation := "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"interface\":\"net0\"}] "
result := addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result == nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
ovnAnnotation = "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"defaultGateway\":\"true\",\"interface\":\"net0\"}] "
result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result == nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
ovnAnnotation = "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\"}] "
result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result != nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
ovnAnnotation = "[{\"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"interface\":\"net0\"}] "
result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result != nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
ovnAnnotation = "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"interface\":\"net0\"}, {\"ip_address\":\"172.16.25.2/24\", \"mac_address\":\"0a:00:00:00:00:0d\", \"gateway_ip\": \"172.16.25.1\",\"interface\":\"net1\"}]"
result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result == nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
ovnAnnotation = "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"interface\":\"net0\", \"defaultGateway\":\"true\"}, {\"ip_address\":\"172.16.25.2/24\", \"mac_address\":\"0a:00:00:00:00:0d\", \"gateway_ip\": \"172.16.25.1\",\"interface\":\"net1\"}]"
result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod")
if result == nil {
t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation)
}
}
|