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 os.chdir(self.res_dir)
48 cmd = ['launch', '-iterations', '1', '-kubeConfig',
49 f'{Path.home()}/.kube/config', '-v', '3']
50 output = subprocess.check_output(
51 cmd, stderr=subprocess.STDOUT, timeout=3600)
52 self.__logger.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
53 lfiles = glob.glob(os.path.join(
54 'results_netperf-latest', 'netperf-latest*.csv'))
55 results = max(lfiles, key=os.path.getmtime)
56 cmd = ['plotperf', '-c', results,
57 '-o', self.res_dir, '-s', 'netperf']
58 output = subprocess.check_output(
59 cmd, stderr=subprocess.STDOUT, timeout=60)
60 self.__logger.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
62 status = testcase.TestCase.EX_OK
63 except Exception: # pylint: disable=broad-except
64 self.__logger.exception("Can not run Netperf")
66 status = testcase.TestCase.EX_RUN_ERROR
67 self.stop_time = time.time()