Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TM VDC and Region Zones #720

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0e7290d
Region PR
Didainius Oct 28, 2024
6ae2108
Add changelog note
Didainius Oct 28, 2024
c2c7276
Self review
Didainius Oct 28, 2024
42d6028
Adjustments
Didainius Oct 30, 2024
c6c4843
Self review
Didainius Oct 30, 2024
05169e7
Self review
Didainius Oct 30, 2024
571c687
WIP
Didainius Nov 4, 2024
e2286ae
Address comments
Didainius Nov 4, 2024
bf7c06b
Address comment - improve code comment
Didainius Nov 5, 2024
f471193
Merge branch 'region-pr' into vdc
Didainius Nov 6, 2024
df26ea1
Rename StoragePolicies to StorageClasses
Nov 6, 2024
8588c19
#
Nov 6, 2024
2c6b7fe
Pick Dainius PR
Nov 6, 2024
4c5dd85
#
Nov 6, 2024
8eaea24
#
Nov 6, 2024
28e9d26
#
Nov 6, 2024
5a32850
WIP
Didainius Nov 7, 2024
8a1f72a
Add VCDClient.GetSupervisorByNameAndVcenterId and test
Didainius Nov 7, 2024
ab3709b
#
Nov 7, 2024
f086097
Cleanup funcs
Nov 7, 2024
d83628c
Merge
Nov 7, 2024
283a1a3
merge main
Didainius Nov 7, 2024
223f26f
Fixes
Nov 7, 2024
910ea72
Tests pass
Nov 7, 2024
f4b7f79
#
Nov 7, 2024
5c1d049
#
Nov 7, 2024
b8c2ccb
#
Nov 7, 2024
864a36a
Move to separate file
Nov 8, 2024
1d72ea2
#
Nov 8, 2024
95a6a12
#
Nov 8, 2024
e071b96
WIP
Didainius Nov 11, 2024
d061a34
Merge branch 'fix-region-sp' into vdc
Didainius Nov 11, 2024
810f8af
Merge up
Didainius Nov 11, 2024
05277dc
Improve test
Didainius Nov 11, 2024
aef69b5
Merge main
Didainius Nov 11, 2024
2986270
Improve test, gitignore and region setup func
Didainius Nov 12, 2024
6fac201
Self review, docs
Didainius Nov 13, 2024
9956f91
Typos and comments
Didainius Nov 14, 2024
ed5f990
Self review
Didainius Nov 15, 2024
96d6ca8
Improve cleanup
Didainius Nov 15, 2024
37b4091
improve names
Didainius Nov 15, 2024
2647d4b
Add GetTmVdcByNameAndOrgId
Didainius Nov 18, 2024
dd39659
Improve test
Didainius Nov 18, 2024
2220bec
Self review - docs
Didainius Nov 18, 2024
63a0abc
Use native filtering in GetTmVdcByName and GetTmVdcByNameAndOrgId
Didainius Nov 25, 2024
42ff199
Add changelog adjustment
Didainius Nov 26, 2024
77d1655
Revert "Add changelog adjustment" - wrong branch
Didainius Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#
Signed-off-by: abarreiro <[email protected]>
  • Loading branch information
abarreiro committed Nov 6, 2024
commit 4c5dd85f533ae5d4f08e84fec8c6fae47ca1ffba
1 change: 1 addition & 0 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type TestConfig struct {
}
Tenants []Tenant `yaml:"tenants,omitempty"`
Tm struct {
Region string `yaml:"region"`
RegionStoragePolicy string `yaml:"regionStoragePolicy"`

CreateVcenter bool `yaml:"createVcenter"`
Expand Down
2 changes: 2 additions & 0 deletions govcd/sample_govcd_test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ solutionAddOn:
# An existing Add-On image within catalog
addonImageDse: "vmware-vcd-ds-1.4.0-23376809.iso"
tm:
# An existing Region to create VDCs, Content Libraries...
region: my-region
# An existing Region Storage Policy to create Content Libraries, Regions...
regionStoragePolicy: "vSAN Default Storage Policy"
createVcenter: true # boolean value if the vCenter test should be executed
Expand Down
4 changes: 2 additions & 2 deletions govcd/tm_content_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (vcdClient *VCDClient) GetContentLibraryByName(name string) (*ContentLibrar
return nil, err
}

return vcdClient.GetContentLibraryById(singleEntity.ContentLibrary.Id)
return vcdClient.GetContentLibraryById(singleEntity.ContentLibrary.ID)
}

