vcl: add support for reconnect
[vpp.git] / test / cpu_config.py
1 import os
2 import psutil
3
4 available_cpus = psutil.Process().cpu_affinity()
5 num_cpus = len(available_cpus)
6
7 max_vpp_cpus = os.getenv("MAX_VPP_CPUS", "auto").lower()
8
9 if max_vpp_cpus == "auto":
10     max_vpp_cpus = num_cpus
11 else:
12     try:
13         max_vpp_cpus = int(max_vpp_cpus)
14     except ValueError as e:
15         raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
16                          "values are a positive integer or 'auto'") from e
17     if max_vpp_cpus <= 0:
18         raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
19                          "values are a positive integer or 'auto'")
20     if max_vpp_cpus > num_cpus:
21         max_vpp_cpus = num_cpus