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 a2332a22..03551c9b 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 @@ -30,7 +30,7 @@ class IsolationMgr: def __init__(self, ufm_client: UFMCommunicator, logger): self.ufm_client = ufm_client # {port_name: IsolatedPort} - self.ports_states = {} + self.isolated_ports = {} # {port_name: telemetry_data} self.ports_data = {} self.ufm_latest_isolation_state = [] @@ -84,10 +84,10 @@ def eval_isolation(self, port_name, cause): if not ret or ret.status_code != http.HTTPStatus.OK: self.logger.warning("Failed isolating port: %s with cause: %s... status_code= %s", port_name, cause, ret.status_code) return - port_state = self.ports_states.get(port_name) - if not port_state: - self.ports_states[port_name] = IsolatedPort(port_name) - self.ports_states[port_name].update(cause) + isolated_port = self.isolated_ports.get(port_name) + if not isolated_port: + self.isolated_ports[port_name] = IsolatedPort(port_name) + self.isolated_ports[port_name].update(cause) log_message = f"Isolated port: {port_name} cause: {cause}. dry_run: {self.dry_run}" self.logger.warning(log_message) @@ -111,8 +111,8 @@ def eval_deisolate(self, port_name): self.logger.info(f"Evaluating deisolation of port {port_name}") if not port_name in self.ufm_latest_isolation_state and not self.dry_run: - if self.ports_states.get(port_name): - self.ports_states.pop(port_name) + if self.isolated_ports.get(port_name): + self.isolated_ports.pop(port_name) return # port is clean now - de-isolate it @@ -127,9 +127,9 @@ def eval_deisolate(self, port_name): ret = self.ufm_client.deisolate_port(port_name) if not ret or ret.status_code != http.HTTPStatus.OK: self.logger.warning("Failed deisolating port: %s with cause: %s... status_code= %s",\ - port_name, self.ports_states[port_name].cause, ret.status_code) + port_name, self.isolated_ports[port_name].cause, ret.status_code) return - self.ports_states.pop(port_name) + self.isolated_ports.pop(port_name) log_message = f"Deisolated port: {port_name}. dry_run: {self.dry_run}" self.logger.warning(log_message) if not self.test_mode: @@ -218,13 +218,13 @@ def get_isolation_state(self): ports = self.ufm_client.get_isolated_ports() if not ports: self.ufm_latest_isolation_state = [] - isolated_ports = [port.split('x')[-1] for port in ports.get(Constants.API_ISOLATED_PORTS, [])] - self.ufm_latest_isolation_state = isolated_ports - for port in isolated_ports: - if not self.ports_states.get(port): - port_state = IsolatedPort(port) - port_state.update(Constants.ISSUE_OONOC) - self.ports_states[port] = port_state + isolated_port_names = [port.split('x')[-1] for port in ports.get(Constants.API_ISOLATED_PORTS, [])] + self.ufm_latest_isolation_state = isolated_port_names + for port_name in isolated_port_names: + if not self.isolated_ports.get(port_name): + isolated_port = IsolatedPort(port_name) + isolated_port.update(Constants.ISSUE_OONOC) + self.isolated_ports[port_name] = isolated_port def get_requested_guids(self): """ @@ -304,9 +304,9 @@ def main_flow(self): # deisolate ports if self.do_deisolate: - for port_state in list(self.ports_states.values()): - if self.pdr_alg.check_deisolation_conditions(port_state): - self.eval_deisolate(port_state.name) + for isolated_port in list(self.isolated_ports.values()): + if self.pdr_alg.check_deisolation_conditions(isolated_port): + self.eval_deisolate(isolated_port.name) ports_updated = self.update_ports_data() if ports_updated: self.update_telemetry_session() diff --git a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/pdr_algorithm.py b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/pdr_algorithm.py index 832f3397..dec6207b 100644 --- a/plugins/pdr_deterministic_plugin/ufm_sim_web_service/pdr_algorithm.py +++ b/plugins/pdr_deterministic_plugin/ufm_sim_web_service/pdr_algorithm.py @@ -436,13 +436,13 @@ def analyze_telemetry_data(self, ports_data, ports_counters): issues[port_name] = Constants.ISSUE_OONOC return list(issues.values()) - def check_deisolation_conditions(self, port_state): + def check_deisolation_conditions(self, isolated_port): """ Check if given port should be deisolated Function doesn't perform deisolation itself, just checks deisolation conditions only Return True if given port should be deisolated """ - cause = port_state.get_cause() + cause = isolated_port.get_cause() # EZ: it is a state that say that some maintenance was done to the link # so need to re-evaluate if to return it to service # Deal with ports that with either cause = oonoc or fixed @@ -450,22 +450,22 @@ def check_deisolation_conditions(self, port_state): return False # We don't deisolate those out of NOC - port_name = port_state.name + port_name = isolated_port.name if self.is_out_of_operating_conf(port_name): return False - if datetime.now() < port_state.get_change_time() + timedelta(seconds=self.deisolate_consider_time): + if datetime.now() < isolated_port.get_change_time() + timedelta(seconds=self.deisolate_consider_time): # Too close to state change return False # TODO: check if it can be moved into BER issue detection port_obj = self.ports_data.get(port_name) - if port_state.cause == Constants.ISSUE_BER: + if isolated_port.cause == Constants.ISSUE_BER: # Check if we are still above the threshold symbol_ber_rate = self.calc_ber_rates(port_name, port_obj.active_speed, port_obj.port_width, self.max_ber_wait_time + 1) if symbol_ber_rate and symbol_ber_rate > self.max_ber_threshold: cause = Constants.ISSUE_BER - port_state.update(cause) + isolated_port.update(cause) return False return True