From 22b96bc26f29d69042bf71783d1a6543f4d0d0a7 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Thu, 14 Sep 2023 16:08:26 +0000 Subject: [PATCH] node-proxy: update reporter agent This commit introduces the required changes in order to make the reporter agent query the new mgr endpoint '/node-proxy/data' Signed-off-by: Guillaume Abrioux (cherry picked from commit 9a305c5c8e94e12b6c103b3b3f4201f4fc3616c9) --- src/cephadm/cephadm.py | 3 ++- src/cephadm/cephadmlib/node_proxy/reporter.py | 13 ++++++++----- src/cephadm/cephadmlib/node_proxy/server.py | 7 +++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 236d46ded21..81149b342ef 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4931,7 +4931,8 @@ WantedBy=ceph-{fsid}.target t_node_proxy = Thread(target=cephadmlib.node_proxy.server.main, kwargs={'host': result_json['result']['addr'], 'username': result_json['result']['username'], - 'password': result_json['result']['password']) + 'password': result_json['result']['password'], + 'data': node_proxy_data}) t_node_proxy.start() try: diff --git a/src/cephadm/cephadmlib/node_proxy/reporter.py b/src/cephadm/cephadmlib/node_proxy/reporter.py index 43b57388e3b..380884dc5b4 100644 --- a/src/cephadm/cephadmlib/node_proxy/reporter.py +++ b/src/cephadm/cephadmlib/node_proxy/reporter.py @@ -2,16 +2,17 @@ from threading import Thread import requests import time from .util import Logger -from typing import Any +from typing import Dict, Any log = Logger(__name__) class Reporter: - def __init__(self, system: Any, observer_url: str) -> None: + def __init__(self, system: Any, data: Dict[str, Any], observer_url: str) -> None: self.system = system self.observer_url = observer_url self.finish = False + self.data = data def stop(self) -> None: self.finish = True @@ -35,11 +36,13 @@ class Reporter: log.logger.info('data ready to be sent to the mgr.') if not self.system.get_system() == self.system.previous_data: log.logger.info('data has changed since last iteration.') - d = self.system.get_system() + self.data['data'] = self.system.get_system() try: # TODO: add a timeout parameter to the reporter in the config file - requests.post(f"{self.observer_url}/", json=d, timeout=5) - except requests.exceptions.RequestException as e: + log.logger.info(f"sending data to {self.observer_url}") + r = requests.post(f"{self.observer_url}", json=self.data, timeout=5, verify=False) + except (requests.exceptions.RequestException, + requests.exceptions.ConnectionError) as e: log.logger.error(f"The reporter couldn't send data to the mgr: {e}") # Need to add a new parameter 'max_retries' to the reporter if it can't # send the data for more than x times, maybe the daemon should stop altogether diff --git a/src/cephadm/cephadmlib/node_proxy/server.py b/src/cephadm/cephadmlib/node_proxy/server.py index b3c2306d88f..18cfedb0501 100644 --- a/src/cephadm/cephadmlib/node_proxy/server.py +++ b/src/cephadm/cephadmlib/node_proxy/server.py @@ -6,6 +6,7 @@ from typing import Dict from .basesystem import BaseSystem import sys import argparse +import json DEFAULT_CONFIG = { 'reporter': { @@ -188,7 +189,8 @@ class API: def main(host: str = '', username: str = '', - password: str = '') -> None: + password: str = '', + data: str = '') -> None: # TODO: add a check and fail if host/username/password/data aren't passed # parser = argparse.ArgumentParser( @@ -210,6 +212,7 @@ def main(host: str = '', host = host username = username password = password + data = json.loads(data) # create the redfish system and the obsever log.logger.info("Server initialization...") @@ -218,7 +221,7 @@ def main(host: str = '', password=password, system_endpoint='/Systems/System.Embedded.1', config=config) - reporter_agent = Reporter(system, config.__dict__['reporter']['endpoint']) + reporter_agent = Reporter(system, data, config.__dict__['reporter']['endpoint']) cherrypy.config.update({ 'node_proxy': config, 'server.socket_port': config.__dict__['server']['port'] -- 2.39.5