From 5ad97dfc197e3be5c69e7b991979082ea09093b6 Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Thu, 18 Aug 2022 21:55:13 -0400 Subject: [PATCH] Adding Error Log Adds error logging to the return in the event of a failure. Sets the timeout for connect to a modest value instead of > 2 minutes. Signed-off-by: Mark Beierl --- .../charms/ops/openldap-operator/src/charm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openldap_primitives_knf/charms/ops/openldap-operator/src/charm.py b/openldap_primitives_knf/charms/ops/openldap-operator/src/charm.py index 0b1d9ae4..fb31d77a 100755 --- a/openldap_primitives_knf/charms/ops/openldap-operator/src/charm.py +++ b/openldap_primitives_knf/charms/ops/openldap-operator/src/charm.py @@ -53,7 +53,7 @@ class Ldap: self.connection = None def _connect(self): - server = Server(self.ldap_uri, get_info=ALL) + server = Server(self.ldap_uri, get_info=ALL, connect_timeout=10) self.connection = Connection( server, user="cn=admin,dc=example,dc=org", password="admin" ) @@ -105,17 +105,21 @@ class OpenldapOperatorCharm(CharmBase): dc_param = event.params["dc"] cn = f"cn={cn_param}" dc = ",".join([f"dc={dc_component}" for dc_component in dc_param.split(".")]) + result = "" try: openldap_service = self.osm_config.get_service("stable-openldap") ldap_uri = ( f'ldap://{openldap_service.ip}:{openldap_service.get_port("ldap-port")}' ) ldap = Ldap(ldap_uri) - user_info = ldap.get_user_info(cn, dc) - event.set_results({"output": user_info}) + result = ldap.get_user_info(cn, dc) except Exception as e: + result = e + logger.error(e) event.fail(f"Failed getting user info: {e}") + event.set_results({"output": result}) + if __name__ == "__main__": main(OpenldapOperatorCharm) -- GitLab