From 2186ea252993b927d296436ce2c43720c6ff75a3 Mon Sep 17 00:00:00 2001 From: LiuHailong Date: Fri, 21 Feb 2025 14:47:46 +0800 Subject: [PATCH] parse_panic: Replace popen and os.system with subprocess.run() Signed-off-by: LiuHailong --- script/server/sysom_vmcore/parse_panic.py | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/script/server/sysom_vmcore/parse_panic.py b/script/server/sysom_vmcore/parse_panic.py index 14ce4b68..d2298b55 100644 --- a/script/server/sysom_vmcore/parse_panic.py +++ b/script/server/sysom_vmcore/parse_panic.py @@ -459,10 +459,12 @@ def check_panic(column): print(f"add {column['name']} calltrace line to db") return True def do_cmd(cmd): - output = os.popen(cmd) - ret = output.read().strip() - output.close() - return ret + try: + result = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return result.stdout + except subprocess.CalledProcessError as e: + print(f"Command failed with error:{e}") + return None def init_column(column): column['upload_time'] = int(time.time()) @@ -519,18 +521,19 @@ def mount_nfs(): return False cmd = 'mount -t nfs %s:%s %s' % (server_host,mount_point,nfs_root) - ret = os.system(cmd) - if ret != 0: - print('failed to mount to nfs %s' % nfs_root) + try: + ret = subprocess.run(cmd, check=True) + except subprocess.CalledProcessError as e: + print(f'failed to mount to nfs {nfs_root}: {e}') return False return True def unmount_nfs(): global nfs_root - cmd = 'umount %s' % nfs_root - ret = os.system(cmd) - if ret != 0: - print(f'failed to unmount nfs at {nfs_root}') + try: + result = subprocess.run(['umount', nfs_root], check=True, stdout=subprocess.PIPTE, stderr=subprocess.PIPE) + except subprocess.CalledProcessError as e: + print(f'failed to unmount nfs at {nfs_root}:{e.stderr.decode().strip()}') def main(): global nfs_root -- Gitee