Skip to content

Commit

Permalink
Fix issue vmware#514 - ignoring pagination in network queries
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
  • Loading branch information
Giuseppe Maxia committed Nov 2, 2022
1 parent 103960d commit 6e2b501
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
8 changes: 4 additions & 4 deletions govcd/orgvdcnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func (vdc *Vdc) CreateOrgVDCNetwork(networkConfig *types.OrgVDCNetwork) (Task, e
// GetNetworkList returns a list of networks for the VDC
func (vdc *Vdc) GetNetworkList() ([]*types.QueryResultOrgVdcNetworkRecordType, error) {
// Find the list of networks with the wanted name
result, err := vdc.client.QueryWithNotEncodedParams(nil, map[string]string{
"type": "orgVdcNetwork",
result, err := vdc.client.cumulativeQuery(types.QtOrgVdcNetwork, nil, map[string]string{
"type": types.QtOrgVdcNetwork,
"filter": fmt.Sprintf("vdc==%s", url.QueryEscape(vdc.Vdc.ID)),
"filterEncoded": "true",
})
Expand All @@ -215,8 +215,8 @@ func (vdc *Vdc) GetNetworkList() ([]*types.QueryResultOrgVdcNetworkRecordType, e
func (vdc *Vdc) FindEdgeGatewayNameByNetwork(networkName string) (string, error) {

// Find the list of networks with the wanted name
result, err := vdc.client.QueryWithNotEncodedParams(nil, map[string]string{
"type": "orgVdcNetwork",
result, err := vdc.client.cumulativeQuery(types.QtOrgVdcNetwork, nil, map[string]string{
"type": types.QtOrgVdcNetwork,
"filter": fmt.Sprintf("name==%s;vdc==%s", url.QueryEscape(networkName), url.QueryEscape(vdc.Vdc.ID)),
"filterEncoded": "true",
})
Expand Down
79 changes: 79 additions & 0 deletions govcd/orgvdcnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,85 @@ func (vcd *TestVCD) Test_GetNetworkList(check *C) {
check.Assert(found, Equals, true)
}

// Test_GetNetworkListLarge makes sure we can query a number of networks larger than the default query page length
func (vcd *TestVCD) Test_GetNetworkListLarge(check *C) {
fmt.Printf("Running: %s\n", check.TestName())

defaultPagelength := 25
externalNetwork, err := vcd.client.GetExternalNetworkByName(vcd.config.VCD.ExternalNetwork)
if err != nil {
check.Skip("[Test_GetNetworkListLarge] parent network not found")
return
}
numOfNetworks := defaultPagelength + 1
baseName := vcd.config.VCD.Org
for i := 1; i <= numOfNetworks; i++ {
networkName := fmt.Sprintf("net-%s-d-%d", baseName, i)
if testVerbose {
fmt.Printf("creating network %s\n", networkName)
}
description := fmt.Sprintf("Created by govcd test - network n. %d", i)
var networkConfig = types.OrgVDCNetwork{
Xmlns: types.XMLNamespaceVCloud,
Name: networkName,
Description: description,
Configuration: &types.NetworkConfiguration{
FenceMode: types.FenceModeBridged,
ParentNetwork: &types.Reference{
HREF: externalNetwork.ExternalNetwork.HREF,
Name: externalNetwork.ExternalNetwork.Name,
Type: externalNetwork.ExternalNetwork.Type,
},
BackwardCompatibilityMode: true,
},
IsShared: false,
}
task, err := vcd.vdc.CreateOrgVDCNetwork(&networkConfig)
check.Assert(err, IsNil)

AddToCleanupList(networkName, "network", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_GetNetworkListLarge")
err = task.WaitTaskCompletion()
check.Assert(err, IsNil)
}

err = vcd.vdc.Refresh()
check.Assert(err, IsNil)

knownNetworkName1 := fmt.Sprintf("net-%s-d", baseName)
knownNetworkName2 := fmt.Sprintf("net-%s-d-%d", baseName, numOfNetworks)
networks, err := vcd.vdc.GetNetworkList()
check.Assert(err, IsNil)
if testVerbose {
fmt.Printf("Number of networks: %d\n", len(networks))
}
check.Assert(len(networks) > defaultPagelength, Equals, true)
found1 := false
found2 := false
for _, net := range networks {
if net.Name == knownNetworkName1 {
found1 = true
}
if net.Name == knownNetworkName2 {
found2 = true
}
}
check.Assert(found1, Equals, true)
check.Assert(found2, Equals, true)

for i := 1; i <= numOfNetworks; i++ {
networkName := fmt.Sprintf("net-%s-d-%d", baseName, i)
if testVerbose {
fmt.Printf("Removing network %s\n", networkName)
}
network, err := vcd.vdc.GetOrgVdcNetworkByName(networkName, false)
check.Assert(err, IsNil)
_, err = network.Delete()
check.Assert(err, IsNil)
}
err = vcd.vdc.Refresh()
check.Assert(err, IsNil)
}

// Tests the creation and update of an isolated Org VDC network
func (vcd *TestVCD) Test_CreateUpdateOrgVdcNetworkIso(check *C) {
fmt.Printf("Running: %s\n", check.TestName())
Expand Down

0 comments on commit 6e2b501

Please sign in to comment.