From 28633aff2944a7c9c9fe7c66cf7f0414a58ebfe4 Mon Sep 17 00:00:00 2001 From: Eli Battat Date: Tue, 29 Oct 2024 13:17:00 +0200 Subject: [PATCH] Integration with krkn-hub --- benchmark_runner/krkn_hub/__init__.py | 0 .../krkn_hub/krknhub_exceptions.py | 5 ++ .../krkn_hub/krknhub_workloads.py | 79 +++++++++++++++++++ .../main/environment_variables.py | 11 ++- benchmark_runner/main/main.py | 41 +++++++--- 5 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 benchmark_runner/krkn_hub/__init__.py create mode 100644 benchmark_runner/krkn_hub/krknhub_exceptions.py create mode 100644 benchmark_runner/krkn_hub/krknhub_workloads.py diff --git a/benchmark_runner/krkn_hub/__init__.py b/benchmark_runner/krkn_hub/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/benchmark_runner/krkn_hub/krknhub_exceptions.py b/benchmark_runner/krkn_hub/krknhub_exceptions.py new file mode 100644 index 000000000..df9e87ac8 --- /dev/null +++ b/benchmark_runner/krkn_hub/krknhub_exceptions.py @@ -0,0 +1,5 @@ + +class KrknHubError(Exception): + """ Base class for all KrknHub error classes. + All exceptions raised by the KrknHub library should inherit from this class. """ + pass diff --git a/benchmark_runner/krkn_hub/krknhub_workloads.py b/benchmark_runner/krkn_hub/krknhub_workloads.py new file mode 100644 index 000000000..6265dbee5 --- /dev/null +++ b/benchmark_runner/krkn_hub/krknhub_workloads.py @@ -0,0 +1,79 @@ + +from benchmark_runner.common.ssh.ssh import SSH +from benchmark_runner.common.logger.logger_time_stamp import logger_time_stamp, logger +from benchmark_runner.workloads.workloads_operations import WorkloadsOperations + + +class KrknHubWorkloads(WorkloadsOperations): + """ + This class is used to run Krkn Hub workloads. + For more details, see the documentation: https://github.com/krkn-chaos/krkn-hub?tab=readme-ov-file#supported-chaos-scenarios. + """ + + def __init__(self): + super().__init__() + # environment variables + self.__namespace = self._environment_variables_dict.get('namespace', '') + self.__krknhub_workload = self._environment_variables_dict.get('krknhub_workload', '') + self.__krknhub_environment_variables = self._environment_variables_dict.get('krknhub_environment_variables', '') + self.__ssh = SSH() + self.__krknhub_pod_name = 'bm' + + @logger_time_stamp + def delete_all(self): + """ + This method deletes Krkn Hub resources + :return: + """ + self.__ssh.run(cmd=f'podman rm -f {self.__krknhub_pod_name}') + + def initialize_workload(self): + """ + This method includes all the initialization of Krkn Hub workload + :return: + """ + self.delete_all() + if self._enable_prometheus_snapshot: + self.start_prometheus() + + def finalize_workload(self): + """ + This method includes all the finalization of Krkn Hub workload + :return: + """ + if self._enable_prometheus_snapshot: + self.end_prometheus() + self.delete_all() + + @logger_time_stamp + def run_workload(self): + """ + This method runs krkn hub workload + :return: + """ + logger.info(f'run krkn-hub: {self.__krknhub_workload}') + workload_command = f'{self.__krknhub_environment_variables}; podman run --name={self.__krknhub_pod_name} --net=host --env-host=true -v /root/.kube/config:/home/krkn/.kube/config:Z quay.io/krkn-chaos/krkn-hub:{self.__krknhub_workload}' + logger.info(workload_command) + self.__ssh.run(workload_command) + + @logger_time_stamp + def run(self): + """ + This method runs Krkn Hub workloads + :return: + """ + try: + # initialize workload + self.initialize_workload() + # Run workload + self.run_workload() + # finalize workload + self.finalize_workload() + # when error raised finalize workload + except Exception: + logger.info(f'{self._workload} workload raised an exception') + # finalize workload + self.finalize_workload() + return False + + return True diff --git a/benchmark_runner/main/environment_variables.py b/benchmark_runner/main/environment_variables.py index 7d60177f3..09e8dbd13 100644 --- a/benchmark_runner/main/environment_variables.py +++ b/benchmark_runner/main/environment_variables.py @@ -102,7 +102,7 @@ def __init__(self): 'hammerdb_pod_mssql', 'hammerdb_vm_mssql', 'hammerdb_kata_mssql', 'hammerdb_pod_mssql_lso', 'hammerdb_vm_mssql_lso', 'hammerdb_kata_mssql_lso', 'vdbench_pod', 'vdbench_kata', 'vdbench_vm', - 'clusterbuster', 'bootstorm_vm', 'windows_vm'] + 'clusterbuster', 'bootstorm_vm', 'windows_vm', 'krknhub'] # Workloads namespaces self._environment_variables_dict['workload_namespaces'] = { 'stressng': 'benchmark-operator', @@ -111,7 +111,8 @@ def __init__(self): 'vdbench': 'benchmark-runner', 'clusterbuster': 'clusterbuster', 'bootstorm': 'benchmark-runner', - 'windows': 'benchmark-runner' + 'windows': 'benchmark-runner', + 'krknhub': 'krknhub', } # Update namespace @@ -190,6 +191,12 @@ def __init__(self): self._environment_variables_dict['clusterbuster_workload'] = EnvironmentVariables.get_env('CLUSTERBUSTER_WORKLOAD', '') self._environment_variables_dict['clusterbuster_uuid'] = EnvironmentVariables.get_env('CLUSTERBUSTER_UUID', '') + # KRKN HUB data: Chaos testing + # For more details, see the documentation: https://github.com/krkn-chaos/krkn-hub?tab=readme-ov-file#supported-chaos-scenarios. + self._environment_variables_dict['krknhub_workload'] = EnvironmentVariables.get_env('KRKNHUB_WORKLOAD', '') + # e.g. "export CLOUD_TYPE='test'; export BMC_USER='user'" + self._environment_variables_dict['krknhub_environment_variables'] = EnvironmentVariables.get_env('KRKNHUB_ENVIRONMENT_VARIABLES', '') + # IBM data self._environment_variables_dict['region_name'] = EnvironmentVariables.get_env('IBM_REGION_NAME', '') # None(default) - must for unittest diff --git a/benchmark_runner/main/main.py b/benchmark_runner/main/main.py index b50fa75a7..80bb07dfe 100644 --- a/benchmark_runner/main/main.py +++ b/benchmark_runner/main/main.py @@ -18,6 +18,8 @@ from benchmark_runner.common.clouds.IBM.ibm_operations import IBMOperations from benchmark_runner.common.clouds.BareMetal.bare_metal_operations import BareMetalOperations from benchmark_runner.clusterbuster.clusterbuster_workloads import ClusterBusterWorkloads +from benchmark_runner.krkn_hub.krknhub_workloads import KrknHubWorkloads + # logger log_level = os.environ.get('log_level', 'INFO').upper() @@ -30,6 +32,7 @@ benchmark_operator_workload = None benchmark_runner_workload = None clusterbuster_workload = None +krknhub_workload = None environment_variables_dict = environment_variables.environment_variables_dict # environment variables data @@ -46,11 +49,14 @@ run_type = environment_variables_dict.get('run_type', '') is_benchmark_operator_workload = 'benchmark-operator' in ( -environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) + environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) is_benchmark_runner_workload = 'benchmark-runner' in ( -environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) + environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) is_clusterbuster_workload = 'clusterbuster' in ( -environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) + environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) +is_krknhub_workload = 'krknhub' in ( + environment_variables.get_workload_namespace(workload), environment_variables_dict.get("runner_type")) + # workload name validation if workload and not ci_status: if workload not in environment_variables.workloads_list: @@ -64,6 +70,8 @@ f'Invalid run type: {run_type} \n, choose one from the list: {environment_variables.run_types_list}') if is_clusterbuster_workload: clusterbuster_workload = ClusterBusterWorkloads() + elif is_krknhub_workload: + krknhub_workload = KrknHubWorkloads() elif is_benchmark_operator_workload: benchmark_operator_workload = BenchmarkOperatorWorkloads() elif is_benchmark_runner_workload: @@ -84,13 +92,13 @@ def azure_cluster_operations(cluster_operation: str): @return: """ azure_operation = AzureOperations( - azure_clientid=environment_variables_dict.get('azure_clientid', ''), - azure_secret=environment_variables_dict.get('azure_secret', ''), - azure_tenantid=environment_variables_dict.get('azure_tenantid', ''), - azure_subscriptionid=environment_variables_dict.get('azure_subscriptionid', ''), - azure_resource_group_name=environment_variables_dict.get('azure_resource_group_name', ''), - kubeadmin_password=environment_variables_dict.get('kubeadmin_password', '') - ) + azure_clientid=environment_variables_dict.get('azure_clientid', ''), + azure_secret=environment_variables_dict.get('azure_secret', ''), + azure_tenantid=environment_variables_dict.get('azure_tenantid', ''), + azure_subscriptionid=environment_variables_dict.get('azure_subscriptionid', ''), + azure_resource_group_name=environment_variables_dict.get('azure_resource_group_name', ''), + kubeadmin_password=environment_variables_dict.get('kubeadmin_password', '') + ) azure_vm_name = (environment_variables_dict.get('azure_vm_name', '')) if cluster_operation == ClusterOperation.START.value: logger.info('Start cluster with verification') @@ -238,6 +246,7 @@ def run_benchmark_runner_workload(): # benchmark-runner node selector return benchmark_runner_workload.run() + @logger_time_stamp def run_clusterbuster_workload(): """ @@ -248,6 +257,16 @@ def run_clusterbuster_workload(): return clusterbuster_workload.run() +@logger_time_stamp +def run_krknhub_workload(): + """ + This method runs krknhub workload + :return: + """ + # run krknhub + return krknhub_workload.run() + + @logger_time_stamp def main(): """ @@ -293,6 +312,8 @@ def main(): success = run_benchmark_runner_workload() elif is_clusterbuster_workload: success = run_clusterbuster_workload() + elif is_krknhub_workload: + success = run_krknhub_workload() else: logger.error(f"empty workload, choose one from the list: {environment_variables.workloads_list}") raise SystemExit(SYSTEM_EXIT_UNKNOWN_EXECUTION_TYPE)