]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: update reporter agent
authorGuillaume Abrioux <gabrioux@ibm.com>
Thu, 14 Sep 2023 16:08:26 +0000 (16:08 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 14:54:13 +0000 (14:54 +0000)
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 <gabrioux@ibm.com>
(cherry picked from commit 9a305c5c8e94e12b6c103b3b3f4201f4fc3616c9)

src/cephadm/cephadm.py
src/cephadm/cephadmlib/node_proxy/reporter.py
src/cephadm/cephadmlib/node_proxy/server.py

index 236d46ded21490c9f45cbb9f81f3a355a5a2ed0b..81149b342efc480ce382e5ab86280f0519a84458 100755 (executable)
@@ -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:
index 43b57388e3b016e67277e0c4e9a2e2dfdc685b93..380884dc5b40f642e103f92efbf54be6ae3cc16f 100644 (file)
@@ -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
index b3c2306d88fcea3b529a9c11b6fac69720b240f9..18cfedb05012969847e6fa37d64d77493da6de77 100644 (file)
@@ -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']