Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[v2] Add versioned endpoint discovery #3435

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

Open
wants to merge 24 commits into
base: v2
Choose a base branch
from

Conversation

stephenfin
Copy link
Contributor

This is a manual backport of #3351 and #3420, with #3108 also included to avoid tricky merge conflicts. A backport of #3108 is proposed separately at #3434 to ease reviews. We should probably merge that first and then come back to rebase and merge this.

stephenfin and others added 24 commits June 19, 2025 15:31
Global tests objects are harmful, in so far as any attempt to modify
them can result in failures further down the food chain. Don't use them
and instead generate new objects on the fly.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 610f545)
The fake service clients rely on the fake server being initialised, even
if we don't actually use it. Add the missing calls, renaming some tests
in the process.

PS: You can reproduce this without the '-shuffle on' by simply deleting
any of the test cases preceding those that we are modifying here and
running the tests.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 47b361b)
This is a mildly backwards-incompatible change, but since most people
only use this API on the level of pagination.Pager, it ought not be a
big deal in practice.

Closes gophercloud#3222.

(cherry picked from commit 97c0a32)
Ahead of some large-scale rework here.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 1476dae)
All aliases were discovered with:

    ag '[^\t]"github.com/gophercloud/gophercloud/v2/testhelper/client"'

They were then replaced with judicious use of sed and ag. Starting with
the most common alias, 'fake', first replace the alias:

    sed -i 's/\<fake\>/client/' $(ag 'fake "github.com/gophercloud/gophercloud/v2/testhelper/client"' -l)

This was repeated for the other aliases, 'fakeclient' and 'thclient'. We
then dropped the now unnecessary aliasing:

    sed -i 's/\<client\> "/"/' $(ag 'client "github.com/gophercloud/gophercloud/v2/testhelper/client"' -l)

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit beeed5b)
Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 2f52485)
The meat of this changes is in 'testhelper/http_responses.go' and
'testhelper/client/fake.go'. The rest of the change is bulk generated
updates to handle those changes:

Create a "FakeServer" instance instead of configuring the global fake:

    sed -i 's/th.SetupHTTP/fakeServer := th.SetupHTTP/g' $(ag 'th.SetupHTTP' -l)

Tear down this instance on test completion:

    sed -i 's/defer th.TeardownHTTP/defer fakeServer.Teardown/g' $(ag 'defer th.TeardownHTTP' -l)

Update calls to the global 'Mux' instance with calls to the FakeServer
version:

    sed -i 's/th.Mux.HandleFunc/fakeServer.Mux.HandleFunc/g' $(ag 'th.Mux.HandleFunc' -l)

Update calls to ServiceClient to include a 'FakeServer' parameter:

    sed -i 's/client.ServiceClient()/client.ServiceClient(fakeServer)/' $(ag -w client.ServiceClient -l)

Plus alises for the same:

    sed -i 's/fake.ServiceClient()/fake.ServiceClient(fakeServer)/' $(ag 'fake.ServiceClient' -l)

Update definitions and calls to various MockFoo and HandleFoo helpers -
plus lowercase, private variants of same - to include a 'FakeServer'
parameter:

    sed -i 's/\(func Mock\w\+(t \*testing.T\)/\1, fakeServer th.FakeServer/' $(ag 'func Mock\w+\(t \*testing.T' -l)
    sed -i 's/\(\tMock\w\+(t\)/\1, fakeServer/' $(ag '\tMock\w+\(t' -l)
    sed -i 's/\(func mock\w\+(t \*testing.T\)/\1, fakeServer th.FakeServer/' $(ag 'func mock\w+\(t \*testing.T' -l)
    sed -i 's/\(\tmock\w\+(t\)/\1, fakeServer/' $(ag '\tmock\w+\(t' -l)
    sed -i 's/\(func Handle\w\+(t \*testing.T\)/\1, fakeServer th.FakeServer/' $(ag 'func Handle\w+\(t \*testing.T' -l)
    sed -i 's/\(\tHandle\w\+(t\)/\1, fakeServer/' $(ag '\tHandle\w+\(t' -l)
    sed -i 's/\(func handle\w\+(t \*testing.T\)/\1, fakeServer th.FakeServer/' $(ag 'func handle\w+\(t \*testing.T' -l)
    sed -i 's/\(\thandle\w\+(t\)/\1, fakeServer/' $(ag '\thandle\w+\(t' -l)

