]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: validate_node_proxy_data() refactor
authorGuillaume Abrioux <gabrioux@ibm.com>
Fri, 29 Sep 2023 13:05:31 +0000 (13:05 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 14:55:15 +0000 (14:55 +0000)
This introduces minor changes in order to improve error
handling in validate_node_proxy_data()

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
(cherry picked from commit 05cc6afe4b76d35f549bb8928e459bc8fb93697c)

src/pybind/mgr/cephadm/agent.py

index 2c99149998c26fa0cde33672c5c726687b6eea6d..0228d73f8285bcde1860359a4f873642e183e5a2 100644 (file)
@@ -117,24 +117,26 @@ class NodeProxy:
             idrac_details = self.mgr.get_store('node_proxy/idrac')
             idrac_details_json = json.loads(idrac_details)
             results['result'] = idrac_details_json[data["host"]]
+        else:
+            results['result'] = self.validate_msg
 
         return results
 
     def validate_node_proxy_data(self, data: Dict[str, Any]) -> bool:
+        self.validate_msg = 'valid node-proxy data received.'
+        cherrypy.response.status = 200
         if 'host' not in data:
             cherrypy.response.status = 400
-            self.mgr.log.warning('The field \'host\' must be provided.')
+            self.validate_msg = 'The field \'host\' must be provided.'
         elif 'keyring' not in data:
             cherrypy.response.status = 400
-            self.mgr.log.warning(f'The agent keyring must be provided.')
+            self.validate_msg = 'The agent keyring must be provided.'
         elif not self.mgr.agent_cache.agent_keys.get(data['host']):
             cherrypy.response.status = 400
-            self.mgr.log.warning(f'Make sure the agent is running on {data["host"]}')
+            self.validate_msg = f'Make sure the agent is running on {data["host"]}'
         elif data['keyring'] != self.mgr.agent_cache.agent_keys[data['host']]:
             cherrypy.response.status = 403
-            self.mgr.log.warning(f'Got wrong keyring from agent on host {data["host"]}.')
-        else:
-            cherrypy.response.status = 200
+            self.validate_msg = f'Got wrong keyring from agent on host {data["host"]}.'
 
         return cherrypy.response.status == 200
 
@@ -199,7 +201,7 @@ class NodeProxy:
             self.mgr.set_store(f'node_proxy/data/{data["host"]}', json.dumps(data['data']))
             self.raise_alert(data)
 
-            results['result'] = data
+        results["result"] = self.validate_msg
 
         return results