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

Add AdminOrgVdcStorageProfile for querying #375

Closed
wants to merge 8 commits into from

Conversation

lelvisl
Copy link
Contributor

@lelvisl lelvisl commented May 11, 2021

Issue: #373

Added:

  • QueryResultAdminOrgVdcStorageProfileRecordType type.
  • Constants for querying: QtOrgVdcStorageProfile and QtAdminOrgVdcStorageProfile.
  • Funcs for querying : QueryAdminOrgVdcStorageProfileByID and QueryOrgVdcStorageProfileByID.

QueryOrgVdcStorageProfileByID (non Admin) not workin (tested wiht vCloud 10.0 and 10.2.2).
May be query isn't correct.

Added:
- QueryResultAdminOrgVdcStorageProfileRecordType type.
- Constants for querying: QtOrgVdcStorageProfile and QtAdminOrgVdcStorageProfile.
- Funcs for querying : QueryAdminOrgVdcStorageProfileByID and QueryOrgVdcStorageProfileByID.

QueryOrgVdcStorageProfileByID (non Admin) not workin (tested wiht vCloud 10.0 and 10.2.2).
May be query isn't correct.
@vmwclabot
Copy link
Member

@lelvisl, you must sign our contributor license agreement before your changes are merged. Click here to sign the agreement. If you are a VMware employee, read this for further instruction.

@vmwclabot
Copy link
Member

@lelvisl, VMware has approved your signed contributor license agreement.

@lelvisl
Copy link
Contributor Author

lelvisl commented May 14, 2021

QueryOrgVdcStorageProfileByID (non Admin) not workin (tested wiht vCloud 10.0 and 10.2.2) - wokring well if you are not provider admin.
As i think, this PR can be merged.

@lelvisl
Copy link
Contributor Author

lelvisl commented May 24, 2021

Can we merge this PR or we need to discuss something?

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this drag. Going for review and testing.

Would you be able to add a line to CHANGELOG.md about this?
Also - any chances you could put a few tests into system_test.go (there are quite a few similar ones if you need inspiration :))

types/v56/constants.go Outdated Show resolved Hide resolved
types/v56/types.go Outdated Show resolved Hide resolved
- corrected review notes
- added point to changelog
- update test suit and add test
@lelvisl
Copy link
Contributor Author

lelvisl commented May 27, 2021

Thanks for your review! Can you look again please?

govcd/system.go Outdated
@@ -975,3 +975,29 @@ func (vcdCli *VCDClient) GetOrgList() (*types.OrgList, error) {
}
return orgList, nil
}

// QueryAdminOrgVdcStorageProfileByID finds a StorageProfile of VDC by ID as admin
func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.QueryResultAdminOrgVdcStorageProfileRecordType, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Now just pardon, but I just tried to play with code and one thing hit me.
I think the signature could be:

Suggested change
func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.QueryResultAdminOrgVdcStorageProfileRecordType, error) {
func QueryAdminOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) (*types.QueryResultAdminOrgVdcStorageProfileRecordType, error) {

That is - you don't need to return a slice of results because you are querying by ID which guarantees that there is either exactly one result, or not.

A slice could be if it was QueryOrgVdcStorageProfile which doesn't guarantee one object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i then rename this method to GetAdminOrgVdcStorageProfileByID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or implement QueryOrgVdcStorageProfile with params and GetAdminOrgVdcStorageProfileByID that use previous?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetX in this SDK usually mean that it is not an object from query endpoint, but from its legitimate endpoint (e.g. AdminOrg.GetVDCById would not return a Query result, but the VDC struct itself. Query and object endpoints usually return different data that is why we try to keep Query and Get (to differentiate these things). This is not 100% due to historic reasons, but that is a good thing to follow.

Or - if you want to implement a function that returns all objects then it could be QueryAdminOrgVdcStorageProfile. But if you simply leave the code as it is (and not apply ID filter) you will hit a problem - by default it returns only the first page of data (which is usually up to 25 items). It is not easy to spot this on testing envs where not many resources exist, but we have already hit that and fixed some of the problems here. The trick here is to use client.cumulativeQuery internally which handles pagination and makes sure all pages are retrieved. (You could look through functions like QueryEdgeGatewayList or QueryAllVdcs to see how it is implemented.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with you and changed signature.

About QueryAdminOrgVdcStorageProfile - i think we need separate issue for discuss.

@lelvisl lelvisl requested a review from Didainius May 28, 2021 14:35
@Didainius
Copy link
Collaborator

Not sure if you saw that, but I put a comment: #375 (comment)

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last convenience spot from me and I agree QueryAdminOrgVdcStorageProfile can be left for later on.

govcd/system.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Approved and I left two typo comments and will wait for other team members to have a glimpse before we can merge.

govcd/system.go Outdated Show resolved Hide resolved
govcd/system.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thanks for contributing!

@lelvisl
Copy link
Contributor Author

lelvisl commented Jun 10, 2021

@dataclouder can you please review this PR?

govcd/system.go Show resolved Hide resolved
@dataclouder
Copy link
Contributor

Another issue: You should merge your PR with master, as some important pieces are missing. When you run the test for QueryOrgVdcStorageProfileByID, for example, you will need tenant credentials, and with the current code authentication will fail. (The bug was fixed in PR #376 )

lelvisl added 2 commits June 12, 2021 14:20
updated fields for QueryResultAdminOrgVdcStorageProfileRecordType and  QueryResultOrgVdcStorageProfileRecordType
add skip/error in case of Client.IsSysAdmin - vmware#384
@lelvisl
Copy link
Contributor Author

lelvisl commented Jun 12, 2021

@dataclouder i merged upstream into my brunch and updated all fields.

About tests:
Please look at #384. Test suit now is provider oriented, i can't (or don't know) how to setup both test successful from single user and i add skip in case of Client.IsSysAdmin (but it's not looking good for me).

@lelvisl lelvisl requested a review from dataclouder June 12, 2021 12:21
@lelvisl
Copy link
Contributor Author

lelvisl commented Sep 1, 2021

How about this change? Close? Or you want this changes? If yes - please give some feedback.

As i see - PR #393 doesn't solve this problem

@Didainius
Copy link
Collaborator

@lelvisl, can you have a look at #499. We're finally hoping to resolve this and close. I merged up with latest, impoved tests.

@Didainius Didainius closed this Aug 18, 2022
@lelvisl lelvisl deleted the AdminOrgVdcStorageProfileRecord branch August 18, 2022 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants