From dcbd5f430907747f8c29111fbe9f5737865a7ae8 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 4 Apr 2020 12:55:08 +0100 Subject: ifconfig: T2205: silence ethtool harmless failures Not all interface are capable of all features. Since commands are now checked for valid completion, ethtool command failure must be ignored. --- python/vyos/util.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'python/vyos/util.py') diff --git a/python/vyos/util.py b/python/vyos/util.py index 3970b8bf1..87c2dcedc 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -16,6 +16,44 @@ import os import re import sys +from subprocess import Popen, PIPE, STDOUT + + +# debugging + + +def debug(flag): + return flag if os.path.isfile(f'/tmp/vyos.{flag}.debug') else '' + + +def debug_msg(message, section=''): + if section: + print(f'DEBUG/{section:<6} {message}') + + +# commands + + +def popen(command, section=''): + p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True) + tmp = p.communicate()[0].strip() + debug_msg(f"cmd '{command}'", section) + decoded = tmp.decode() + if decoded: + debug_msg(f"returned:\n{decoded}", section) + return decoded, p.returncode + + +def cmd(command, section=''): + decoded, code = popen(command, section) + if code != 0: + # error code can be recovered with .errno + raise OSError(code, f'{command}\nreturned: {decoded}') + return decoded + + +# file manipulation + def read_file(path): """ Read a file to string """ -- cgit v1.2.3