From 7f1cef22f0b1a1d7a2b16a2800abdff0a9d5179f Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sun, 5 Apr 2020 18:06:11 +0100 Subject: util: T2226: rewrite keepalived to use cmd --- src/system/keepalived-fifo.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/system') diff --git a/src/system/keepalived-fifo.py b/src/system/keepalived-fifo.py index 5e85da4a4..2778deaab 100755 --- a/src/system/keepalived-fifo.py +++ b/src/system/keepalived-fifo.py @@ -20,7 +20,6 @@ import time import signal import argparse import threading -import subprocess import re import json from pathlib import Path @@ -28,6 +27,8 @@ from queue import Queue import logging from logging.handlers import SysLogHandler +from vyos.util import cmd + # configure logging logger = logging.getLogger(__name__) logs_format = logging.Formatter('%(filename)s: %(message)s') @@ -84,14 +85,11 @@ class KeepalivedFifo: # run command def _run_command(self, command): + logger.debug("Running the command: {}".format(command)) try: - logger.debug("Running the command: {}".format(command)) - process = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) - stdout, stderr = process.communicate() - if process.returncode != 0: - raise Exception("The command \"{}\" returned status {}. Error: {}".format(command, process.returncode, stderr)) - except Exception as err: - logger.error("Unable to execute command \"{}\": {}".format(command, err)) + cmd(command, universal_newlines=True) + except OSError as err: + logger.error(f'Unable to execute command "{command}": {err}') # create FIFO pipe def pipe_create(self): -- cgit v1.2.3