diff --git a/openstack_operator/identity.py b/openstack_operator/identity.py index a07931b1..38e99007 100644 --- a/openstack_operator/identity.py +++ b/openstack_operator/identity.py @@ -17,8 +17,6 @@ This module contains a few common functions for identity management """ -import kopf - from openstack_operator import utils @@ -32,22 +30,19 @@ def ensure_service(name, service_type, desc, url=None, path=""): path: sub path of endpoint """ - try: - # Create or resume service - utils.create_or_update('identity/service.yml.j2', name=name, - type=service_type, description=desc) + # Create or resume service + utils.create_or_update('identity/service.yml.j2', name=name, + type=service_type, description=desc) - # Create or resume endpoints - internal_url = public_url = \ - "http://" + name + ".openstack.svc.cluster.local" + path + # Create or resume endpoints + internal_url = public_url = \ + "http://" + name + ".openstack.svc.cluster.local" + path - if url is not None: - public_url = "https://" + url + path - utils.create_or_update('identity/endpoint.yml.j2', - service=service_type, interface='internal', - url=internal_url) - utils.create_or_update('identity/endpoint.yml.j2', - service=service_type, interface='public', - url=public_url) - except Exception as ex: - raise kopf.TemporaryError(str(ex), delay=5) + if url is not None: + public_url = "https://" + url + path + utils.create_or_update('identity/endpoint.yml.j2', + service=service_type, interface='internal', + url=internal_url) + utils.create_or_update('identity/endpoint.yml.j2', + service=service_type, interface='public', + url=public_url) diff --git a/openstack_operator/openstack/identity/endpoints.py b/openstack_operator/openstack/identity/endpoints.py index 2b4bdc2f..8a4e808c 100644 --- a/openstack_operator/openstack/identity/endpoints.py +++ b/openstack_operator/openstack/identity/endpoints.py @@ -25,7 +25,10 @@ from openstack_operator import utils def _get_service_by_type(conn, service_type): """Get a service from Keystone based on service type.""" - services = conn.search_services(filters={"type": service_type}) + try: + services = conn.search_services(filters={"type": service_type}) + except Exception as ex: + raise kopf.TemporaryError(str(ex), delay=5) if len(services) > 1: raise RuntimeError("Multiple services with type: %s" % service_type) diff --git a/openstack_operator/openstack/identity/services.py b/openstack_operator/openstack/identity/services.py index a4f8c99a..41a964f9 100644 --- a/openstack_operator/openstack/identity/services.py +++ b/openstack_operator/openstack/identity/services.py @@ -30,8 +30,11 @@ def _get_service(conn, name, service_type): found more than one or return None if it couldn't find it """ - services = conn.search_services(name_or_id=name, - filters={"type": service_type}) + try: + services = conn.search_services(name_or_id=name, + filters={"type": service_type}) + except ConnectionRefusedError: + raise kopf.TemporaryError("Keystone is not up yet", delay=5) if len(services) > 1: raise RuntimeError("Found multiple services with name and type")