Repository navigation
site env / endpoint env: add --with-region to export OS_REGION_NAME - #250
Open
giannidallatorre wants to merge 4 commits into
Open
giannidallatorre wants to merge 4 commits into
giannidallatorre wants to merge 4 commits into
Conversation
The region is not part of the site configuration, so the only place it can be read from is the service catalog of a scoped token, which get_scoped_token() already receives and discards. Tools that need an explicit region, e.g. the OpenStack Terraform provider, have to guess it today, and a wrong guess fails with "No suitable endpoint could be found in the service catalog", which does not mention the region at all. The flag is opt-in: "site env" makes no Keystone call at all at the moment, and making the region mandatory would turn it into a command that fails when the token is expired, which is exactly when people run it. With the flag, a failing Keystone call is a warning on stderr and the environment is still generated. get_scoped_token() now returns the region as a third element, so "endpoint env" gets it for free from the call it already makes. Closes tdviet#249
get_unscoped_token() is documented to try all protocols, but it only catches RuntimeError while retrieve_unscoped_token() raises TokenException, so the fallback to the oidc protocol never happened. Sites that do not support openid could not be reached at all, which also means the region could not be read from their catalog. The error raised when no protocol works is now the unscoped one, which is what actually failed.
The request for a scoped token had no timeout, unlike the request for an unscoped one, so a Keystone that accepts the connection and never answers blocked the command forever. This matters more now that "site env" can make that call: the command used to be local and instant.
Cover the decision that makes the flag opt-in: without it, "site env" must not call Keystone at all. Also check the position of OS_REGION_NAME in the output and that an unknown region is a warning, not an error.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #249.
What.
fedcloud site envandfedcloud endpoint envcan now exportOS_REGION_NAME, behind an opt-in--with-regionflag:Why opt-in. The region is not in the site configuration, so the only place it can be read from is the service catalog of a scoped token.
site envmakes no Keystone call today; making the region mandatory would turn it into a command that fails when the token is expired — which is exactly when people run it. With the flag, a failing Keystone call is a warning on stderr and the environment is still generated.How.
get_region_from_token(token_body): pure helper, returns the firstregion_id(orregion) in the catalog,Noneif there is none.get_scoped_token()returns it as a third element, soendpoint envgets it for free from the call it already makes;endpoint tokenignores it.get_region_from_site(): the Keystone call forsite env, with failures downgraded to warnings.sites.pyimports it insideenv(), becauseendpoint.pyalready importssites.pyand a top-level import would be circular.Two fixes needed to make this work outside the happy path. Testing the flag against a fake Keystone turned up two pre-existing problems that would have made it silently useless on some sites, so they are in separate commits:
get_unscoped_token()is documented to try all protocols, but it only caughtRuntimeErrorwhileretrieve_unscoped_token()raisesTokenException, so the fallback tooidcnever ran. Sites that do not supportopenidcould not be reached at all, and therefore no region. The error raised when no protocol works is now the unscoped one, which is what actually failed.site envcan make that call, since the command used to be local and instant.Testing. New
fedcloudclient/endpoint_test.py(10 tests) andfedcloudclient/sites_test.py(3 tests), no network: single region, multiple regions (first wins),regioninstead ofregion_id, token body without any region,get_scoped_token()returning the region (mockedrequests.post, timeout included), theoidcfallback, a failing Keystone call producing a warning instead of an exception, and — the reason the flag is opt-in — thatsite envwithout--with-regionnever calls Keystone.pytest: 19 passed.flake8with the CI flags: clean.Also checked end-to-end against a fake Keystone, one mode per failure: normal site,
oidc-only site, expired token, connection refused, catalog without region, two regions, project not accessible (403), Keystone that never answers. In every failure case the environment is still printed and the reason goes to stderr:Open question (from #249): in
endpoint envthe token body is already in hand, so the region is free there — should it be printed always, without the flag? I kept it behind the flag for consistency withsite env; happy to change it.CHANGELOG not touched (last entry 1.2.9).