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

Make wait_for_endpoints more robust. #1172

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions zaza/openstack/charm_tests/keystone/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,34 @@ def wait_for_url(url, ok_codes=None):
assert r.status_code in ok_codes


def wait_for_client():
Copy link
Member

@freyes freyes Dec 1, 2023

Choose a reason for hiding this comment

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

nitpick: the function's name is a bit strange ... it's waiting, but also returning a value ... the "waiting" seems to be irrelevant from the caller's perspective, why not call it "get_keystone_client"?, or maybe re-use get_keystone_client()[0] and wrap that one with a retry() decorator?, if there is a concern about the retry on a core function like this one, the number of retries could be an argument that defaults to 1

[0] https://github.com/openstack-charmers/zaza-openstack-tests/blob/master/zaza/openstack/utilities/openstack.py#L616

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that the function's name is wrong. I don't think that get_keystone_client() can be used as it seems more basic that this function; i.e. it's using overcloud auth rather than openrc.

I think this function ought to be in z.o.utilities.openstack.py though along with the other keystone client functions which would also open a space for refactoring at a future point.

Finally, the wait_for_url() function is also really generic and probably could also live in a utility module; the wait_for_all_endpoints() a bit more arguable as to where it should go. It's specific enother to be testing keystone ... but also generic enough that other tests might also want to wait on the endpoints being available as a utility.

"""Wait for client to be returned successfully.

If keystone is still in a transient state then it may take a few retries
before a client is returned
"""
for attempt in tenacity.Retrying(
stop=tenacity.stop_after_attempt(10),
wait=tenacity.wait_exponential(
multiplier=1, min=2, max=60)):
with attempt:
overcloud_auth = openstack_utils.get_overcloud_auth()
wait_for_url(overcloud_auth['OS_AUTH_URL'])
session = openstack_utils.get_overcloud_keystone_session()
keystone_client = openstack_utils.get_keystone_session_client(
session)

return keystone_client


def wait_for_all_endpoints(interface='public'):
"""Check all endpoints are returning an acceptable return code.

:param interface: Endpoint type to check. public, admin or internal
:type interface: str
:raises: AssertionError
"""
overcloud_auth = openstack_utils.get_overcloud_auth()
wait_for_url(overcloud_auth['OS_AUTH_URL'])
session = openstack_utils.get_overcloud_keystone_session()
keystone_client = openstack_utils.get_keystone_session_client(session)
keystone_client = wait_for_client()
for service in keystone_client.services.list():
for ep in keystone_client.endpoints.list(service=service,
interface=interface):
Expand Down
Loading