Finally, there were some manual fixes to handle stuff that the regexes
missed.

Conflicts:
    openstack/baremetal/v1/portgroups/testing/fixtures.go
    openstack/baremetal/v1/portgroups/testing/requests_test.go
    openstack/compute/v2/servers/testing/requests_test.go
    openstack/db/v1/quotas/testing/fixtures_test.go
    openstack/db/v1/quotas/testing/requests_test.go
    openstack/dns/v2/zones/testing/requests_test.go
    openstack/loadbalancer/v2/flavors/testing/fixtures.go
    openstack/loadbalancer/v2/flavors/testing/requests_test.go
    openstack/networking/v2/extensions/security/rules/testing/requests_test.go

Changes:
    openstack/blockstorage/v3/manageablevolumes/testing/fixtures_test.go
    openstack/blockstorage/v3/manageablevolumes/testing/requests_test.go
    openstack/blockstorage/v3/volumes/testing/fixtures_test.go
    openstack/blockstorage/v3/volumes/testing/requests_test.go
    openstack/networking/v2/extensions/security/addressgroups/testing/requests_test.go

NOTE(stephenfin): Conflicts are generally due to tests or test files
that don't exist on the v2 branch. Changes are due to tests that have
been removed or moved on the main branch.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit eed41cd)
I don't know why this isn't the default behavior, but relying on test
order is a bad idea (TM) that we should do our best to avoid.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 9251e99)
We do not need to check the validity of the provided opts more than once
so don't. We can also simplify our handling of multiple endpoints
(though not as much as we'd like in the v2 case, due to forthcoming
patches).

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 4329495)
We will use this to do proper discovery across multiple versions.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit bae4c6f)
This retrieves the base endpoint without stripping the version information.
This is helpful for service catalog entries that include project IDs, like
those historically preferred by Cinder for some reason.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 2bf97ce)
This is an re-implementation of GetSupportedMicroversions that supports
use with a ProviderClient and an explicit endpoint URL, allowing us to
use this during discovery.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 8cbcb2f)
For now these are exact duplicates of the V2EndpointURL and V3EndpointURL
helpers but with different names.

  diff -u openstack/endpoint_location.go openstack/endpoint.go

This is done to ease review. We will introduce further differences shortly.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit ed23d9b)
This is simpler than expected. Effectively, for each potential endpoint,
we retrieve the version document from the root URL and parse the version
information, if any, from it, comparing it against the version expected.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit f28c963)
Avoid unnecessary lookups for when we are encoding the version in our
service type.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 07d1ee0)
And deprecate the old ones since they are no longer used.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 8139f99)
Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 82c2ca0)
Ahead of the addition of some new tests.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 774a8b8)
Right now these are effectively duplicates of the tests for
GetSupportedMicroversions, which is also expanded here to test against
the version documents of other services, but that will change shortly.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 9c18abd)
In commit f28c963, we added support for
discovering API versions. To do this, we added a dependency on the
'version' and 'min_version' headers, which are used by services with
microversion support to document the maximum and minimum API versions
supported, respectively. However, not all services support API
microversions: services like Glance and Designate use API versions as a
signal of a new feature (or, in Glance's case, as a signal that a
feature is not enabled), others like Keystone just support a single
version, while Neutron does its own thing with API extensions [1]. Given
this fact, relying on these fields is a mistake.

Instead, we should be relying on the 'id' field. Per the api-sig
guidelines [2], this should be the API major version [3]. We continue
parsing the microversion-related headers, since it will be useful later
on if/when we want to do versioned discovery.

[1] https://that.guru/blog/api-versioning-in-openstack/
[2] https://specs.openstack.org/openstack/api-sig/guidelines/discoverability.html
[3] The studious among you may notice that the api-sig guidelines
    indicate that the maximum API microversion should be exposed via the
    'max_version' header. However, in practice, virtually everyone uses
    'version' instead. Why? Who knows. Best to just take these things on
    the chin and move on with our lives.
