]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: encapsulate send logic in dedicated method
authorGuillaume Abrioux <gabrioux@ibm.com>
Thu, 5 Feb 2026 09:01:06 +0000 (10:01 +0100)
committerGuillaume Abrioux <gabrioux@ibm.com>
Wed, 18 Feb 2026 08:52:38 +0000 (09:52 +0100)
Move the "send data to mgr when inventory changed" logic from main()
into a dedicated method _try_send_update().
This flattens the reporter loop and keeps main() to a single call under
the lock.

Fixes: https://tracker.ceph.com/issues/74749
Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
src/ceph-node-proxy/ceph_node_proxy/reporter.py

index da4f4b2f9d331132292773bd5375e5053cb0ad6c..b7c1c82efc945fff47c6bd3e55668640080fa24d 100644 (file)
@@ -85,6 +85,25 @@ class Reporter(BaseThread):
             # which is by definition big so we don't log it as it would be too verbose
             self.log.info("first data received from the system.")
 
+    def _try_send_update(self) -> None:
+        """Send data to mgr if system data has changed. Caller must hold system.lock."""
+        if not self.system.data_ready:
+            return
+        self.log.debug("data ready to be sent to the mgr.")
+        current = self.system.get_system()
+        if current == self.system.previous_data:
+            self.log.debug("no diff, not sending data to the mgr.")
+            return
+        self._log_data_delta(current)
+        self.data["patch"] = current
+        if self._send_with_retries():
+            self.system.previous_data = current
+        else:
+            self.log.error(
+                f"Failed to send data after {self.max_retries} retries; "
+                "will retry on next cycle."
+            )
+
     def main(self) -> None:
         last_heartbeat = time.monotonic()
         while not self.stop:
@@ -92,21 +111,7 @@ class Reporter(BaseThread):
             with self.system.lock:
                 if not self.system.pending_shutdown:
                     self.log.debug("lock acquired in reporter loop.")
-                    if self.system.data_ready:
-                        self.log.debug("data ready to be sent to the mgr.")
-                        if self.system.get_system() != self.system.previous_data:
-                            new_data = self.system.get_system()
-                            self._log_data_delta(new_data)
-                            self.data["patch"] = new_data
-                            if self._send_with_retries():
-                                self.system.previous_data = new_data
-                            else:
-                                self.log.error(
-                                    f"Failed to send data after {self.max_retries} retries; "
-                                    "will retry on next cycle."
-                                )
-                        else:
-                            self.log.debug("no diff, not sending data to the mgr.")
+                    self._try_send_update()
             self.log.debug("lock released in reporter loop.")
             now = time.monotonic()
             if now - last_heartbeat >= HEARTBEAT_INTERVAL_SEC: