From: Guillaume Abrioux Date: Thu, 23 Nov 2023 16:08:18 +0000 (+0000) Subject: node-proxy: raise HTTPError 404 error when no host is found X-Git-Tag: v19.3.0~102^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5cb8f2af44ea587f3c85d72bee385f571e6cc2cb;p=ceph.git node-proxy: raise HTTPError 404 error when no host is found Raise a 404 HTTPError when these differents endpoints are passed an inexisting hostname. Otherwise the code will fail with a `KeyError` exception. Signed-off-by: Guillaume Abrioux --- diff --git a/src/pybind/mgr/cephadm/agent.py b/src/pybind/mgr/cephadm/agent.py index b8453f719af8..316cc7c0da30 100644 --- a/src/pybind/mgr/cephadm/agent.py +++ b/src/pybind/mgr/cephadm/agent.py @@ -358,8 +358,14 @@ class NodeProxy: :return: The full report data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.fullreport(**kw) + try: + results = self.mgr.node_proxy.fullreport(**kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -376,8 +382,14 @@ class NodeProxy: :return: Critical information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.criticals(**kw) + try: + results = self.mgr.node_proxy.criticals(**kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -394,8 +406,14 @@ class NodeProxy: :return: Summary information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.summary(**kw) + try: + results = self.mgr.node_proxy.summary(**kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -413,8 +431,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('memory', **kw) + try: + results = self.mgr.node_proxy.common('memory', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -432,8 +456,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('network', **kw) + try: + results = self.mgr.node_proxy.common('network', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -451,8 +481,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('processors', **kw) + try: + results = self.mgr.node_proxy.common('processors', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -470,8 +506,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('storage', **kw) + try: + results = self.mgr.node_proxy.common('storage', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -489,8 +531,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('power', **kw) + try: + results = self.mgr.node_proxy.common('power', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -508,8 +556,14 @@ class NodeProxy: :return: Specific information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.common('fans', **kw) + try: + results = self.mgr.node_proxy.common('fans', **kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results @cherrypy.expose @cherrypy.tools.allow(methods=['GET']) @@ -526,8 +580,14 @@ class NodeProxy: :return: Firmware information data. :rtype: dict[str, Any] + + :raises cherrypy.HTTPError 404: If the passed hostname is not found. """ - return self.mgr.node_proxy.firmwares(**kw) + try: + results = self.mgr.node_proxy.firmwares(**kw) + except KeyError: + raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.") + return results class HostData(Server):