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

Openapi TestConnection new method #447

Closed
wants to merge 21 commits into from

Conversation

mikeletux
Copy link
Contributor

This PR does not have any issue associated.

Description

When creating a catalog and subscribing to an external one, VCD uses the endpoint /cloudapi/1.0.0/testConnection/ to check before hand if the endpoint where the user is trying to subscribe the external catalog from exists.

Detailed description

In order to implement the external catalog subscription in the Terraform provider for VCD when creating a catalog, TestConnection functionality needs to be implemented since before subscribing, VCD does this previous sanity check.

This has been implemented as a Client method, since it doesn't belong to any VCD resource and it's a client helping tool.

Also, I propose a slight change to Client.OpenApiPostItem since to use TestConnection, I had to do a POST request against /cloudapi/1.0.0/testConnection/. This results in a 200OK, instead of 201 or 202.
Client.OpenApiPostItem wasn't covering this case, so the function worked but it wasn't unmarshalling the response into the needed struct.
This last point is open to discussion, as it might be a better way to handle this.

🚀

Miguel Sama added 6 commits March 10, 2022 12:56
Fix small issue with OpenApiPostItem since it wasnt unmarshalling 200 OK responses

Signed-off-by: Miguel Sama <[email protected]>
Signed-off-by: Miguel Sama <[email protected]>
@mikeletux mikeletux marked this pull request as ready for review March 11, 2022 09:41
@lvirbalas
Copy link
Collaborator

In order to implement the external catalog subscription in the Terraform provider for VCD when creating a catalog, TestConnection functionality needs to be implemented since before subscribing, VCD does this previous sanity check.

I guess I'm still missing the use case: who/where/when will call the new OpenApiTestConnection function?

Thanks!

@mikeletux
Copy link
Contributor Author

In order to implement the external catalog subscription in the Terraform provider for VCD when creating a catalog, TestConnection functionality needs to be implemented since before subscribing, VCD does this previous sanity check.

I guess I'm still missing the use case: who/where/when will call the new OpenApiTestConnection function?

Thanks!

Yeah, maybe I didn't get much context.
When creating a catalog using the VCD UI (and as long as you have permission to subscribe to an external catalog), you can create a catalog subscribing from an external one. Please check the first figure:

image

If you check the HTTP traffic using a traffic sniffer, when you fill everything and click the OK button, you can see two POST calls being generated by the frontend.

image

  • The first one is to TestConnection. That endpoint checks that the remote endpoint where you are trying to subscribe the external catalog from, exists.
  • The second one is the actual call that creates the catalog for that Org.

Let me know if this make it clear 😄

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 explaining how we will use it at #447 (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.

Two parts

OpenAPI function adjustment

Looks good in general, but because functions in openapi.go are a backbone for all OpenAPI requests I have a few minor addition requests which I left inline, but also here as I can't comment untouched code lines.

OpenApiTestConnection

The test Test_OpenApiTestConnection has issue on 10.2 versions:

  • 10.2.0 - FAILS:
go test  -count 1 -tags ALL -check.vv -check.f OpenApiTestConnection -timeout=155m .
START: api_vcd_test.go:477: TestVCD.SetUpSuite
Running on VCD https://HOST/api (version 10.2.0.17008054 built at 2020-10-08 20:53:08 +0000 UTC)
as user administrator@System (using password)
Skipping all vapp tests because one of the following wasn't given: Network, StorageProfile, Catalog, Catalogitem
PASS: api_vcd_test.go:477: TestVCD.SetUpSuite   19.153s

START: openapi_test.go:265: TestVCD.Test_OpenApiTestConnection
openapi_test.go:304:
    check.Assert(err, IsNil)
