diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-08-02 18:33:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 18:33:26 +0200 |
commit | 7a32e9ee70d6371dc38a5f4acb684c218bb8d4d3 (patch) | |
tree | 4f38d85a4fcab1c8489bdbbed06ab718c8c712a0 /python/vyos/ifconfig/l2tpv3.py | |
parent | 0284d6796298bca0b06385ef9e8dd7565a7551b7 (diff) | |
parent | 055532b731f0b69a2ef1a01ce36dc0f69cf68636 (diff) | |
download | vyos-1x-7a32e9ee70d6371dc38a5f4acb684c218bb8d4d3.tar.gz vyos-1x-7a32e9ee70d6371dc38a5f4acb684c218bb8d4d3.zip |
Merge pull request #952 from sever-sever/T1594-curr
l2tpv3: T1594: Fix timeout before set l2tpv3 interface
Diffstat (limited to 'python/vyos/ifconfig/l2tpv3.py')
-rw-r--r-- | python/vyos/ifconfig/l2tpv3.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/python/vyos/ifconfig/l2tpv3.py b/python/vyos/ifconfig/l2tpv3.py index 7ff0fdd0e..fcd1fbf81 100644 --- a/python/vyos/ifconfig/l2tpv3.py +++ b/python/vyos/ifconfig/l2tpv3.py @@ -13,8 +13,28 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see <http://www.gnu.org/licenses/>. +from time import sleep +from time import time +from vyos.util import run from vyos.ifconfig.interface import Interface +def wait_for_add_l2tpv3(timeout=10, sleep_interval=1, cmd=None): + ''' + In some cases, we need to wait until local address is assigned. + And only then can the l2tpv3 tunnel be configured. + For example when ipv6 address in tentative state + or we wait for some routing daemon for remote address. + ''' + start_time = time() + test_command = cmd + while True: + if (start_time + timeout) < time(): + return None + result = run(test_command) + if result == 0: + return True + sleep(sleep_interval) + @Interface.register class L2TPv3If(Interface): """ @@ -43,7 +63,9 @@ class L2TPv3If(Interface): cmd += ' encap {encapsulation}' cmd += ' local {source_address}' cmd += ' remote {remote}' - self._cmd(cmd.format(**self.config)) + c = cmd.format(**self.config) + # wait until the local/remote address is available, but no more 10 sec. + wait_for_add_l2tpv3(cmd=c) # setup session cmd = 'ip l2tp add session name {ifname}' |