[4] The term "major version" is a bit loaded. Consider Nova: at the time
    of writing, it exposes two "major versions": v2.0 and v2.1. v2.0
    does not support microversions. v2.1 does. For v2.1 you therefore
    also have microversions to content with and at the time of writing
    it supports a minimum microversion of 2.1 and a maximum microversion
    of 2.100 (no 'v' prefix here). Normalizing these as we've done here
    gives us a major version of 2, a minor version of 1, a major maximum
    microversion of 2, a minor maximum microversion of 100, a major
    minimum microversion of 2, and a minor minimum microversion of 1 🤯.

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 5b89285)
While the expected format of these documents is defined by a spec [1],
most services do things slightly differently. Here, we add support for
the Keystone and Barbican-style documents, which embed version objects
inside another object with a single 'values' key, like so:

  {"versions": {"values": [{"id": "v3.14", ...}]}}

And the Magnum-style document, which doesn't envelope individual version
objects at all:

  {"id": "v2", ...}

These are in contrast to the format used by Nova, Cinder etc.:

  {"versions": [{"id": "v2", ...}]}

We also add support for 'max_version' key, which is used by Magnum and
is what the spec actually recommends.

[1] https://specs.openstack.org/openstack/api-sig/guidelines/discoverability.html

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 6e92c22)
Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit 37ec207)
Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit b6be984)
The 'vlan-transparent' extension is now enabled by default [1]. This is
highlighting a bug in the aforementioned test: namely, that we are
trying to update an attribute which is read-only [2]. Remove the update
step of the job and fix the test.

[1] openstack/neutron@11ff4f2
[2] https://github.com/openstack/neutron-lib/blob/fd011c955dfae1072555c69b6ba742b85f041736/neutron_lib/api/definitions/vlantransparent.py#L49

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit a574a3e)
@github-actions github-actions bot added edit:networking This PR updates networking code edit:openstack This PR updates common OpenStack code edit:dns This PR updates dns code edit:common This PR updates common code edit:actions This PR updates GitHub Actions code edit:image This PR updates image code labels Jun 19, 2025
@github-actions github-actions bot added edit:orchestration This PR updates orchestration code edit:db This PR updates db code edit:loadbalancer This PR updates loadbalancer code edit:compute This PR updates compute code edit:keymanager This PR updates keymanager code edit:utils This PR updates utils code v2 This PR targets v2 edit:messaging This PR updates messaging code edit:containerinfra This PR updates containerinfra code edit:placement This PR updates placement code edit:objectstorage This PR updates objectstorage code edit:workflow This PR updates workflow code edit:sharedfilesystems This PR updates sharedfilesystems code edit:baremetal This PR updates baremetal code edit:gophercloud This PR updates common Gophercloud code edit:blockstorage This PR updates blockstorage code edit:identity This PR updates identity code edit:container This PR updates container code edit:baremetalintrospection This PR updates baremetalintrospection code edit:testinfra This PR updates testing infrastructure code semver:major Breaking change labels Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edit:actions This PR updates GitHub Actions code edit:baremetal This PR updates baremetal code edit:baremetalintrospection This PR updates baremetalintrospection code edit:blockstorage This PR updates blockstorage code edit:common This PR updates common code edit:compute This PR updates compute code edit:container This PR updates container code edit:containerinfra This PR updates containerinfra code edit:db This PR updates db code edit:dns This PR updates dns code edit:gophercloud This PR updates common Gophercloud code edit:identity This PR updates identity code edit:image This PR updates image code edit:keymanager This PR updates keymanager code edit:loadbalancer This PR updates loadbalancer code edit:messaging This PR updates messaging code edit:networking This PR updates networking code edit:objectstorage This PR updates objectstorage code edit:openstack This PR updates common OpenStack code edit:orchestration This PR updates orchestration code edit:placement This PR updates placement code edit:sharedfilesystems This PR updates sharedfilesystems code edit:testinfra This PR updates testing infrastructure code edit:utils This PR updates utils code edit:workflow This PR updates workflow code semver:major Breaking change v2 This PR targets v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants