diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-09-20 07:38:59 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-09-20 07:38:59 +0200 |
commit | 672a70613aa6c987bca417f93b587eddccbfd53a (patch) | |
tree | 063b98db7d410d608b6b99be7721d91b86728a30 /python | |
parent | 62fc13d98013d46cf4cc37f4ac5c6f3c864290c2 (diff) | |
download | vyos-1x-672a70613aa6c987bca417f93b587eddccbfd53a.tar.gz vyos-1x-672a70613aa6c987bca417f93b587eddccbfd53a.zip |
vyos.ifconfig: T2738: can only read from a file when it exists
When IPv6 is disbaled on an interface also the sysfs files related to IPv6 for
this interface vanish. We need to check if the file exists before we read it.
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig/control.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/python/vyos/ifconfig/control.py b/python/vyos/ifconfig/control.py index d41dfef47..7a6b36e7c 100644 --- a/python/vyos/ifconfig/control.py +++ b/python/vyos/ifconfig/control.py @@ -18,11 +18,12 @@ import os from inspect import signature from inspect import _empty -from vyos import debug +from vyos.ifconfig.section import Section from vyos.util import popen from vyos.util import cmd -from vyos.ifconfig.section import Section - +from vyos.util import read_file +from vyos.util import write_file +from vyos import debug class Control(Section): _command_get = {} @@ -116,20 +117,18 @@ class Control(Section): Provide a single primitive w/ error checking for reading from sysfs. """ value = None - with open(filename, 'r') as f: - value = f.read().rstrip('\n') - - self._debug_msg("read '{}' < '{}'".format(value, filename)) + if os.path.exists(filename): + value = read_file(filename) + self._debug_msg("read '{}' < '{}'".format(value, filename)) return value def _write_sysfs(self, filename, value): """ Provide a single primitive w/ error checking for writing to sysfs. """ - self._debug_msg("write '{}' > '{}'".format(value, filename)) if os.path.isfile(filename): - with open(filename, 'w') as f: - f.write(str(value)) + write_file(filename, str(value)) + self._debug_msg("write '{}' > '{}'".format(value, filename)) return True return False |