github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/nsxt_edgegateway_static_route_test.go (about)

     1  //go:build network || nsxt || functional || openapi || ALL
     2  
     3  package govcd
     4  
     5  import (
     6  	"github.com/vmware/go-vcloud-director/v2/types/v56"
     7  	. "gopkg.in/check.v1"
     8  )
     9  
    10  func (vcd *TestVCD) Test_NsxEdgeStaticRoute(check *C) {
    11  	skipNoNsxtConfiguration(vcd, check)
    12  	skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeGatewayStaticRoutes)
    13  	vcd.skipIfNotSysAdmin(check)
    14  
    15  	org, err := vcd.client.GetOrgByName(vcd.config.VCD.Org)
    16  	check.Assert(err, IsNil)
    17  	nsxtVdc, err := org.GetVDCByName(vcd.config.VCD.Nsxt.Vdc, false)
    18  	check.Assert(err, IsNil)
    19  	edge, err := nsxtVdc.GetNsxtEdgeGatewayByName(vcd.config.VCD.Nsxt.EdgeGateway)
    20  	check.Assert(err, IsNil)
    21  
    22  	// Switch Edge Gateway to use dedicated uplink for the time of this test and then turn it off
    23  	err = switchEdgeGatewayDedication(edge, true) // Turn on Dedicated Tier 0 gateway
    24  	check.Assert(err, IsNil)
    25  	defer func() {
    26  		err = switchEdgeGatewayDedication(edge, false)
    27  		check.Assert(err, IsNil)
    28  	}()
    29  
    30  	// Get Org VDC routed network
    31  	orgVdcNet, err := nsxtVdc.GetOpenApiOrgVdcNetworkByName(vcd.config.VCD.Nsxt.RoutedNetwork)
    32  	check.Assert(err, IsNil)
    33  	check.Assert(orgVdcNet, NotNil)
    34  
    35  	staticRouteConfig := &types.NsxtEdgeGatewayStaticRoute{
    36  		Name:        check.TestName(),
    37  		Description: "description",
    38  		NetworkCidr: "1.1.1.0/24",
    39  		NextHops: []types.NsxtEdgeGatewayStaticRouteNextHops{
    40  			{
    41  				IPAddress:     orgVdcNet.OpenApiOrgVdcNetwork.Subnets.Values[0].Gateway,
    42  				AdminDistance: 4,
    43  				Scope: &types.NsxtEdgeGatewayStaticRouteNextHopScope{
    44  					ID:        orgVdcNet.OpenApiOrgVdcNetwork.ID,
    45  					ScopeType: "NETWORK",
    46  				},
    47  			},
    48  		},
    49  	}
    50  
    51  	staticRoute, err := edge.CreateStaticRoute(staticRouteConfig)
    52  	check.Assert(err, IsNil)
    53  	check.Assert(staticRoute, NotNil)
    54  
    55  	// Get all BGP IP Prefix Lists
    56  	staticRouteList, err := edge.GetAllStaticRoutes(nil)
    57  	check.Assert(err, IsNil)
    58  	check.Assert(staticRouteList, NotNil)
    59  	check.Assert(len(staticRouteList), Equals, 1)
    60  	check.Assert(staticRouteList[0].NsxtEdgeGatewayStaticRoute.Name, Equals, staticRoute.NsxtEdgeGatewayStaticRoute.Name)
    61  
    62  	// Get By Name
    63  	staticRouteByName, err := edge.GetStaticRouteByName(staticRoute.NsxtEdgeGatewayStaticRoute.Name)
    64  	check.Assert(err, IsNil)
    65  	check.Assert(staticRouteByName, NotNil)
    66  
    67  	// Get By Id
    68  	staticRouteById, err := edge.GetStaticRouteById(staticRoute.NsxtEdgeGatewayStaticRoute.ID)
    69  	check.Assert(err, IsNil)
    70  	check.Assert(staticRouteById, NotNil)
    71  
    72  	// Get By Network CIDR
    73  	staticRouteByNetworkCidr, err := edge.GetStaticRouteByNetworkCidr(staticRoute.NsxtEdgeGatewayStaticRoute.NetworkCidr)
    74  	check.Assert(err, IsNil)
    75  	check.Assert(staticRouteByNetworkCidr, NotNil)
    76  
    77  	// Update
    78  	staticRouteConfig.Name = check.TestName() + "-updated"
    79  	staticRouteConfig.Description = "test-description-updated"
    80  	staticRouteConfig.ID = staticRouteByNetworkCidr.NsxtEdgeGatewayStaticRoute.ID
    81  
    82  	// staticRoute
    83  	updatedStaticRoute, err := staticRoute.Update(staticRouteConfig)
    84  	check.Assert(err, IsNil)
    85  	check.Assert(updatedStaticRoute, NotNil)
    86  
    87  	check.Assert(updatedStaticRoute.NsxtEdgeGatewayStaticRoute.ID, Equals, staticRouteByName.NsxtEdgeGatewayStaticRoute.ID)
    88  
    89  	// Delete
    90  	err = staticRoute.Delete()
    91  	check.Assert(err, IsNil)
    92  
    93  	// Try to get once again and ensure it is not there
    94  	notFoundByName, err := edge.GetStaticRouteByName(staticRoute.NsxtEdgeGatewayStaticRoute.Name)
    95  	check.Assert(err, NotNil)
    96  	check.Assert(ContainsNotFound(err), Equals, true)
    97  	check.Assert(notFoundByName, IsNil)
    98  
    99  	notFoundById, err := edge.GetStaticRouteById(staticRoute.NsxtEdgeGatewayStaticRoute.ID)
   100  	check.Assert(err, NotNil)
   101  	check.Assert(ContainsNotFound(err), Equals, true)
   102  	check.Assert(notFoundById, IsNil)
   103  
   104  	notFoundByCidr, err := edge.GetStaticRouteByNetworkCidr(staticRoute.NsxtEdgeGatewayStaticRoute.NetworkCidr)
   105  	check.Assert(err, NotNil)
   106  	check.Assert(ContainsNotFound(err), Equals, true)
   107  	check.Assert(notFoundByCidr, IsNil)
   108  }