// GetContentLibraryById retrieves a Content Library with the given ID
Expand Down Expand Up @@ -130,7 +130,7 @@ func (o *ContentLibrary) Delete() error {
c := crudConfig{
entityLabel: labelContentLibrary,
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointContentLibraries,
endpointParams: []string{o.ContentLibrary.Id},
endpointParams: []string{o.ContentLibrary.ID},
}
return deleteEntityById(&o.vcdClient.Client, c)
}
18 changes: 11 additions & 7 deletions govcd/tm_content_library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,40 @@ func (vcd *TestVCD) Test_ContentLibraryProvider(check *C) {
skipNonTm(vcd, check)
sysadminOnly(vcd, check)

region, err := vcd.client.GetRegionByName("adam-region-1")
check.Assert(err, IsNil)
check.Assert(region, NotNil)

cls, err := vcd.client.GetAllContentLibraries(nil)
check.Assert(err, IsNil)
existingContentLibraryCount := len(cls)

rsp, err := vcd.client.GetRegionStoragePolicyByName(vcd.config.Tm.RegionStoragePolicy)
rsp, err := region.GetStoragePolicyByName(vcd.config.Tm.RegionStoragePolicy)
check.Assert(err, IsNil)
check.Assert(rsp, NotNil)

clDefinition := &types.ContentLibrary{
Name: check.TestName(),
StorageClasses: []*types.OpenApiReference{{ID: rsp.RegionStoragePolicy.Id}},
StorageClasses: []*types.OpenApiReference{{ID: rsp.RegionStoragePolicy.ID}},
AutoAttach: true, // TODO: TM: Test with false, still does not work
Description: check.TestName(),
}

createdCl, err := vcd.client.CreateContentLibrary(clDefinition)
check.Assert(err, IsNil)
check.Assert(createdCl, NotNil)
AddToCleanupListOpenApi(createdCl.ContentLibrary.Name, check.TestName(), types.OpenApiPathVcf+types.OpenApiEndpointContentLibraries+createdCl.ContentLibrary.Id)
AddToCleanupListOpenApi(createdCl.ContentLibrary.Name, check.TestName(), types.OpenApiPathVcf+types.OpenApiEndpointContentLibraries+createdCl.ContentLibrary.ID)

// Defer deletion for a correct cleanup
defer func() {
err = createdCl.Delete()
check.Assert(err, IsNil)
}()
check.Assert(isUrn(createdCl.ContentLibrary.Id), Equals, true)
check.Assert(isUrn(createdCl.ContentLibrary.ID), Equals, true)
check.Assert(createdCl.ContentLibrary.Name, Equals, clDefinition.Name)
check.Assert(createdCl.ContentLibrary.Description, Equals, clDefinition.Description)
check.Assert(len(createdCl.ContentLibrary.StorageClasses), Equals, 1)
check.Assert(createdCl.ContentLibrary.StorageClasses[0].ID, Equals, rsp.RegionStoragePolicy.Id)
check.Assert(createdCl.ContentLibrary.StorageClasses[0].ID, Equals, rsp.RegionStoragePolicy.ID)
check.Assert(createdCl.ContentLibrary.AutoAttach, Equals, clDefinition.AutoAttach)
// "Computed" values
check.Assert(createdCl.ContentLibrary.IsShared, Equals, true) // TODO: TM: Still not used in UI
Expand All @@ -63,7 +67,7 @@ func (vcd *TestVCD) Test_ContentLibraryProvider(check *C) {
check.Assert(err, IsNil)
check.Assert(len(cls), Equals, existingContentLibraryCount+1)
for _, l := range cls {
if l.ContentLibrary.Id == createdCl.ContentLibrary.Id {
if l.ContentLibrary.ID == createdCl.ContentLibrary.ID {
check.Assert(*l.ContentLibrary, DeepEquals, *createdCl.ContentLibrary)
break
}
Expand All @@ -74,7 +78,7 @@ func (vcd *TestVCD) Test_ContentLibraryProvider(check *C) {
check.Assert(cl, NotNil)
check.Assert(*cl.ContentLibrary, DeepEquals, *createdCl.ContentLibrary)

cl, err = vcd.client.GetContentLibraryById(cl.ContentLibrary.Id)
cl, err = vcd.client.GetContentLibraryById(cl.ContentLibrary.ID)
check.Assert(err, IsNil)
check.Assert(cl, NotNil)
check.Assert(*cl.ContentLibrary, DeepEquals, *createdCl.ContentLibrary)
Expand Down
36 changes: 24 additions & 12 deletions govcd/tm_region_storage_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const labelRegionStoragePolicy = "Region Storage Policy"
// RegionStoragePolicy defines the Region Storage Policy data structure
type RegionStoragePolicy struct {
RegionStoragePolicy *types.RegionStoragePolicy
vcdClient *VCDClient
client *Client
}

// wrap is a hidden helper that facilitates the usage of a generic CRUD function
Expand All @@ -27,29 +27,32 @@ func (g RegionStoragePolicy) wrap(inner *types.RegionStoragePolicy) *RegionStora
return &g
}

// GetAllRegionStoragePolicies retrieves all Region Storage Policies with the given query parameters, which allow setting filters
// GetAllStoragePolicies retrieves all Region Storage Policies with the given query parameters, which allow setting filters
// and other constraints
func (vcdClient *VCDClient) GetAllRegionStoragePolicies(queryParameters url.Values) ([]*RegionStoragePolicy, error) {
func (r *Region) GetAllStoragePolicies(queryParameters url.Values) ([]*RegionStoragePolicy, error) {
return getAllStoragePolicies(r, queryParameters)
}
func getAllStoragePolicies(r *Region, queryParameters url.Values) ([]*RegionStoragePolicy, error) {
c := crudConfig{
entityLabel: labelRegionStoragePolicy,
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegionStoragePolicies,
queryParameters: queryParameters,
}

outerType := RegionStoragePolicy{vcdClient: vcdClient}
return getAllOuterEntities(&vcdClient.Client, outerType, c)
outerType := RegionStoragePolicy{client: &r.vcdClient.Client}
return getAllOuterEntities(&r.vcdClient.Client, outerType, c)
}

// GetRegionStoragePolicyByName retrieves a Region Storage Policy by name
func (vcdClient *VCDClient) GetRegionStoragePolicyByName(name string) (*RegionStoragePolicy, error) {
// GetStoragePolicyByName retrieves a Region Storage Policy by name
func (r *Region) GetStoragePolicyByName(name string) (*RegionStoragePolicy, error) {
if name == "" {
return nil, fmt.Errorf("%s lookup requires name", labelRegionStoragePolicy)
}

queryParams := url.Values{}
queryParams.Add("filter", "name=="+name)
queryParams.Add("filter", fmt.Sprintf("(name==%s;region.id==%s)", name, r.Region.ID))

filteredEntities, err := vcdClient.GetAllRegionStoragePolicies(queryParams)
filteredEntities, err := getAllStoragePolicies(r, queryParams)
if err != nil {
return nil, err
}
Expand All @@ -64,17 +67,26 @@ func (vcdClient *VCDClient) GetRegionStoragePolicyByName(name string) (*RegionSt
// return nil, err
//}

return vcdClient.GetRegionStoragePolicyById(singleEntity.RegionStoragePolicy.Id)
return getStoragePolicyById(&r.vcdClient.Client, singleEntity.RegionStoragePolicy.ID)
}

// GetStoragePolicyById retrieves a Region Storage Policy by ID
func (r *Region) GetStoragePolicyById(id string) (*RegionStoragePolicy, error) {
return getStoragePolicyById(&r.vcdClient.Client, id)
}

// GetRegionStoragePolicyById retrieves a Region Storage Policy by ID
func (vcdClient *VCDClient) GetRegionStoragePolicyById(id string) (*RegionStoragePolicy, error) {
return getStoragePolicyById(&vcdClient.Client, id)
}

func getStoragePolicyById(client *Client, id string) (*RegionStoragePolicy, error) {
c := crudConfig{
entityLabel: labelRegionStoragePolicy,
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegionStoragePolicies,
endpointParams: []string{id},
}

outerType := RegionStoragePolicy{vcdClient: vcdClient}
return getOuterEntity(&vcdClient.Client, outerType, c)
outerType := RegionStoragePolicy{client: client}
return getOuterEntity(client, outerType, c)
}
22 changes: 12 additions & 10 deletions govcd/tm_region_storage_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@ import (
. "gopkg.in/check.v1"
)

// TODO: TM: Missing Create, Update, Delete
func (vcd *TestVCD) Test_RegionStoragePolicy(check *C) {
skipNonTm(vcd, check)
sysadminOnly(vcd, check)

allRegionStoragePolicies, err := vcd.client.GetAllRegionStoragePolicies(nil)
region, err := vcd.client.GetRegionByName(vcd.config.Tm.Region)
check.Assert(err, IsNil)
check.Assert(region, NotNil)

// TODO: TM: Once we can create Region SPs, we don't need the TM environment to have pre-existing Storage Policies
if len(allRegionStoragePolicies) == 0 {
check.Skip("didn't find any Region Storage Policy")
}
allRegionStoragePolicies, err := region.GetAllStoragePolicies(nil)
check.Assert(err, IsNil)

rspById, err := vcd.client.GetRegionStoragePolicyById(allRegionStoragePolicies[0].RegionStoragePolicy.Id)
rspById, err := region.GetStoragePolicyById(allRegionStoragePolicies[0].RegionStoragePolicy.ID)
check.Assert(err, IsNil)
check.Assert(*rspById.RegionStoragePolicy, DeepEquals, *allRegionStoragePolicies[0].RegionStoragePolicy)

rspByName, err := vcd.client.GetRegionStoragePolicyByName(allRegionStoragePolicies[0].RegionStoragePolicy.Name)
rspById2, err := vcd.client.GetRegionStoragePolicyById(allRegionStoragePolicies[0].RegionStoragePolicy.ID)
check.Assert(err, IsNil)
check.Assert(*rspById2.RegionStoragePolicy, DeepEquals, *rspById.RegionStoragePolicy)

rspByName, err := region.GetStoragePolicyByName(allRegionStoragePolicies[0].RegionStoragePolicy.Name)
check.Assert(err, IsNil)
check.Assert(*rspByName.RegionStoragePolicy, DeepEquals, *allRegionStoragePolicies[0].RegionStoragePolicy)

// Check ENF errors
_, err = vcd.client.GetRegionStoragePolicyById("urn:vcloud:regionStoragePolicy:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
_, err = region.GetStoragePolicyById("urn:vcloud:regionStoragePolicy:aaaaaaaa-1111-0000-cccc-bbbb1111dddd")
check.Assert(err, NotNil)
check.Assert(ContainsNotFound(err), Equals, true)

_, err = vcd.client.GetRegionStoragePolicyByName("NotExists")
_, err = region.GetStoragePolicyByName("NotExists")
check.Assert(err, NotNil)
check.Assert(ContainsNotFound(err), Equals, true)
}
4 changes: 2 additions & 2 deletions types/v56/tm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

// RegionStoragePolicy defines a Region storage policy
type RegionStoragePolicy struct {
Id string `json:"id,omitempty"`
ID string `json:"id,omitempty"`
// Name for the policy. It must follow RFC 1123 Label Names to conform with Kubernetes standards
Name string `json:"name"`
// The Region that this policy belongs to
Expand Down Expand Up @@ -34,7 +34,7 @@ type ContentLibrary struct {
// The description of the Content Library
Description string `json:"description,omitempty"`
// A unique identifier for the Content library
Id string `json:"id,omitempty"`
ID string `json:"id,omitempty"`
// Whether this Content Library is shared with other organizations
IsShared bool `json:"isShared,omitempty"`
// Whether this Content Library is subscribed from an external published library
Expand Down