From 76d9b5a81ac2ba80716ac405c078619a2681259c Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Mon, 12 Jun 2023 10:31:07 +0200 Subject: [PATCH] node scenarios refactoring --- kraken/node_actions/run.py | 34 ++++++++++++++++++++++++++-------- run_kraken.py | 5 +++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/kraken/node_actions/run.py b/kraken/node_actions/run.py index b37660e70..678cccfaf 100644 --- a/kraken/node_actions/run.py +++ b/kraken/node_actions/run.py @@ -13,7 +13,7 @@ from kraken.node_actions.docker_node_scenarios import docker_node_scenarios import kraken.node_actions.common_node_functions as common_node_functions import kraken.cerberus.setup as cerberus - +from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry node_general = False @@ -53,8 +53,14 @@ def get_node_scenario_object(node_scenario, kubecli: krkn_lib_kubernetes.KrknLib # Run defined scenarios # krkn_lib_kubernetes -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> list[ScenarioTelemetry]: + scenario_telemetries: list[ScenarioTelemetry] = [] for node_scenario_config in scenarios_list: + scenario_telemetry = ScenarioTelemetry() + scenario_telemetry.scenario = node_scenario_config + scenario_telemetry.startTimeStamp = time.time() + telemetry.set_parameters_base64(scenario_telemetry, node_scenario_config) + scenario_failed = False with open(node_scenario_config, "r") as f: node_scenario_config = yaml.full_load(f) for node_scenario in node_scenario_config["node_scenarios"]: @@ -62,12 +68,24 @@ def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.Krkn if node_scenario["actions"]: for action in node_scenario["actions"]: start_time = int(time.time()) - inject_node_scenario(action, node_scenario, node_scenario_object, kubecli) - logging.info("Waiting for the specified duration: %s" % (wait_duration)) - time.sleep(wait_duration) - end_time = int(time.time()) - cerberus.get_status(config, start_time, end_time) - logging.info("") + try: + inject_node_scenario(action, node_scenario, node_scenario_object, kubecli) + logging.info("Waiting for the specified duration: %s" % (wait_duration)) + time.sleep(wait_duration) + end_time = int(time.time()) + cerberus.get_status(config, start_time, end_time) + logging.info("") + except Exception as e: + logging.error("Node Scenario failed with exception: %s", str(e)) + scenario_failed = True + + if scenario_failed: + scenario_telemetry.exitStatus = 1 + else: + scenario_telemetry.exitStatus = 0 + scenario_telemetry.endTimeStamp = time.time() + scenario_telemetries.append(scenario_telemetry) + return scenario_telemetries # Inject the specified node scenario diff --git a/run_kraken.py b/run_kraken.py index 1002d7d70..f924da22a 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -224,6 +224,7 @@ def main(cfg): ) chaos_telemetry.scenarios.extend(scenario_telemetries) # krkn_lib_kubernetes + # telemetry_no_integration elif scenario_type == "container_scenarios": logging.info("Running container scenarios") failed_post_scenarios = pod_scenarios.container_run( @@ -239,8 +240,8 @@ def main(cfg): # krkn_lib_kubernetes elif scenario_type == "node_scenarios": logging.info("Running node scenarios") - nodeaction.run(scenarios_list, config, wait_duration, kubecli) - + scenario_telemetries = nodeaction.run(scenarios_list, config, wait_duration, kubecli, telemetry) + chaos_telemetry.scenarios.extend(scenario_telemetries) # Inject managedcluster chaos scenarios specified in the config # krkn_lib_kubernetes elif scenario_type == "managedcluster_scenarios":