Skip to content

Commit

Permalink
Integration with krkn-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
ebattat committed Oct 30, 2024
1 parent b516bef commit 28633af
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 12 deletions.
Empty file.
5 changes: 5 additions & 0 deletions benchmark_runner/krkn_hub/krknhub_exceptions.py
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions benchmark_runner/krkn_hub/krknhub_workloads.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions benchmark_runner/main/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 31 additions & 10 deletions benchmark_runner/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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')
Expand Down Expand Up @@ -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():
"""
Expand All @@ -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():
"""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 28633af

Please sign in to comment.