diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-10-06 16:16:50 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-10-06 16:16:57 +0200 |
commit | 1257d7851866d42287018b38dd871f279b87286a (patch) | |
tree | 8bbc247988ceee393ef7f94bcf145b846f687285 | |
parent | eddc97b9d12d2f31eba9a479eb538fbd7f0c3e55 (diff) | |
download | vyos-1x-1257d7851866d42287018b38dd871f279b87286a.tar.gz vyos-1x-1257d7851866d42287018b38dd871f279b87286a.zip |
Python/ifconfig: T1712: wait when changing interface state
With some interfaces, for example bond vif, it take some time for the state
change to really happen. Because of this later code, like starting DHCP client,
might not work as expected as get_state() reports the old (real) state.
Now when changing state of an interface we are (busy-)waiting up to 12.5
seconds before we inform the user that the interface could not be brought up.
This should be more then enough time for any interface to start except when
there is really no cable attached.
-rw-r--r-- | python/vyos/ifconfig.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index d4b1a73c1..4ac605b54 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -293,7 +293,21 @@ class Interface: # Assemble command executed on system. Unfortunately there is no way # to up/down an interface via sysfs cmd = 'ip link set dev {} {}'.format(self._ifname, state) - return self._cmd(cmd) + tmp = self._cmd(cmd) + + # better safe then sorry - wait until the interface is really up + # but only for a given period of time to avoid potential deadlocks! + cnt = 0 + while self.get_state() != state: + cnt += 1 + if cnt == 50: + print('Interface {} could not be brought up in time ...'.format(self._ifname)) + break + + # sleep 250ms + sleep(0.250) + + return tmp def set_proxy_arp(self, enable): """ |