aboutsummaryrefslogtreecommitdiffstats
path: root/functest_kubernetes
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2024-01-13 14:48:16 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2024-01-13 14:49:04 +0100
commita2abab6871ef68435f5c4b3f5579e31ba40b5b3f (patch)
tree5b2fd8a6562fc0fe258fdad27d6525c05d6027c7 /functest_kubernetes
parent1bd69d63994d66582f4e7967e4a1f703dc247c69 (diff)
Manage netperf namespace to enforce baseline
Change-Id: If74322d583d9f16478aad8dcda6afa2368ff5482 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest_kubernetes')
-rw-r--r--functest_kubernetes/netperf/netperf.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/functest_kubernetes/netperf/netperf.py b/functest_kubernetes/netperf/netperf.py
index 7832e6d1..5923cb78 100644
--- a/functest_kubernetes/netperf/netperf.py
+++ b/functest_kubernetes/netperf/netperf.py
@@ -19,16 +19,21 @@ import shutil
import subprocess
import time
+from kubernetes import client
+from kubernetes import config
from xtesting.core import testcase
class Netperf(testcase.TestCase):
"""Run Benchmarking Kubernetes Networking Performance"""
+ ns_generate_name = "netperf-"
__logger = logging.getLogger(__name__)
def __init__(self, **kwargs):
super().__init__(**kwargs)
+ config.load_kube_config()
+ self.corev1 = client.CoreV1Api()
self.output_log_name = 'functest-kubernetes.log'
self.output_debug_log_name = 'functest-kubernetes.debug.log'
@@ -45,13 +50,22 @@ class Netperf(testcase.TestCase):
if not os.path.exists(self.res_dir):
os.makedirs(self.res_dir)
os.chdir(self.res_dir)
+ api_response = self.corev1.create_namespace(
+ client.V1Namespace(metadata=client.V1ObjectMeta(
+ generate_name=self.ns_generate_name,
+ labels={
+ "pod-security.kubernetes.io/enforce": "baseline"})))
+ self.namespace = api_response.metadata.name
+ self.__logger.debug("create_namespace: %s", api_response)
cmd = ['launch', '-iterations', '1', '-kubeConfig',
- f'{Path.home()}/.kube/config', '-v', '3']
+ f'{Path.home()}/.kube/config', '-v', '3',
+ '-namespace', self.namespace]
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, timeout=3600)
self.__logger.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
lfiles = glob.glob(os.path.join(
- 'results_netperf-latest', 'netperf-latest*.csv'))
+ f'results_{self.namespace}-latest',
+ f'{self.namespace}-latest*.csv'))
results = max(lfiles, key=os.path.getmtime)
cmd = ['plotperf', '-c', results,
'-o', self.res_dir, '-s', 'netperf']
@@ -69,3 +83,11 @@ class Netperf(testcase.TestCase):
status = testcase.TestCase.EX_RUN_ERROR
self.stop_time = time.time()
return status
+
+ def clean(self):
+ if self.namespace:
+ try:
+ api_response = self.corev1.delete_namespace(self.namespace)
+ self.__logger.debug("delete_namespace: %s", self.namespace)
+ except client.rest.ApiException:
+ pass