... value *errors.errorString = &errors.errorString{s:"error creating Edge Gateway: error in HTTP POST request: VCD_50006 - [ 71b4c62b-90f2-4b16-9668-448b7d3358e5 ] Json processing error.\n - Unrecognized field \"hostnameVerificationAlgorithm\" (class com.vmware.vcloud.rest.openapi.model.Connection), not marked as ignorable (5 known properties: \"host\", \"port\", \"proxyConnection\", \"secure\", \"timeout\"])\n at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 6, column: 37] (through reference chain: com.vmware.vcloud.rest.openapi.model.Connection[\"hostnameVerificationAlgorithm\"])"} ("error creating Edge Gateway: error in HTTP POST request: VCD_50006 - [ 71b4c62b-90f2-4b16-9668-448b7d3358e5 ] Json processing error.\n - Unrecognized field \"hostnameVerificationAlgorithm\" (class com.vmware.vcloud.rest.openapi.model.Connection), not marked as ignorable (5 known properties: \"host\", \"port\", \"proxyConnection\", \"secure\", \"timeout\"])\n at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 6, column: 37] (through reference chain: com.vmware.vcloud.rest.openapi.model.Connection[\"hostnameVerificationAlgorithm\"])")

FAIL: openapi_test.go:265: TestVCD.Test_OpenApiTestConnection

START: api_vcd_test.go:1549: TestVCD.TearDownSuite
PASS: api_vcd_test.go:1549: TestVCD.TearDownSuite       0.002s

OOPS: 0 passed, 1 FAILED
  • 10.2.2 - FAILS
go test  -count 1 -tags ALL -check.vv -check.f OpenApiTestConnection -timeout=155m .
START: api_vcd_test.go:477: TestVCD.SetUpSuite
Running on VCD https://HOST/api (version 10.2.2.18634228 built at 2021-09-15 17:30:35 +0000 UTC)
as user administrator@System (using password)
Skipping all vapp tests because one of the following wasn't given: Network, StorageProfile, Catalog, Catalogitem
PASS: api_vcd_test.go:477: TestVCD.SetUpSuite   21.967s

START: openapi_test.go:265: TestVCD.Test_OpenApiTestConnection
openapi_test.go:304:
    check.Assert(err, IsNil)
... value *errors.errorString = &errors.errorString{s:"error creating Edge Gateway: error in HTTP POST request: VCD_50006 - [ e08d6df1-4eb0-42ec-b090-cda5ef4dedeb ] Json processing error.\n - Unrecognized field \"hostnameVerificationAlgorithm\" (class com.vmware.vcloud.rest.openapi.model.Connection), not marked as ignorable (5 known properties: \"host\", \"port\", \"proxyConnection\", \"secure\", \"timeout\"])\n at [Source: (org.apache.cxf.metrics.interceptors.CountingInputStream); line: 6, column: 37] (through reference chain: com.vmware.vcloud.rest.openapi.model.Connection[\"hostnameVerificationAlgorithm\"])"} ("error creating Edge Gateway: error in HTTP POST request: VCD_50006 - [ e08d6df1-4eb0-42ec-b090-cda5ef4dedeb ] Json processing error.\n - Unrecognized field \"hostnameVerificationAlgorithm\" (class com.vmware.vcloud.rest.openapi.model.Connection), not marked as ignorable (5 known properties: \"host\", \"port\", \"proxyConnection\", \"secure\", \"timeout\"])\n at [Source: (org.apache.cxf.metrics.interceptors.CountingInputStream); line: 6, column: 37] (through reference chain: com.vmware.vcloud.rest.openapi.model.Connection[\"hostnameVerificationAlgorithm\"])")

FAIL: openapi_test.go:265: TestVCD.Test_OpenApiTestConnection

START: api_vcd_test.go:1549: TestVCD.TearDownSuite
PASS: api_vcd_test.go:1549: TestVCD.TearDownSuite       0.001s

OOPS: 0 passed, 1 FAILED
--- FAIL: Test (22.90s)
  • 10.3.2 - OK

