3 # Copyright (c) 2021 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
11 Benchmarking Kubernetes Networking Performance
17 from pathlib import Path
22 from xtesting.core import testcase
25 class Netperf(testcase.TestCase):
26 """Run Benchmarking Kubernetes Networking Performance"""
28 __logger = logging.getLogger(__name__)
30 def __init__(self, **kwargs):
31 super().__init__(**kwargs)
32 self.output_log_name = 'functest-kubernetes.log'
33 self.output_debug_log_name = 'functest-kubernetes.debug.log'
35 def check_requirements(self):
36 """Check if launch is in $PATH"""
37 self.is_skipped = not (
38 shutil.which("launch") and shutil.which("plotperf"))
40 self.__logger.warning("launch or plotperf is missing")
42 def run(self, **kwargs):
43 self.start_time = time.time()
45 if not os.path.exists(self.res_dir):
46 os.makedirs(self.res_dir)
47 cmd = ['launch', '-iterations', '1', '-kubeConfig',
48 f'{Path.home()}/.kube/config']
49 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
50 self.__logger.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
51 lfiles = glob.glob(os.path.join(
52 'results_netperf-latest', 'netperf-latest*.csv'))
53 results = max(lfiles, key=os.path.getmtime)
54 shutil.move(results, os.path.join(self.res_dir, 'netperf.csv'))
55 cmd = ['plotperf', '-c',
56 os.path.join(self.res_dir, 'netperf.csv'),
57 '-o', self.res_dir, '-s', 'netperf']
58 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
59 self.__logger.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
61 status = testcase.TestCase.EX_OK
62 except Exception: # pylint: disable=broad-except
63 self.__logger.exception("Can not run Netperf")
65 status = testcase.TestCase.EX_RUN_ERROR
66 self.stop_time = time.time()