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 0b1d9ae4b196927bddfafcd5fc3e23a1dc9a4849..fb31d77a97926d9e8efb1ec501b5be31dfe3b4fe 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)