diff options
author | Naveen Joy <najoy@cisco.com> | 2024-01-31 08:46:18 -0800 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2024-02-14 22:08:20 +0000 |
commit | 0215ef1010fbe41a72d57e7cddc4fb18dc3d53d2 (patch) | |
tree | a9cc98c338af1d08e10260f8ae1a9c23d14a6026 /test/vpp_iperf.py | |
parent | 28aef29e01f786499d719ee40dbee77e7638a729 (diff) |
tests: refactor virtual interface tests
Split virtual interface tests in VPP into smaller and modular
tests for testing various interface types and features.
Type: test
Change-Id: Ic38af88379f75eee3090679d411edbdc8fd5d2e5
Signed-off-by: Naveen Joy <najoy@cisco.com>
Diffstat (limited to 'test/vpp_iperf.py')
-rw-r--r-- | test/vpp_iperf.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/test/vpp_iperf.py b/test/vpp_iperf.py index 8fe0d749a4b..b325399f8e1 100644 --- a/test/vpp_iperf.py +++ b/test/vpp_iperf.py @@ -65,6 +65,7 @@ class VppIperf: sys.exit(1) def start_iperf_server(self): + """Starts the iperf server and returns the process cmdline args.""" args = [ "ip", "netns", @@ -75,11 +76,11 @@ class VppIperf: "-D", ] args.extend(self.server_args.split()) - args = " ".join(args) - self.logger.debug(f"Starting iperf server: {args}") + cmd = " ".join(args) + self.logger.debug(f"Starting iperf server: {cmd}") try: - return subprocess.run( - args, + subprocess.run( + cmd, timeout=self.duration + 5, encoding="utf-8", shell=True, @@ -88,6 +89,7 @@ class VppIperf: ) except subprocess.TimeoutExpired as e: raise Exception("Error: Timeout expired for iPerf", e.output) + return args[4:] def start_iperf_client(self): args = [ @@ -125,7 +127,7 @@ class VppIperf: """ self.ensure_init() if not client_only: - self.start_iperf_server() + return self.start_iperf_server() if not server_only: result = self.start_iperf_client() self.logger.debug(f"Iperf client args: {result.args}") @@ -192,17 +194,22 @@ def start_iperf( return iperf.start(server_only=server_only, client_only=client_only) -def stop_iperf(): - args = ["pkill", "iperf"] - args = " ".join(args) - try: - return subprocess.run( - args, - encoding="utf-8", - shell=True, - ) - except Exception: - pass +def stop_iperf(iperf_cmd): + """Stop the iperf process matching the iperf_cmd string.""" + args = ["pgrep", "-x", "-f", iperf_cmd] + p = subprocess.Popen( + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8" + ) + stdout, _ = p.communicate() + for pid in stdout.split(): + try: + subprocess.run( + f"kill -9 {pid}", + encoding="utf-8", + shell=True, + ) + except Exception: + pass if __name__ == "__main__": |