@@ -1066,7 +1066,7 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10661066 }
10671067
10681068 for i , tc := range tcs {
1069- cpicIPs := sets .New [ string ] (tc .cloudPrivateIPConfigs ... )
1069+ cpicIPs := sets .New (tc .cloudPrivateIPConfigs ... )
10701070 nodeEgressIPConfig , err := o .getNeutronPortNodeEgressIPConfiguration (tc .port , cpicIPs )
10711071 if err != nil {
10721072 if ! strings .Contains (err .Error (), tc .errString ) {
@@ -1081,6 +1081,87 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10811081 }
10821082}
10831083
1084+ func TestGetNeutronPortNodeEgressIPConfigurationMaxAllowedAddressPairs (t * testing.T ) {
1085+ th .SetupHTTP ()
1086+ defer th .TeardownHTTP ()
1087+ HandleSubnetList (t )
1088+ HandlePortListAndCreation (t )
1089+
1090+ tcs := []struct {
1091+ name string
1092+ maxAllowedAddrPairs int
1093+ port neutronports.Port
1094+ nodeEgressIPConfig NodeEgressIPConfiguration
1095+ cloudPrivateIPConfigs []string
1096+ errString string
1097+ }{
1098+ {
1099+ name : "custom positive value overrides default" ,
1100+ maxAllowedAddrPairs : 20 ,
1101+ port : portMap ["9ab428d4-58f8-42d7-9672-90c3f5641f83" ],
1102+ nodeEgressIPConfig : NodeEgressIPConfiguration {
1103+ Interface : "9ab428d4-58f8-42d7-9672-90c3f5641f83" ,
1104+ IFAddr : ifAddr {
1105+ IPv4 : "192.0.2.0/24" ,
1106+ IPv6 : "2000::/64" ,
1107+ },
1108+ Capacity : capacity {
1109+ IP : ptr .To (20 - 5 ), // 5 allowed_address_pairs on the port
1110+ },
1111+ },
1112+ },
1113+ {
1114+ name : "max too small for existing address pairs" ,
1115+ maxAllowedAddrPairs : 3 ,
1116+ port : portMap ["9ab428d4-58f8-42d7-9672-90c3f5641f83" ],
1117+ errString : "max allowed address pairs 3 is too small for port 9ab428d4-58f8-42d7-9672-90c3f5641f83 which already has 5 allowed address pairs and 0 managed by CNCC" ,
1118+ },
1119+ {
1120+ name : "unset flag uses default capacity" ,
1121+ maxAllowedAddrPairs : 0 ,
1122+ port : portMap ["9ab428d4-58f8-42d7-9672-90c3f5641f83" ],
1123+ nodeEgressIPConfig : NodeEgressIPConfiguration {
1124+ Interface : "9ab428d4-58f8-42d7-9672-90c3f5641f83" ,
1125+ IFAddr : ifAddr {
1126+ IPv4 : "192.0.2.0/24" ,
1127+ IPv6 : "2000::/64" ,
1128+ },
1129+ Capacity : capacity {
1130+ IP : ptr .To (defaultOpenstackMaxCapacity - 5 ),
1131+ },
1132+ },
1133+ },
1134+ }
1135+
1136+ for _ , tc := range tcs {
1137+ t .Run (tc .name , func (t * testing.T ) {
1138+ o := OpenStack {
1139+ CloudProvider : CloudProvider {
1140+ cfg : CloudProviderConfig {
1141+ OSMaxAllowedAddressPairs : tc .maxAllowedAddrPairs ,
1142+ },
1143+ },
1144+ novaClient : testclient .ServiceClient (),
1145+ neutronClient : testclient .ServiceClient (),
1146+ }
1147+ cpicIPs := sets .New (tc .cloudPrivateIPConfigs ... )
1148+ nodeEgressIPConfig , err := o .getNeutronPortNodeEgressIPConfiguration (tc .port , cpicIPs )
1149+ if err != nil {
1150+ if tc .errString == "" || ! strings .Contains (err .Error (), tc .errString ) {
1151+ t .Fatalf ("Received unexpected error, err: %q, expected to contain: %q" , err , tc .errString )
1152+ }
1153+ return
1154+ }
1155+ if tc .errString != "" {
1156+ t .Fatalf ("Expected error containing %q but got none" , tc .errString )
1157+ }
1158+ if ! reflect .DeepEqual (* nodeEgressIPConfig , tc .nodeEgressIPConfig ) {
1159+ t .Fatalf ("Received unexpected nodeEgressIPConfig.\n Expected: %v\n Got: %v" , tc .nodeEgressIPConfig , nodeEgressIPConfig )
1160+ }
1161+ })
1162+ }
1163+ }
1164+
10841165// TestAllowUnAllowIPAddressOnNeutronPort tests both allowIPAddressOnNeutronPort and
10851166// unAllowIPAddressOnNeutronPort.
10861167func TestAllowUnAllowIPAddressOnNeutronPort (t * testing.T ) {
0 commit comments