]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: raise HTTPError 404 error when no host is found
authorGuillaume Abrioux <gabrioux@ibm.com>
Thu, 23 Nov 2023 16:08:18 +0000 (16:08 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 15:16:01 +0000 (15:16 +0000)
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 <gabrioux@ibm.com>
(cherry picked from commit bda2568d8c73bbdc77897d22a99f74c1f4a23511)

src/pybind/mgr/cephadm/agent.py

index b8453f719af856d3ac8d2339a39cadbf80023854..316cc7c0da30b6dfd95454b2fd50c190265c28c3 100644 (file)
@@ -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):