From 05cc6afe4b76d35f549bb8928e459bc8fb93697c Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Fri, 29 Sep 2023 13:05:31 +0000 Subject: [PATCH] node-proxy: validate_node_proxy_data() refactor This introduces minor changes in order to improve error handling in validate_node_proxy_data() Signed-off-by: Guillaume Abrioux --- src/pybind/mgr/cephadm/agent.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/cephadm/agent.py b/src/pybind/mgr/cephadm/agent.py index 2c99149998c..0228d73f828 100644 --- a/src/pybind/mgr/cephadm/agent.py +++ b/src/pybind/mgr/cephadm/agent.py @@ -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 -- 2.39.5