Miguel Sama added 6 commits March 15, 2022 13:23
Signed-off-by: Miguel Sama <[email protected]>
…nt.TestConnection`

Update OpenApiPostItemSync so it supports 200OK codes and now returns error if return code is different from 200 or 201

Signed-off-by: Miguel Sama <[email protected]>
Rename `OpenApiTestConnection` to `TestConnection`

Signed-off-by: Miguel Sama <[email protected]>
Signed-off-by: Miguel Sama <[email protected]>
Signed-off-by: Miguel Sama <[email protected]>
@mikeletux
Copy link
Contributor Author

@Didainius some comments regarding the changes that I did.

  • Apart from the changes you suggested to Client.OpenApiPostItemSync now the method is returning an error if the status code that is returned is not 200 or 201. This wasn't the previous behavior. I did it because the function description actually says that if return code is different from 200 or 201 it errors, and also because when writing the test if wasn't impossible to find out if POST against an endpoint that returns 200OK was handled appropriately.
  • Add a workaround to Client.TestConnection so if API max version is below 36.0, sets some fields not supported to empty so they are not send in the POST request and the function doesn't error (I tested this on 10.2.2. Could you please test it on 10.2.0?)
  • Add a test in Test_OpenApiInlineStructCRUDRoles that manually builds TestConnection payload and send it using Client.OpenApiPostItemSync to check that this function handles correctly 200OK.

Let me know if you're concerned about anything else! 🚀

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

I would say we need wrapper function too, which would have only minimum values for input like URL and everything else default. I guess in UI you provide URL.

Miguel Sama added 2 commits March 16, 2022 10:54
@mikeletux
Copy link
Contributor Author

I would say we need wrapper function too, which would have only minimum values for input like URL and everything else default. I guess in UI you provide URL.

This is interesting. Let's see what @lvirbalas @Didainius @adambarreiro have to say about it.
I could grab the default values that the UI uses and write a wrapper.

@Didainius
Copy link
Collaborator

This is interesting. Let's see what @lvirbalas @Didainius @adambarreiro have to say about it.
I could grab the default values that the UI uses and write a wrapper.

Go ahead if this is easy to make it (no advanced computations for fields)

@vbauzys
Copy link
Contributor

vbauzys commented Mar 16, 2022

I would say we need wrapper function too, which would have only minimum values for input like URL and everything else default. I guess in UI you provide URL.

This is interesting. Let's see what @lvirbalas @Didainius @adambarreiro have to say about it. I could grab the default values that the UI uses and write a wrapper.

how the current function is used in terraform? how does call look like?

@mikeletux
Copy link
Contributor Author

how the current function is used in terraform? how does call look like?

Is not yet being used, but I'll use it when enhancing the Catalog resource, when it comes to create a new catalog subscribing from an external one.
Before doing anything, check that the VCD instance where the catalog you're going to subscribe from, exist.

@vbauzys
Copy link
Contributor

vbauzys commented Mar 16, 2022

how the current function is used in terraform? how does call look like?

Is not yet being used, but I'll use it when enhancing the Catalog resource, when it comes to create a new catalog subscribing from an external one. Before doing anything, check that the VCD instance where the catalog you're going to subscribe from, exist.

So then you see how kind wrapper is better :)

Miguel Sama added 2 commits March 16, 2022 13:25
…s` so it test that function and `TestConnection` at the same time

Signed-off-by: Miguel Sama <[email protected]>
@mikeletux
Copy link
Contributor Author

@vbauzysvmware added the method TestConnectionWithDefaults so it gets a subscription URL and returns if it was possible to connect.

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 for fixes. I am approving - just fix the typo in a separate comment.

@@ -115,7 +121,7 @@ func (client *Client) checkOpenApiEndpointCompatibility(endpoint string) (string
// supported API versions just like client.checkOpenApiEndpointCompatibility().
//
// The advantage of this functions is that it provides a controlled API elevation instead of just picking the highest
// which could be risky and untested (especially if new API version is released after release of package consuming this
// which could be risky and untested (especially if new API version hich could be risky and untested (especially if new API version is released after release of package consuming this
Copy link
Collaborator

Choose a reason for hiding this comment

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

This remaining thing to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rephrased that so it makes sense now. Thanks for spotting that 🚀

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

Thank you

Miguel Sama added 2 commits March 16, 2022 16:03
@Didainius
Copy link
Collaborator

Closing in favor of #501

@Didainius Didainius closed this Aug 25, 2022
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.

6 participants