summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-06-26 15:35:10 +0200
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-06-26 14:35:54 +0000
commitb9fb91699b9af7a8ea375d4662a50363004eacfd (patch)
tree1b82f8594d824a0695d7a557e0da570137049117 /python
parent621dd08a7c3bb0972ec176be1bb8397d06717e52 (diff)
downloadvyos-1x-b9fb91699b9af7a8ea375d4662a50363004eacfd.tar.gz
vyos-1x-b9fb91699b9af7a8ea375d4662a50363004eacfd.zip
interfaces: T6519: harden config migration if ethernet interface is missing
During a corner case where the configuration is migrated to a different system with fewer ethernet interfaces, migration will fail during an image upgrade. vyos.ethtool.Ethtool() is instantiated with an invalid interface leading to an exception that kills the migrator (cherry picked from commit e47d4fd385631236da6882233b09f6364cbb077b)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ethtool.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/python/vyos/ethtool.py b/python/vyos/ethtool.py
index d45c9c272..80bb56fa2 100644
--- a/python/vyos/ethtool.py
+++ b/python/vyos/ethtool.py
@@ -16,6 +16,7 @@
import re
from json import loads
+from vyos.utils.network import interface_exists
from vyos.utils.process import popen
# These drivers do not support using ethtool to change the speed, duplex, or
@@ -64,6 +65,9 @@ class Ethtool:
def __init__(self, ifname):
# Get driver used for interface
+ if not interface_exists(ifname):
+ raise ValueError(f'Interface "{ifname}" does not exist!')
+
out, _ = popen(f'ethtool --driver {ifname}')
driver = re.search(r'driver:\s(\w+)', out)
if driver: