Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
Signed-off-by: abarreiro <[email protected]>
  • Loading branch information
abarreiro committed Jan 9, 2025
2 parents 8bdfe21 + 3d77bc4 commit 8a9f090
Show file tree
Hide file tree
Showing 19 changed files with 1,063 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .changes/v3.0.0/717-features.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Added `ContentLibraryItem` and `types.ContentLibraryItem` structures to manage Content Library Items
with methods `ContentLibrary.CreateContentLibraryItem`, `ContentLibrary.GetAllContentLibraryItems`,
`ContentLibrary.GetContentLibraryItemByName`, `ContentLibrary.GetContentLibraryItemById`, `ContentLibraryItem.Update`,
`ContentLibraryItem.Delete`, `VCDClient.GetContentLibraryItemById` [GH-717, GH-724]
`ContentLibraryItem.Delete`, `VCDClient.GetContentLibraryItemById` [GH-717, GH-724, GH-733]
14 changes: 14 additions & 0 deletions .changes/v3.0.0/725-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* Added `TmProviderGateway` and `types.TmProviderGateway` structures and methods
`VCDClient.CreateTmProviderGateway`, `VCDClient.GetAllTmProviderGateways`,
`VCDClient.GetTmProviderGatewayByName`, `VCDClient.GetTmProviderGatewayById`,
`VCDClient.GetTmProviderGatewayByNameAndRegionId`, `TmProviderGateway.Update`,
`TmProviderGateway.Delete` to manage Provider Gateways [GH-725]
* Added `TmTier0Gateway` and `types.TmTier0Gateway` structures and methods
`VCDClient.GetAllTmTier0GatewaysWithContext`, `VCDClient.GetTmTier0GatewayWithContextByName` to
read Tier 0 Gateways that are available for TM consumption [GH-725]
* Added `TmIpSpaceAssociation` and `types.TmIpSpaceAssociation` structures and methods
`VCDClient.CreateTmIpSpaceAssociation`, `VCDClient.GetAllTmIpSpaceAssociations`,
`VCDClient.GetTmIpSpaceAssociationById`,
`VCDClient.GetAllTmIpSpaceAssociationsByProviderGatewayId`,
`VCDClient.GetAllTmIpSpaceAssociationsByIpSpaceId`, `TmIpSpaceAssociation.Delete` to manage IP
Space associations with Provider Gateways [GH-725]
5 changes: 5 additions & 0 deletions .changes/v3.0.0/730-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Added types `TmEdgeCluster` and `types.TmEdgeCluster` for reading TM Edge Clusters and managing
their QoS settings `VCDClient.GetAllTmEdgeClusters`, `VCDClient.GetTmEdgeClusterByName`,
`VCDClient.GetTmEdgeClusterByNameAndRegionId`, `VCDClient.GetTmEdgeClusterById`,
`VCDClient.TmSyncEdgeClusters`, `TmEdgeCluster.Update`, `TmEdgeCluster.Delete`,
`TmEdgeCluster.GetTransportNodeStatus` [GH-730]
59 changes: 59 additions & 0 deletions govcd/api_vcd_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//go:build api || openapi || functional || catalog || vapp || gateway || network || org || query || extnetwork || task || vm || vdc || system || disk || lb || lbAppRule || lbAppProfile || lbServerPool || lbServiceMonitor || lbVirtualServer || user || search || nsxv || nsxt || auth || affinity || role || alb || certificate || vdcGroup || metadata || providervdc || rde || vsphere || uiPlugin || cse || slz || ALL

