From 1263cc7f72405b904fcffc67a489423254fa9b6b Mon Sep 17 00:00:00 2001 From: tlerner Date: Mon, 26 Aug 2024 11:20:45 +0300 Subject: [PATCH] Revert "move get telemetry to it's own file" This reverts commit 03dd1a5837d4a304fd2ca5b9a58cf755617bcd82. --- .../ufm_sim_web_service/isolation_mgr.py | 4 +-- .../telemetry_collector.py | 28 ------------------- .../ufm_communication_mgr.py | 17 +++++++++++ 3 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 plugins/pdr_deterministic_plugin/ufm_sim_web_service/telemetry_collector.py diff --git a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_mgr.py b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_mgr.py index 3b9ffb46..20804fb0 100644 --- a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_mgr.py +++ b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/isolation_mgr.py @@ -22,7 +22,6 @@ from exclude_list import ExcludeList from constants import PDRConstants as Constants -from telemetry_collector import TelemetryCollector from ufm_communication_mgr import UFMCommunicator # should actually be persistent and thread safe dictionary pf PortStates @@ -194,7 +193,6 @@ def __init__(self, ufm_client: UFMCommunicator, logger): self.test_iteration = 0 # Take from Conf self.logger = logger - self.telemetry_collector = TelemetryCollector(self.test_mode) self.ber_intervals = Constants.BER_THRESHOLDS_INTERVALS if not self.test_mode else [[0.5 * 60, 3]] intervals = [x[0] for x in self.ber_intervals] self.min_ber_wait_time = min(intervals) @@ -530,7 +528,7 @@ def read_next_set_of_high_ber_or_pdr_ports(self): Read the next set of ports and check if they have high BER, PDR, temperature or link downed issues """ issues = {} - ports_counters = self.telemetry_collector.get_telemetry() + ports_counters = self.ufm_client.get_telemetry(self.test_mode) if ports_counters is None: self.logger.error("Couldn't retrieve telemetry data") return {} diff --git a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/telemetry_collector.py b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/telemetry_collector.py deleted file mode 100644 index 6f12931e..00000000 --- a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/telemetry_collector.py +++ /dev/null @@ -1,28 +0,0 @@ -import pandas as pd -from constants import PDRConstants as Constants -import logging -import urllib - - -class TelemetryCollector: - """ - Represent Telemetry collector which send DataFrame once telemetry is called. - """ - def __init__(self,test_mode) -> None: - self.test_mode=test_mode - - def get_telemetry(self): - """ - get the telemetry from secondary telemetry, if it in test mode it get from the simulation - return DataFrame of the telemetry - """ - if self.test_mode: - url = f"http://127.0.0.1:9090/csv/xcset/simulated_telemetry" - else: - url = f"http://127.0.0.1:{Constants.SECONDARY_TELEMETRY_PORT}/csv/xcset/{Constants.SECONDARY_INSTANCE}" - try: - telemetry_data = pd.read_csv(url) - except (pd.errors.ParserError, pd.errors.EmptyDataError, urllib.error.URLError) as e: - logging.error(f"Failed to get telemetry data from UFM, fetched url={url}. Error: {e}") - telemetry_data = None - return telemetry_data diff --git a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/ufm_communication_mgr.py b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/ufm_communication_mgr.py index bcb303df..3f2cfe33 100644 --- a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/ufm_communication_mgr.py +++ b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/ufm_communication_mgr.py @@ -55,6 +55,23 @@ def send_request(self, uri, data, method=Constants.POST_METHOD, headers=None): logging.info("UFM API Request Status: {}, URL: {}".format(response.status_code, request)) return response + def get_telemetry(self,test_mode): + """ + get the telemetry from secondary telemetry, if it in test mode it get from the simulation + return DataFrame of the telemetry + """ + if test_mode: + url = f"http://127.0.0.1:9090/csv/xcset/simulated_telemetry" + else: + url = f"http://127.0.0.1:{Constants.SECONDARY_TELEMETRY_PORT}/csv/xcset/{Constants.SECONDARY_INSTANCE}" + try: + telemetry_data = pd.read_csv(url) + except (pd.errors.ParserError, pd.errors.EmptyDataError, urllib.error.URLError) as e: + logging.error(f"Failed to get telemetry data from UFM, fetched url={url}. Error: {e}") + telemetry_data = None + return telemetry_data + + def send_event(self, message, event_id=Constants.EXTERNAL_EVENT_NOTICE, external_event_name="PDR Plugin Event", external_event_type="PDR Plugin Event"): data = { "event_id": event_id,