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

Allow to pass and override default hard coded api version #274

Merged
merged 12 commits into from
Dec 16, 2019
Merged

Allow to pass and override default hard coded api version #274

merged 12 commits into from
Dec 16, 2019

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Dec 6, 2019

This change is driven from VM internal disk PR(#272) and investigation. Also we saw need that in near feature in other cases, as we face more such cases when we need specific version due limitation of using lowest possible API version.

  • Moved field supportedVersions from vCDclient to client
  • Updated all references with cange of supportedVersions
  • Added request handling methods WithApiVersion which allows to pass API version which will be written in request header(override default hard coded one)

We need override only per request base API version. Changing connection API version would create compatibility issues and breakage.

…ersion

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
@vbauzys vbauzys changed the title Add change which allows to pass and override default hard coded api v… Allow to pass and override default hard coded api version Dec 9, 2019
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.

Essentially documentation asks. Please also add a changelog entry.

govcd/api.go Outdated Show resolved Hide resolved
govcd/api.go Show resolved Hide resolved
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
govcd/api.go Outdated
@@ -188,6 +196,12 @@ func (cli *Client) NewRequest(params map[string]string, method string, reqUrl ur
return cli.NewRequestWitNotEncodedParams(params, nil, method, reqUrl, body)
}

// NewRequest creates a new HTTP request and applies necessary auth headers if set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// NewRequest creates a new HTTP request and applies necessary auth headers if set.
// NewRequestWithApiVersion creates a new HTTP request and applies necessary auth headers if set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

udpated

@@ -127,6 +129,12 @@ func ContainsNotFound(err error) bool {

// NewRequestWitNotEncodedParams allows passing complex values params that shouldn't be encoded like for queries. e.g. /query?filter=name=foo
func (cli *Client) NewRequestWitNotEncodedParams(params map[string]string, notEncodedParams map[string]string, method string, reqUrl url.URL, body io.Reader) *http.Request {
return cli.NewRequestWitNotEncodedParamsWithApiVersion(params, notEncodedParams, method, reqUrl, body, cli.APIVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see a few tests for the new functions, to make sure that:

  1. They are really using the intended API version.
  2. Subsequent requests using the regular Execute* methods are not affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you share your idea how to test that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a possible way:

  1. Add fields to a type that was enhanced in API versions later than the current one.
  2. Run a GET that retrieves the type with the enhanced fields
  3. Make sure the fields are non-empty
  4. Run the same query without the new API version
  5. Make sure that the enhanced fields are empty

Copy link
Collaborator

Choose a reason for hiding this comment

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

Two more ideas:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first option could be valid with on specific vCD version or I have to find valid for all versions, which is lottery
I'll check possibility with response headers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
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.

Would also like to see a test hitting the new API-version-override ability, LGTM otherwise.

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
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.

I am happy with it, just as well. The only thing - would be good to have some test as Giuseppe mentioned.

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>

# Conflicts:
#	CHANGELOG.md
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>

// Test_NewRequestWitNotEncodedParamsWithApiVersion verifies that api version override works
func (vcd *TestVCD) Test_NewRequestWitNotEncodedParamsWithApiVersion(check *C) {
fmt.Printf("Running: %s\n", check.TestName())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Double check the outputs as they are missing new lines. Heres' how it looks.

START: api_test.go:105: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion
Running: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion
Test: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion run with api Version: 33.0
PASS: api_test.go:105: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion 0.191s

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. This is fine as it is as planned.

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.

Tested the particular function on 9.0, 9.5 and 10. All worked.
The only ask is to fix the outputs.

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

LGTM

@vbauzys vbauzys merged commit ca7fe09 into vmware:master Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants