Skip to content

site env / endpoint env: add --with-region to export OS_REGION_NAME - #250

Open
giannidallatorre wants to merge 4 commits into
tdviet:masterfrom
giannidallatorre:with-region
Open

giannidallatorre wants to merge 4 commits into
tdviet:masterfrom
giannidallatorre:with-region

Conversation

@giannidallatorre

Copy link
Copy Markdown

Closes #249.

What. fedcloud site env and fedcloud endpoint env can now export OS_REGION_NAME, behind an opt-in --with-region flag:

$ fedcloud site env --site IN2P3-IRES --vo vo.access.egi.eu --with-region
export OS_AUTH_URL="https://sbgcloud.in2p3.fr:5000/v3/";
export OS_AUTH_TYPE="v3oidcaccesstoken";
export OS_IDENTITY_PROVIDER="egi.eu";
export OS_PROTOCOL="openid";
export OS_PROJECT_ID="7a91022b9ae74ed9ac1a574972a79499";
export OS_REGION_NAME="IPHC";
export OS_ACCESS_TOKEN="...";

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 env makes 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 first region_id (or region) in the catalog, None if there is none.
  • get_scoped_token() returns it as a third element, so endpoint env gets it for free from the call it already makes; endpoint token ignores it.
  • get_region_from_site(): the Keystone call for site env, with failures downgraded to warnings.
  • sites.py imports it inside env(), because endpoint.py already imports sites.py and 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 caught RuntimeError while retrieve_unscoped_token() raises TokenException, so the fallback to oidc never ran. Sites that do not support openid could 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.
  • The scoped token request had no timeout, unlike the unscoped one: a Keystone that accepts the connection and never answers blocked the command forever. That matters more now that site env can make that call, since the command used to be local and instant.

Testing. New fedcloudclient/endpoint_test.py (10 tests) and fedcloudclient/sites_test.py (3 tests), no network: single region, multiple regions (first wins), region instead of region_id, token body without any region, get_scoped_token() returning the region (mocked requests.post, timeout included), the oidc fallback, a failing Keystone call producing a warning instead of an exception, and — the reason the flag is opt-in — that site env without --with-region never calls Keystone. pytest: 19 passed. flake8 with 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:

[WARN] Unable to get region: Unable to get an unscoped token

Open question (from #249): in endpoint env the 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 with site env; happy to change it.

CHANGELOG not touched (last entry 1.2.9).

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

No deployments
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.

site env / endpoint env: export OS_REGION_NAME

1 participant