5
5
import random
6
6
import time
7
7
import uuid
8
+ from collections .abc import Iterable
9
+ from concurrent .futures import ThreadPoolExecutor
8
10
from config import DERP_SERVERS , LIBTELIO_IPV6_WG_SUBNET , WG_SERVERS
9
11
from datetime import datetime
10
12
from ipaddress import ip_address
@@ -444,10 +446,11 @@ def config_dynamic_nodes(
444
446
return tuple (list (self .nodes .values ())[current_node_list_len :])
445
447
446
448
447
- def start_tcpdump (container_names : List [str ]):
449
+ def start_tcpdump (container_names : Iterable [str ]):
448
450
if os .environ .get ("NATLAB_SAVE_LOGS" ) is None :
449
451
return
450
- for container_name in container_names :
452
+
453
+ def aux (container_name ):
451
454
# First make sure that no leftover processes/files will interfere
452
455
cmd = f"docker exec --privileged { container_name } killall -w tcpdump"
453
456
os .system (cmd )
@@ -456,22 +459,31 @@ def start_tcpdump(container_names: List[str]):
456
459
cmd = f"docker exec -d --privileged { container_name } tcpdump -i any -U -w { PCAP_FILE_PATH } "
457
460
os .system (cmd )
458
461
462
+ with ThreadPoolExecutor () as executor :
463
+ executor .map (aux , container_names )
464
+
459
465
460
- def stop_tcpdump (container_names ):
466
+ def stop_tcpdump (container_names , store_in = None ):
461
467
if os .environ .get ("NATLAB_SAVE_LOGS" ) is None :
462
468
return
463
469
log_dir = get_current_test_log_path ()
464
470
os .makedirs (log_dir , exist_ok = True )
465
- for container_name in container_names :
471
+
472
+ def aux (container_name ):
466
473
cmd = f"docker exec --privileged { container_name } killall -w tcpdump"
467
474
os .system (cmd )
468
- path = find_unique_path_for_tcpdump (log_dir , container_name )
475
+ path = find_unique_path_for_tcpdump (
476
+ store_in if store_in else log_dir , container_name
477
+ )
469
478
cmd = f"docker container cp { container_name } :{ PCAP_FILE_PATH } { path } "
470
479
os .system (cmd )
471
480
481
+ with ThreadPoolExecutor () as executor :
482
+ executor .map (aux , container_names )
483
+
472
484
473
485
def find_unique_path_for_tcpdump (log_dir , container_name ):
474
- candidate_path = f"./ { log_dir } /{ container_name } .pcap"
486
+ candidate_path = f"{ log_dir } /{ container_name } .pcap"
475
487
counter = 1
476
488
# NOTE: counter starting from '1' means that the file will either have no suffix or
477
489
# will have a suffix starting from '2'. This is to make it clear that it's not the
0 commit comments