@@ -897,6 +897,97 @@ func TestNodeAddressesWithAddressSortOrderOptions(t *testing.T) {
897897}
898898}
899899
900+ func TestNodeAddressesWithExcludeNetworkName (t * testing.T ) {
901+ srv := servers.Server {
902+ Status : "ACTIVE" ,
903+ HostID : "29d3c8c896a45aa4c34e52247875d7fefc3d94bbcc9f622b5d204362" ,
904+ AccessIPv4 : "50.56.176.99" ,
905+ AccessIPv6 : "2001:4800:790e:510:be76:4eff:fe04:82a8" ,
906+ Addresses : map [string ]interface {}{
907+ "private" : []interface {}{
908+ map [string ]interface {}{
909+ "OS-EXT-IPS-MAC:mac_addr" : "fa:16:3e:7c:1b:2b" ,
910+ "version" : float64 (4 ),
911+ "addr" : "10.0.0.32" ,
912+ "OS-EXT-IPS:type" : "fixed" ,
913+ },
914+ map [string ]interface {}{
915+ "version" : float64 (4 ),
916+ "addr" : "50.56.176.36" ,
917+ "OS-EXT-IPS:type" : "floating" ,
918+ },
919+ map [string ]interface {}{
920+ "version" : float64 (4 ),
921+ "addr" : "10.0.0.31" ,
922+ // No OS-EXT-IPS:type
923+ },
924+ },
925+ "public" : []interface {}{
926+ map [string ]interface {}{
927+ "version" : float64 (4 ),
928+ "addr" : "50.56.176.35" ,
929+ },
930+ map [string ]interface {}{
931+ "version" : float64 (6 ),
932+ "addr" : "2001:4800:780e:510:be76:4eff:fe04:84a8" ,
933+ },
934+ },
935+ "excluded-network" : []interface {}{
936+ map [string ]interface {}{
937+ "version" : float64 (4 ),
938+ "addr" : "192.168.1.100" ,
939+ },
940+ },
941+ },
942+ Metadata : map [string ]string {
943+ "name" : "a1-yinvcez57-0-bvynoyawrhcg-kube-minion-fg5i4jwcc2yy" ,
944+ TypeHostName : "a1-yinvcez57-0-bvynoyawrhcg-kube-minion-fg5i4jwcc2yy.novalocal" ,
945+ },
946+ }
947+
948+ networkingOpts := NetworkingOpts {
949+ PublicNetworkName : []string {"public" },
950+ ExcludeNetworkName : []string {"excluded-network" },
951+ }
952+
953+ ports := []PortWithTrunkDetails {{
954+ Port : neutronports.Port {
955+ Status : "ACTIVE" ,
956+ FixedIPs : []neutronports.IP {
957+ {
958+ IPAddress : "10.0.0.32" ,
959+ },
960+ {
961+ IPAddress : "10.0.0.31" ,
962+ },
963+ },
964+ },
965+ },
966+ }
967+
968+ addrs , err := nodeAddresses (context .TODO (), & srv , ports , nil , networkingOpts )
969+ if err != nil {
970+ t .Fatalf ("nodeAddresses returned error: %v" , err )
971+ }
972+
973+ t .Logf ("addresses are %v" , addrs )
974+
975+ want := []v1.NodeAddress {
976+ {Type : v1 .NodeInternalIP , Address : "10.0.0.32" },
977+ {Type : v1 .NodeInternalIP , Address : "10.0.0.31" },
978+ {Type : v1 .NodeExternalIP , Address : "50.56.176.99" },
979+ {Type : v1 .NodeExternalIP , Address : "2001:4800:790e:510:be76:4eff:fe04:82a8" },
980+ {Type : v1 .NodeHostName , Address : "a1-yinvcez57-0-bvynoyawrhcg-kube-minion-fg5i4jwcc2yy.novalocal" },
981+ {Type : v1 .NodeExternalIP , Address : "50.56.176.36" },
982+ {Type : v1 .NodeExternalIP , Address : "50.56.176.35" },
983+ {Type : v1 .NodeExternalIP , Address : "2001:4800:780e:510:be76:4eff:fe04:84a8" },
984+ }
985+
986+ if ! reflect .DeepEqual (want , addrs ) {
987+ t .Errorf ("nodeAddresses returned incorrect value, want %v" , want )
988+ }
989+ }
990+
900991func TestNewOpenStack (t * testing.T ) {
901992cfg := ConfigFromEnv ()
902993testConfigFromEnv (t , & cfg )
0 commit comments