]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: wait for L2TP tunnels being removed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Jul 2022 21:06:36 +0000 (23:06 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Jul 2022 00:36:14 +0000 (02:36 +0200)
Fixes #23985.

test/test-network/systemd-networkd-tests.py

index 7a791af00316a9c20abcf1f5e372de50a0709a2f..bb9ca4358560a54e0822ecda6c9ef45738654c9c 100755 (executable)
@@ -447,12 +447,24 @@ def flush_fou_ports():
         call(f'ip fou del port {port}')
 
 def flush_l2tp_tunnels():
+    tids = []
     output = check_output('ip l2tp show tunnel')
     for line in output.splitlines():
         words = line.split()
         if words[0] == 'Tunnel':
             tid = words[1].rstrip(',')
             call(f'ip l2tp del tunnel tunnel_id {tid}')
+            tids.append(tid)
+
+    # Removing L2TP tunnel is asynchronous and slightly takes a time.
+    for tid in tids:
+        for _ in range(50):
+            r = run(f'ip l2tp show tunnel tunnel_id {tid}')
+            if r.returncode != 0 or len(r.stdout.rstrip()) == 0:
+                break
+            time.sleep(.2)
+        else:
+            print(f'Cannot remove L2TP tunnel {tid}, ignoring.')
 
 def read_link_attr(*args):
     with open(os.path.join('/sys/class/net', *args), encoding='utf-8') as f:
@@ -572,6 +584,7 @@ def tear_down_common():
     call_quiet('ip netns del ns99')
 
     # 4. remove links
+    flush_l2tp_tunnels()
     flush_links()
 
     # 5. stop networkd
@@ -583,7 +596,6 @@ def tear_down_common():
 
     # 7. flush settings
     flush_fou_ports()
-    flush_l2tp_tunnels()
     flush_nexthops()
     flush_routing_policy_rules()
     flush_routes()