From 07959c4bbe09e89bef1c91932c0ce6c326bab1b3 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 11 Oct 2024 14:25:06 +0800 Subject: [PATCH] fix(ci): optimize an openthread ci case --- examples/openthread/ot_ci_function.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/openthread/ot_ci_function.py b/examples/openthread/ot_ci_function.py index 3561f4ad1d..bc47d49e55 100644 --- a/examples/openthread/ot_ci_function.py +++ b/examples/openthread/ot_ci_function.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Unlicense OR CC0-1.0 # !/usr/bin/env python3 # this file defines some functions for testing cli and br under pytest framework - import re import socket import struct @@ -411,12 +410,15 @@ def host_publish_service() -> None: def host_close_service() -> None: - command = "ps | grep avahi-publish-s | awk '{print $1}'" + command = 'ps aux | grep avahi-publish-s' out_bytes = subprocess.check_output(command, shell=True, timeout=5) out_str = out_bytes.decode('utf-8') - the_pid = re.findall(r'(\d+)\n', str(out_str)) - for pid in the_pid: + service_info = [line for line in out_str.splitlines() if 'testxxx _testxxx._udp' in line] + for line in service_info: + print('Process:', line) + pid = line.split()[1] command = 'kill -9 ' + pid + print('kill ', pid) subprocess.call(command, shell=True, timeout=5) time.sleep(1)