Commit 5ad97dfc authored by Mark Beierl's avatar Mark Beierl
Browse files

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: default avatarMark Beierl <mark.beierl@canonical.com>
parent 5fedfaf3
Loading
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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)