From d863a2be8cc5292c1fa2392f44f1748394b350fe Mon Sep 17 00:00:00 2001 From: Aliaksandr Nikitsin Date: Mon, 2 Feb 2026 18:08:25 +0100 Subject: [PATCH] ping refactor --- framework/python/src/net_orc/ip_control.py | 4 ++-- framework/python/src/net_orc/network_orchestrator.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/framework/python/src/net_orc/ip_control.py b/framework/python/src/net_orc/ip_control.py index c6df5d91e..4f295bc65 100644 --- a/framework/python/src/net_orc/ip_control.py +++ b/framework/python/src/net_orc/ip_control.py @@ -264,11 +264,11 @@ def configure_container_interface(self, return False return True - def ping_via_gateway(self, host): + def ping_via_gateway(self, host: str) -> bool: """Ping the host trough the gateway container""" command = f'timeout 3 docker exec tr-ct-gateway ping -W 1 -c 1 {host}' output = util.run_command(command, supress_error=True) - if '0% packet loss' in output[0]: + if re.search(r'\s0% packet loss', output[0]): return True return False diff --git a/framework/python/src/net_orc/network_orchestrator.py b/framework/python/src/net_orc/network_orchestrator.py index ee340e0d2..4acd5f3c3 100644 --- a/framework/python/src/net_orc/network_orchestrator.py +++ b/framework/python/src/net_orc/network_orchestrator.py @@ -16,6 +16,7 @@ import ipaddress import json import os +import re from scapy.all import sniff, wrpcap, BOOTP, AsyncSniffer from scapy.error import Scapy_Exception import shutil @@ -356,8 +357,10 @@ def _ping(self, net_module): host = net_module.net_config.ipv4_address namespace = 'tr-ctns-' + net_module.dir_name cmd = 'ip netns exec ' + namespace + ' ping -c 1 ' + str(host) - success = util.run_command(cmd, output=False) - return success + out, _ = util.run_command(cmd, supress_error=True) + if re.search(r'\s0% packet loss', out): + return True + return False def _ci_pre_network_create(self): """ Stores network properties to restore network after