summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig/control.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-04 19:58:11 +0200
committerGitHub <noreply@github.com>2020-04-04 19:58:11 +0200
commit26d6092b0e96075d532da19b973a63d2fb061869 (patch)
treec65624b134a79242fc19d02d9dc42a90cdee3674 /python/vyos/ifconfig/control.py
parent2364dac59628a801cec373c278860b258b014b46 (diff)
parentdcbd5f430907747f8c29111fbe9f5737865a7ae8 (diff)
downloadvyos-1x-26d6092b0e96075d532da19b973a63d2fb061869.tar.gz
vyos-1x-26d6092b0e96075d532da19b973a63d2fb061869.zip
Merge pull request #299 from thomas-mangin/T2205
ifconfig: T2205: silence ethtool harmless failures
Diffstat (limited to 'python/vyos/ifconfig/control.py')
-rw-r--r--python/vyos/ifconfig/control.py30
1 files changed, 13 insertions, 17 deletions
diff --git a/python/vyos/ifconfig/control.py b/python/vyos/ifconfig/control.py
index c1a073aef..c7a2fa2d6 100644
--- a/python/vyos/ifconfig/control.py
+++ b/python/vyos/ifconfig/control.py
@@ -15,8 +15,9 @@
import os
-from subprocess import Popen, PIPE, STDOUT
+from vyos.util import debug, debug_msg
+from vyos.util import popen, cmd
from vyos.ifconfig.register import Register
@@ -32,27 +33,18 @@ class Control(Register):
# to prevent this, debugging can be explicitely disabled
# if debug is not explicitely disabled the the config, enable it
- self.debug = kargs.get('debug', True)
+ self.debug = ''
+ if kargs.get('debug', True):
+ self.debug = debug('ifconfig')
- def _debug_msg(self, msg):
- if os.path.isfile('/tmp/vyos.ifconfig.debug') and self.debug:
- print('DEBUG/{:<6} {}'.format(self.config['ifname'], msg))
+ def _debug_msg (self, message):
+ return debug_msg(message, self.debug)
def _popen(self, command):
- p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True)
- tmp = p.communicate()[0].strip()
- self._debug_msg(f"cmd '{command}'")
- decoded = tmp.decode()
- if decoded:
- self._debug_msg(f"returned:\n{decoded}")
- return decoded, p.returncode
+ return popen(command, self.debug)
def _cmd(self, command):
- decoded, code = self._popen(command)
- if code != 0:
- # error code can be recovered with .errno
- raise OSError(code, f'{command}\nreturned: {decoded}')
- return decoded
+ return cmd(command, self.debug)
def _get_command(self, config, name):
"""
@@ -79,6 +71,10 @@ class Control(Register):
if convert:
value = convert(value)
+ possible = self._command_set[name].get('possible', None)
+ if possible and not possible(config['ifname'], value):
+ return False
+
config = {**config, **{'value': value}}
cmd = self._command_set[name]['shellcmd'].format(**config)