github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/nsxt_edgegateway_bgp_configuration_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_NsxEdgeBgpConfiguration(check *C) { 11 skipNoNsxtConfiguration(vcd, check) 12 skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeBgpConfig) 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 // Get and store existing BGP configuration 28 bgpConfig, err := edge.GetBgpConfiguration() 29 check.Assert(err, IsNil) 30 check.Assert(bgpConfig, NotNil) 31 32 // Disable BGP 33 err = edge.DisableBgpConfiguration() 34 check.Assert(err, IsNil) 35 36 newBgpConfig := &types.EdgeBgpConfig{ 37 Enabled: true, 38 Ecmp: true, 39 LocalASNumber: "65420", 40 GracefulRestart: &types.EdgeBgpGracefulRestartConfig{ 41 StaleRouteTimer: 190, 42 RestartTimer: 600, 43 Mode: "HELPER_ONLY", 44 }, 45 } 46 47 updatedBgpConfig, err := edge.UpdateBgpConfiguration(newBgpConfig) 48 check.Assert(err, IsNil) 49 check.Assert(updatedBgpConfig, NotNil) 50 51 newBgpConfig.Version = updatedBgpConfig.Version // Version is constantly iterated and cant be checked 52 check.Assert(updatedBgpConfig, DeepEquals, newBgpConfig) 53 54 // Check "disable" function which keeps all fields the same, but sets "Enabled: false" 55 err = edge.DisableBgpConfiguration() 56 check.Assert(err, IsNil) 57 58 bgpConfigAfterDisabling, err := edge.GetBgpConfiguration() 59 check.Assert(err, IsNil) 60 check.Assert(bgpConfig, NotNil) 61 check.Assert(bgpConfigAfterDisabling.Enabled, Equals, false) 62 63 } 64 65 func switchEdgeGatewayDedication(edge *NsxtEdgeGateway, isDedicated bool) error { 66 edge.EdgeGateway.EdgeGatewayUplinks[0].Dedicated = isDedicated 67 _, err := edge.Update(edge.EdgeGateway) 68 69 return err 70 }