summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-01-07 23:41:33 +0100
committerChristian Poessinger <christian@poessinger.com>2021-01-07 23:41:33 +0100
commit7a95aa238ba4d6743be645ffa3baef0e69251926 (patch)
treed40d9098f6b5bd27c82297077c0cf4bca0b690c8
parent551ae04df7f6ce8a6cdbdf9712b4eea5d9e0c2f3 (diff)
downloadvyos-1x-7a95aa238ba4d6743be645ffa3baef0e69251926.tar.gz
vyos-1x-7a95aa238ba4d6743be645ffa3baef0e69251926.zip
smoketest: ethernet: verify() speed/duplex must both be auto or discrete
-rwxr-xr-xsmoketest/scripts/cli/test_interfaces_ethernet.py12
-rwxr-xr-xsrc/conf_mode/interfaces-ethernet.py11
2 files changed, 16 insertions, 7 deletions
diff --git a/smoketest/scripts/cli/test_interfaces_ethernet.py b/smoketest/scripts/cli/test_interfaces_ethernet.py
index 0f3579c30..6b21853c3 100755
--- a/smoketest/scripts/cli/test_interfaces_ethernet.py
+++ b/smoketest/scripts/cli/test_interfaces_ethernet.py
@@ -136,6 +136,18 @@ class EthernetInterfaceTest(BasicInterfaceTest.BaseTest):
# manually, else tearDown() will have problem in commit()
self.session.delete(unknonw_interface)
+ def test_speed_duplex_verify(self):
+ for interface in self._interfaces:
+ self.session.set(self._base_path + [interface, 'speed', '1000'])
+
+ # check validate() - if either speed or duplex is not auto, the
+ # other one must be manually configured, too
+ with self.assertRaises(ConfigSessionError):
+ self.session.commit()
+ self.session.set(self._base_path + [interface, 'duplex', 'full'])
+
+ self.session.commit()
+
def test_eapol_support(self):
for interface in self._interfaces:
# Enable EAPoL
diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py
index 0a904c592..e7f0cd6a5 100755
--- a/src/conf_mode/interfaces-ethernet.py
+++ b/src/conf_mode/interfaces-ethernet.py
@@ -62,13 +62,10 @@ def verify(ethernet):
ifname = ethernet['ifname']
verify_interface_exists(ifname)
- if ethernet.get('speed', None) == 'auto':
- if ethernet.get('duplex', None) != 'auto':
- raise ConfigError('If speed is hardcoded, duplex must be hardcoded, too')
-
- if ethernet.get('duplex', None) == 'auto':
- if ethernet.get('speed', None) != 'auto':
- raise ConfigError('If duplex is hardcoded, speed must be hardcoded, too')
+ # No need to check speed and duplex keys as both have default values.
+ if ((ethernet['speed'] == 'auto' and ethernet['duplex'] != 'auto') or
+ (ethernet['speed'] != 'auto' and ethernet['duplex'] == 'auto')):
+ raise ConfigError('Speed/Duplex missmatch. Must be both auto or manually configured')
verify_mtu(ethernet)
verify_mtu_ipv6(ethernet)