Skip to content

Commit bf8ea06

Browse files
committed
add windows swiftv2 infra with delegated ep info test
1 parent d909633 commit bf8ea06

File tree

1 file changed

+148
-4
lines changed

1 file changed

+148
-4
lines changed

cni/network/network_windows_test.go

Lines changed: 148 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,7 @@ func TestPluginMultitenancyWindowsDelete(t *testing.T) {
859859
}
860860

861861
// windows swiftv2 example
862-
func GetTestCNSResponseSecondary() map[string]network.InterfaceInfo {
863-
macAddress := "60:45:bd76:f6:44"
862+
func GetTestCNSResponseSecondaryWindows(macAddress string) map[string]network.InterfaceInfo {
864863
parsedMAC, _ := net.ParseMAC(macAddress)
865864
return map[string]network.InterfaceInfo{
866865
string(cns.InfraNIC): {
@@ -872,20 +871,29 @@ func GetTestCNSResponseSecondary() map[string]network.InterfaceInfo {
872871
},
873872
Routes: []network.RouteInfo{
874873
{
875-
Gw: net.ParseIP("10.244.2.1"),
874+
Dst: *getCIDRNotationForAddress("1.1.1.1/24"),
875+
Gw: net.ParseIP("10.244.2.1"),
876876
},
877877
},
878878
SkipDefaultRoutes: true,
879879
NICType: cns.InfraNIC,
880+
HostSubnetPrefix: *getCIDRNotationForAddress("20.224.0.0/16"),
880881
},
881-
"60:45:bd76:f6:44": {
882+
macAddress: {
882883
MacAddress: parsedMAC,
883884
IPConfigs: []*network.IPConfig{
884885
{
885886
Address: *getCIDRNotationForAddress("10.241.0.21/16"),
886887
Gateway: net.ParseIP("10.241.0.1"),
887888
},
888889
},
890+
Routes: []network.RouteInfo{
891+
{
892+
// just to ensure we don't overwrite if we had more routes
893+
Dst: *getCIDRNotationForAddress("2.2.2.2/24"),
894+
Gw: net.ParseIP("99.244.2.1"),
895+
},
896+
},
889897
NICType: cns.NodeNetworkInterfaceFrontendNIC,
890898
},
891899
}
@@ -901,6 +909,15 @@ func TestPluginWindowsAdd(t *testing.T) {
901909
EnableExactMatchForPodName: true,
902910
Master: "eth0",
903911
}
912+
nwCfg := cni.NetworkConfig{
913+
CNIVersion: "0.3.0",
914+
Name: "net",
915+
MultiTenancy: false,
916+
EnableExactMatchForPodName: true,
917+
}
918+
macAddress := "60:45:bd:76:f6:44"
919+
parsedMACAddress, _ := net.ParseMAC(macAddress)
920+
904921
type endpointEntry struct {
905922
epInfo *network.EndpointInfo
906923
epIDRegex string
@@ -1035,6 +1052,133 @@ func TestPluginWindowsAdd(t *testing.T) {
10351052
},
10361053
},
10371054
},
1055+
{
1056+
// Based on a live swiftv2 windows cluster's (infra + delegated) cns invoker response
1057+
name: "Add Happy Path Swiftv2",
1058+
plugin: &NetPlugin{
1059+
Plugin: resources.Plugin,
1060+
nm: network.NewMockNetworkmanager(network.NewMockEndpointClient(nil)),
1061+
tb: &telemetry.TelemetryBuffer{},
1062+
report: &telemetry.CNIReport{},
1063+
ipamInvoker: NewCustomMockIpamInvoker(GetTestCNSResponseSecondaryWindows(macAddress)),
1064+
netClient: &InterfaceGetterMock{
1065+
// used in secondary find master interface
1066+
interfaces: []net.Interface{
1067+
{
1068+
Name: "secondary",
1069+
HardwareAddr: parsedMACAddress,
1070+
},
1071+
{
1072+
Name: "primary",
1073+
HardwareAddr: net.HardwareAddr{},
1074+
},
1075+
},
1076+
// used in primary find master interface
1077+
interfaceAddrs: map[string][]net.Addr{
1078+
"primary": {
1079+
// match with the host subnet prefix to know that this ip belongs to the host
1080+
getCIDRNotationForAddress("20.224.0.0/16"),
1081+
},
1082+
},
1083+
},
1084+
},
1085+
args: &cniSkel.CmdArgs{
1086+
StdinData: nwCfg.Serialize(),
1087+
ContainerID: "test-container",
1088+
Netns: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
1089+
Args: fmt.Sprintf("K8S_POD_NAME=%v;K8S_POD_NAMESPACE=%v", "test-pod", "test-pod-ns"),
1090+
IfName: eth0IfName,
1091+
},
1092+
match: func(ei1, ei2 *network.EndpointInfo) bool {
1093+
return ei1.NICType == ei2.NICType
1094+
},
1095+
want: []endpointEntry{
1096+
// should match infra
1097+
{
1098+
epInfo: &network.EndpointInfo{
1099+
ContainerID: "test-container",
1100+
Data: map[string]interface{}{},
1101+
Routes: []network.RouteInfo{
1102+
{
1103+
Dst: *getCIDRNotationForAddress("1.1.1.1/24"),
1104+
Gw: net.ParseIP("10.244.2.1"),
1105+
},
1106+
},
1107+
PODName: "test-pod",
1108+
PODNameSpace: "test-pod-ns",
1109+
NICType: cns.InfraNIC,
1110+
SkipDefaultRoutes: true,
1111+
MasterIfName: "primary",
1112+
NetworkID: "net",
1113+
NetNsPath: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
1114+
NetNs: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
1115+
HostSubnetPrefix: "20.224.0.0/16",
1116+
Options: map[string]interface{}{},
1117+
// matches with cns ip configuration
1118+
IPAddresses: []net.IPNet{
1119+
{
1120+
IP: net.ParseIP("10.244.2.107"),
1121+
Mask: getIPNetWithString("10.244.2.107/16").Mask,
1122+
},
1123+
},
1124+
NATInfo: nil,
1125+
// ip config pod ip + mask(s) from cns > interface info > subnet info
1126+
Subnets: []network.SubnetInfo{
1127+
{
1128+
Family: platform.AfINET,
1129+
Prefix: *getIPNetWithString("10.244.0.0/16"),
1130+
// matches cns ip configuration gateway ip address
1131+
Gateway: net.ParseIP("10.244.2.1"),
1132+
},
1133+
},
1134+
},
1135+
epIDRegex: `.*`,
1136+
},
1137+
// should match secondary
1138+
{
1139+
epInfo: &network.EndpointInfo{
1140+
MacAddress: parsedMACAddress,
1141+
ContainerID: "test-container",
1142+
Data: map[string]interface{}{},
1143+
Routes: []network.RouteInfo{
1144+
{
1145+
// just to ensure we don't overwrite if we had more routes
1146+
Dst: *getCIDRNotationForAddress("2.2.2.2/24"),
1147+
Gw: net.ParseIP("99.244.2.1"),
1148+
},
1149+
},
1150+
PODName: "test-pod",
1151+
PODNameSpace: "test-pod-ns",
1152+
NICType: cns.NodeNetworkInterfaceFrontendNIC,
1153+
SkipDefaultRoutes: false,
1154+
MasterIfName: "secondary",
1155+
NetworkID: "azure-" + macAddress,
1156+
NetNsPath: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
1157+
NetNs: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
1158+
HostSubnetPrefix: "<nil>",
1159+
Options: map[string]interface{}{},
1160+
// matches with cns ip configuration
1161+
IPAddresses: []net.IPNet{
1162+
{
1163+
IP: net.ParseIP("10.241.0.21"),
1164+
Mask: getIPNetWithString("10.241.0.21/16").Mask,
1165+
},
1166+
},
1167+
NATInfo: nil,
1168+
// ip config pod ip + mask(s) from cns > interface info > subnet info
1169+
Subnets: []network.SubnetInfo{
1170+
{
1171+
Family: platform.AfINET,
1172+
Prefix: *getIPNetWithString("10.241.0.21/16"),
1173+
// matches cns ip configuration gateway ip address
1174+
Gateway: net.ParseIP("10.241.0.1"),
1175+
},
1176+
},
1177+
},
1178+
epIDRegex: `.*`,
1179+
},
1180+
},
1181+
},
10381182
}
10391183

10401184
for _, tt := range tests {

0 commit comments

Comments
 (0)