diff options
author | DmitriyEshenko <dmitriy.eshenko@vyos.io> | 2020-03-03 15:40:48 +0000 |
---|---|---|
committer | DmitriyEshenko <dmitriy.eshenko@vyos.io> | 2020-03-03 15:40:48 +0000 |
commit | c7e4d1d2e9207d41096e34f9ea345d9e2d9a9d8f (patch) | |
tree | d13ee4853cec7f777838185fab6e622bb3492c30 /python | |
parent | 98a4a7d66a7dbfee113885a5f804e7d3f344685d (diff) | |
download | vyos-1x-c7e4d1d2e9207d41096e34f9ea345d9e2d9a9d8f.tar.gz vyos-1x-c7e4d1d2e9207d41096e34f9ea345d9e2d9a9d8f.zip |
ifconfig: T2074: add check for sysfs files
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index b1f9baabe..d5b511f82 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -407,11 +407,12 @@ class Interface: >>> from vyos.ifconfig import Interface >>> Interface('eth0').set_link_detect(1) """ - if int(link_filter) >= 0 and int(link_filter) <= 2: - return self._write_sysfs('/proc/sys/net/ipv4/conf/{0}/link_filter' - .format(self.config['ifname']), link_filter) - else: - raise ValueError("Value out of range") + sysfs_file = '/proc/sys/net/ipv4/conf/{0}/link_filter'.format(self.config['ifname']) + if os.path.exists(sysfs_file): + if int(link_filter) >= 0 and int(link_filter) <= 2: + return self._write_sysfs(sysfs_file, link_filter) + else: + raise ValueError("Value out of range") def set_alias(self, ifalias=None): """ @@ -1218,8 +1219,12 @@ class EthernetIf(VLANIf): >>> i.get_driver_name() 'vmxnet3' """ - link = os.readlink('/sys/class/net/{}/device/driver/module'.format(self.config['ifname'])) - return os.path.basename(link) + sysfs_file = '/sys/class/net/{}/device/driver/module'.format(self.config['ifname']) + if os.path.exists(sysfs_file): + link = os.readlink(sysfs_file) + return os.path.basename(link) + else: + return None def set_flow_control(self, enable): """ |