github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/nsxt_edgegateway_bgp_neighbor_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_NsxEdgeBgpNeighbor(check *C) {
    11  	skipNoNsxtConfiguration(vcd, check)
    12  	skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeBgpNeighbor)
    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 switchEdgeGatewayDedication(edge, false) // Turn off Dedicated Tier 0 gateway
    26  
    27  	// Create a new BGP IP Neighbor
    28  	bgpNeighbor := &types.EdgeBgpNeighbor{
    29  		NeighborAddress:        "11.11.11.11",
    30  		RemoteASNumber:         "64123",
    31  		KeepAliveTimer:         80,
    32  		HoldDownTimer:          241,
    33  		NeighborPassword:       "iQuee-ph2phe",
    34  		AllowASIn:              true,
    35  		GracefulRestartMode:    "HELPER_ONLY",
    36  		IpAddressTypeFiltering: "DISABLED",
    37  	}
    38  
    39  	createdBgpNeighbor, err := edge.CreateBgpNeighbor(bgpNeighbor)
    40  	check.Assert(err, IsNil)
    41  	check.Assert(createdBgpNeighbor, NotNil)
    42  
    43  	// Get all BGP Neighbors
    44  	BgpNeighbors, err := edge.GetAllBgpNeighbors(nil)
    45  	check.Assert(err, IsNil)
    46  	check.Assert(BgpNeighbors, NotNil)
    47  	check.Assert(len(BgpNeighbors), Equals, 1)
    48  	check.Assert(BgpNeighbors[0].EdgeBgpNeighbor.NeighborAddress, Equals, bgpNeighbor.NeighborAddress)
    49  
    50  	// Get BGP Neighbor By Neighbor IP Address
    51  	bgpNeighborByIp, err := edge.GetBgpNeighborByIp(bgpNeighbor.NeighborAddress)
    52  	check.Assert(err, IsNil)
    53  	check.Assert(bgpNeighborByIp, NotNil)
    54  
    55  	// Get BGP Neighbor By Id
    56  	bgpNeighborById, err := edge.GetBgpNeighborById(createdBgpNeighbor.EdgeBgpNeighbor.ID)
    57  	check.Assert(err, IsNil)
    58  	check.Assert(bgpNeighborById, NotNil)
    59  
    60  	// Update BGP Neighbor
    61  	bgpNeighbor.NeighborAddress = "12.12.12.12"
    62  	bgpNeighbor.ID = BgpNeighbors[0].EdgeBgpNeighbor.ID
    63  
    64  	updatedBgpNeighbor, err := BgpNeighbors[0].Update(bgpNeighbor)
    65  	check.Assert(err, IsNil)
    66  	check.Assert(updatedBgpNeighbor, NotNil)
    67  
    68  	check.Assert(updatedBgpNeighbor.EdgeBgpNeighbor.ID, Equals, BgpNeighbors[0].EdgeBgpNeighbor.ID)
    69  
    70  	// Delete BGP Neighbor
    71  	err = BgpNeighbors[0].Delete()
    72  	check.Assert(err, IsNil)
    73  
    74  	// Try to get deleted BGP Neighbor once again and ensure it is not there
    75  	notFoundByIp, err := edge.GetBgpNeighborByIp(bgpNeighbor.NeighborAddress)
    76  	check.Assert(err, NotNil)
    77  	check.Assert(notFoundByIp, IsNil)
    78  
    79  	notFoundById, err := edge.GetBgpNeighborById(createdBgpNeighbor.EdgeBgpNeighbor.ID)
    80  	check.Assert(err, NotNil)
    81  	check.Assert(notFoundById, IsNil)
    82  
    83  }