From c9c8cd50f4165c7f86e71a6723f0ebb3a2cbdaf5 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 11 Nov 2019 19:42:11 +0100 Subject: ifconfig: T1793: extend set_speed_duplex() delta check Commit 9e4947770064 ("ifconfig: T1793: add delta check on set_speed_duplex()") was wave1 of reducing the amount of switch-port flaps and BGP session resets. The delta check now also handles the case of fixed speed and duplex settings. --- python/vyos/ifconfig.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 24a718e73..279d948b7 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1144,7 +1144,24 @@ class EthernetIf(VLANIf): tmp = self._cmd(cmd) if re.search("\tAuto-negotiation: on", tmp): - if speed == 'auto' or duplex == 'auto': + if speed == 'auto' and duplex == 'auto': + # bail out early as nothing is to change + return + else: + # read in current speed and duplex settings + cur_speed = 0 + cur_duplex = '' + for line in tmp.splitlines(): + if line.lstrip().startswith("Speed:"): + non_decimal = re.compile(r'[^\d.]+') + cur_speed = non_decimal.sub('', line) + continue + + if line.lstrip().startswith("Duplex:"): + cur_duplex = line.split()[-1].lower() + break + + if (cur_speed == speed) and (cur_duplex == duplex): # bail out early as nothing is to change return -- cgit v1.2.3