/*
* Copyright 2025 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/
package govcd

import (
"fmt"
"net/http"

"github.com/vmware/go-vcloud-director/v3/types/v56"
"github.com/vmware/go-vcloud-director/v3/util"

. "gopkg.in/check.v1"
)

// Test_NewRequestWitNotEncodedParamsWithApiVersion verifies that api version override works
func (vcd *TestVCD) Test_NewRequestWitNotEncodedParamsWithApiVersion(check *C) {
fmt.Printf("Running: %s\n", check.TestName())
queryUlr := vcd.client.Client.VCDHREF
queryUlr.Path += "/query"

apiVersion, err := vcd.client.Client.MaxSupportedVersion()
check.Assert(err, IsNil)

req := vcd.client.Client.NewRequestWitNotEncodedParamsWithApiVersion(nil, map[string]string{"type": "media",
"filter": "name==any"}, http.MethodGet, queryUlr, nil, apiVersion)

check.Assert(req.Header.Get("User-Agent"), Equals, vcd.client.Client.UserAgent)

resp, err := checkResp(vcd.client.Client.Http.Do(req))
check.Assert(err, IsNil)

check.Assert(resp.Header.Get("Content-Type"), Equals, types.MimeQueryRecords+";version="+apiVersion)

bodyBytes, err := rewrapRespBodyNoopCloser(resp)
check.Assert(err, IsNil)

util.ProcessResponseOutput(util.FuncNameCallStack(), resp, string(bodyBytes))
debugShowResponse(resp, bodyBytes)

// Repeats the call without API version change
req = vcd.client.Client.NewRequestWitNotEncodedParams(nil, map[string]string{"type": "media",
"filter": "name==any"}, http.MethodGet, queryUlr, nil)

resp, err = checkResp(vcd.client.Client.Http.Do(req))
check.Assert(err, IsNil)

// Checks that the regularAPI version was not affected by the previous call
check.Assert(resp.Header.Get("Content-Type"), Equals, types.MimeQueryRecords+";version="+vcd.client.Client.APIVersion)

bodyBytes, err = rewrapRespBodyNoopCloser(resp)
check.Assert(err, IsNil)
util.ProcessResponseOutput(util.FuncNameCallStack(), resp, string(bodyBytes))
debugShowResponse(resp, bodyBytes)

fmt.Printf("Test: %s run with api Version: %s\n", check.TestName(), apiVersion)
}
46 changes: 2 additions & 44 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/json"
"flag"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -160,6 +159,8 @@ type TestConfig struct {
NsxtManagerUsername string `yaml:"nsxtManagerUsername"`
NsxtManagerPassword string `yaml:"nsxtManagerPassword"`
NsxtManagerUrl string `yaml:"nsxtManagerUrl"`
NsxtEdgeCluster string `yaml:"nsxtEdgeCluster"`
NsxtTier0Gateway string `yaml:"nsxtTier0Gateway"`
} `yaml:"tm,omitempty"`
VCD struct {
Org string `yaml:"org"`
Expand Down Expand Up @@ -1977,49 +1978,6 @@ func (vcd *TestVCD) findFirstVapp() VApp {
return *vapp
}

// Test_NewRequestWitNotEncodedParamsWithApiVersion verifies that api version override works
func (vcd *TestVCD) Test_NewRequestWitNotEncodedParamsWithApiVersion(check *C) {
fmt.Printf("Running: %s\n", check.TestName())
queryUlr := vcd.client.Client.VCDHREF
queryUlr.Path += "/query"

apiVersion, err := vcd.client.Client.MaxSupportedVersion()
check.Assert(err, IsNil)

req := vcd.client.Client.NewRequestWitNotEncodedParamsWithApiVersion(nil, map[string]string{"type": "media",
"filter": "name==any"}, http.MethodGet, queryUlr, nil, apiVersion)

check.Assert(req.Header.Get("User-Agent"), Equals, vcd.client.Client.UserAgent)

resp, err := checkResp(vcd.client.Client.Http.Do(req))
check.Assert(err, IsNil)

check.Assert(resp.Header.Get("Content-Type"), Equals, types.MimeQueryRecords+";version="+apiVersion)

bodyBytes, err := rewrapRespBodyNoopCloser(resp)
check.Assert(err, IsNil)

util.ProcessResponseOutput(util.FuncNameCallStack(), resp, string(bodyBytes))
debugShowResponse(resp, bodyBytes)

// Repeats the call without API version change
req = vcd.client.Client.NewRequestWitNotEncodedParams(nil, map[string]string{"type": "media",
"filter": "name==any"}, http.MethodGet, queryUlr, nil)

resp, err = checkResp(vcd.client.Client.Http.Do(req))
check.Assert(err, IsNil)

// Checks that the regularAPI version was not affected by the previous call
check.Assert(resp.Header.Get("Content-Type"), Equals, types.MimeQueryRecords+";version="+vcd.client.Client.APIVersion)

bodyBytes, err = rewrapRespBodyNoopCloser(resp)
check.Assert(err, IsNil)
util.ProcessResponseOutput(util.FuncNameCallStack(), resp, string(bodyBytes))
debugShowResponse(resp, bodyBytes)

fmt.Printf("Test: %s run with api Version: %s\n", check.TestName(), apiVersion)
}

// setBoolFlag binds a flag to a boolean variable (passed as pointer)
// it also uses an optional environment variable that, if set, will
// update the variable before binding it to the flag.
Expand Down
32 changes: 20 additions & 12 deletions govcd/openapi_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,23 @@ var endpointMinApiVersions = map[string]string{
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtTier0RouterInterfaces: "38.0",

// VCF
types.OpenApiPathVcf + types.OpenApiEndpointRegionStoragePolicies: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointStorageClasses: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraries: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraryItems: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraryItemFiles: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointNsxManagers: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointRegions: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointSupervisors: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointSupervisorZones: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointZones: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmIpSpaces: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointRegionStoragePolicies: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointStorageClasses: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraries: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraryItems: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointContentLibraryItemFiles: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointNsxManagers: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointRegions: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointSupervisors: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointSupervisorZones: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointZones: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmIpSpaces: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmProviderGateways: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmIpSpaceAssociations: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmEdgeClusters: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmEdgeClusterTransportNodeStatus: "40.0",
types.OpenApiPathVcf + types.OpenApiEndpointTmEdgeClustersSync: "40.0",
}

// endpointElevatedApiVersions endpoint elevated API versions
Expand Down Expand Up @@ -258,6 +263,9 @@ var endpointElevatedApiVersions = map[string][]string{
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs: {
"40.0", // TM Orgs
},
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointImportableTier0Routers: {
"40.0", // TM Tier 0 Gateways
},
}

// checkOpenApiEndpointCompatibility checks if VCD version (to which the client is connected) is sufficient to work with
Expand Down
1 change: 1 addition & 0 deletions govcd/sample_govcd_test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,4 @@ tm:
nsxtManagerUsername: username for NSX-T Manager
nsxtManagerPassword: password for NSX-T Manager
nsxtManagerUrl: https://HOST
nsxtTier0Gateway: tier0gateway
36 changes: 36 additions & 0 deletions govcd/tm_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package govcd

import (
"fmt"
"net/url"
"time"

Expand Down Expand Up @@ -223,6 +224,7 @@ func createOrg(vcd *TestVCD, check *C, canManageOrgs bool) (*TmOrg, func()) {
Name: check.TestName(),
DisplayName: check.TestName(),
CanManageOrgs: canManageOrgs,
IsEnabled: true,
}
tmOrg, err := vcd.client.CreateTmOrg(cfg)
check.Assert(err, IsNil)
Expand All @@ -231,7 +233,41 @@ func createOrg(vcd *TestVCD, check *C, canManageOrgs bool) (*TmOrg, func()) {
PrependToCleanupListOpenApi(tmOrg.TmOrg.ID, check.TestName(), types.OpenApiPathVersion1_0_0+types.OpenApiEndpointOrgs+tmOrg.TmOrg.ID)

return tmOrg, func() {
if tmOrg.TmOrg.IsEnabled {
err = tmOrg.Disable()
check.Assert(err, IsNil)
}
err = tmOrg.Delete()
check.Assert(err, IsNil)
}
}

func createTmIpSpace(vcd *TestVCD, region *Region, check *C, nameSuffix, octet3 string) (*TmIpSpace, func()) {
ipSpaceType := &types.TmIpSpace{
Name: check.TestName() + "-" + nameSuffix,
RegionRef: types.OpenApiReference{ID: region.Region.ID},
Description: check.TestName(),
DefaultQuota: types.TmIpSpaceDefaultQuota{
MaxCidrCount: 3,
MaxIPCount: -1,
MaxSubnetSize: 24,
},
ExternalScopeCidr: fmt.Sprintf("12.12.%s.0/30", octet3),
InternalScopeCidrBlocks: []types.TmIpSpaceInternalScopeCidrBlocks{
{
Cidr: fmt.Sprintf("10.0.%s.0/24", octet3),
},
},
}

ipSpace, err := vcd.client.CreateTmIpSpace(ipSpaceType)
check.Assert(err, IsNil)
check.Assert(ipSpace, NotNil)
AddToCleanupListOpenApi(ipSpace.TmIpSpace.ID, check.TestName(), types.OpenApiPathVcf+types.OpenApiEndpointTmIpSpaces+ipSpace.TmIpSpace.ID)

return ipSpace, func() {
printVerbose("# Deleting IP Space %s\n", ipSpace.TmIpSpace.Name)
err = ipSpace.Delete()
check.Assert(err, IsNil)
}
}
9 changes: 2 additions & 7 deletions govcd/tm_content_library_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package govcd
import (
"github.com/vmware/go-vcloud-director/v3/types/v56"
. "gopkg.in/check.v1"
"strings"
)

// TODO: TM: Test upload failures:
Expand Down Expand Up @@ -86,14 +85,10 @@ func (vcd *TestVCD) Test_ContentLibraryItemOva(check *C) {
check.Assert(ContainsNotFound(err), Equals, true)

_, err = cl.GetContentLibraryItemById("urn:vcloud:contentLibraryItem:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
// TODO: TM: Should return ENF, but throws a 500. The API will eventually be fixed
check.Assert(strings.Contains(err.Error(), "INTERNAL_SERVER_ERROR"), Equals, true)
// check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(ContainsNotFound(err), Equals, true)

_, err = vcd.client.GetContentLibraryItemById("urn:vcloud:contentLibraryItem:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
// TODO: TM: Should return ENF, but throws a 500. The API will eventually be fixed
check.Assert(strings.Contains(err.Error(), "INTERNAL_SERVER_ERROR"), Equals, true)
// check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(ContainsNotFound(err), Equals, true)
}

// Test_ContentLibraryItemIso tests CRUD operations for a Content Library Item when uploading an ISO file
Expand Down
11 changes: 4 additions & 7 deletions govcd/tm_content_library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
package govcd

import (
"strings"

"github.com/vmware/go-vcloud-director/v3/types/v56"
. "gopkg.in/check.v1"
"strings"
)

// TODO: TM: Tests missing: Tenant, subscribed catalog, shared catalog
Expand Down Expand Up @@ -99,12 +100,8 @@ func (vcd *TestVCD) Test_ContentLibraryProvider(check *C) {

_, err = vcd.client.GetContentLibraryById("urn:vcloud:contentLibrary:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
check.Assert(err, NotNil)
// TODO: TM: Should return ENF, but throws a 500. The API will eventually be fixed
check.Assert(strings.Contains(err.Error(), "INTERNAL_SERVER_ERROR"), Equals, true)
// check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(ContainsNotFound(err), Equals, true)

_, err = vcd.client.GetContentLibraryById("urn:vcloud:contentLibrary:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
// TODO: TM: Should return ENF, but throws a 500. The API will eventually be fixed
check.Assert(strings.Contains(err.Error(), "INTERNAL_SERVER_ERROR"), Equals, true)
// check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(ContainsNotFound(err), Equals, true)
}
Loading

0 comments on commit 8a9f090

Please sign in to comment.