From 42fc8eea404d3962c026fbedb763ace4fc2929f1 Mon Sep 17 00:00:00 2001 From: Paige Rubendall Date: Wed, 29 May 2024 15:41:43 -0400 Subject: [PATCH] adding wait in pvc scenarios and serivce hijack rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED Signed-off-by: Paige Rubendall --- kraken/pvc/pvc_scenario.py | 6 ++++-- kraken/service_hijacking/service_hijacking.py | 6 +++++- run_kraken.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kraken/pvc/pvc_scenario.py b/kraken/pvc/pvc_scenario.py index cdaf8a8b..9783a304 100644 --- a/kraken/pvc/pvc_scenario.py +++ b/kraken/pvc/pvc_scenario.py @@ -11,7 +11,7 @@ # krkn_lib -def run(scenarios_list, config, kubecli: KrknKubernetes, telemetry: KrknTelemetryKubernetes) -> (list[str], list[ScenarioTelemetry]): +def run(scenarios_list, config, wait_duration, kubecli: KrknKubernetes, telemetry: KrknTelemetryKubernetes) -> (list[str], list[ScenarioTelemetry]): """ Reads the scenario config and creates a temp file to fill up the PVC """ @@ -305,7 +305,9 @@ def run(scenarios_list, config, kubecli: KrknKubernetes, telemetry: KrknTelemetr file_size_kb, kubecli ) - + logging.info("End of scenario. Waiting for the specified duration: %s" % (wait_duration)) + time.sleep(wait_duration) + end_time = int(time.time()) cerberus.publish_kraken_status( config, diff --git a/kraken/service_hijacking/service_hijacking.py b/kraken/service_hijacking/service_hijacking.py index e885606e..ecd1e890 100644 --- a/kraken/service_hijacking/service_hijacking.py +++ b/kraken/service_hijacking/service_hijacking.py @@ -7,7 +7,7 @@ from krkn_lib.telemetry.k8s import KrknTelemetryKubernetes -def run(scenarios_list: list[str], krkn_lib: KrknKubernetes, telemetry: KrknTelemetryKubernetes) -> (list[str], list[ScenarioTelemetry]): +def run(scenarios_list: list[str],wait_duration: int, krkn_lib: KrknKubernetes, telemetry: KrknTelemetryKubernetes) -> (list[str], list[ScenarioTelemetry]): scenario_telemetries= list[ScenarioTelemetry]() failed_post_scenarios = [] for scenario in scenarios_list: @@ -67,6 +67,10 @@ def run(scenarios_list: list[str], krkn_lib: KrknKubernetes, telemetry: KrknTele logging.info("selectors successfully restored") logging.info("undeploying service-hijacking resources...") krkn_lib.undeploy_service_hijacking(webservice) + + logging.info("End of scenario. Waiting for the specified duration: %s" % (wait_duration)) + time.sleep(wait_duration) + scenario_telemetry.exit_status = 0 scenario_telemetry.end_timestamp = time.time() scenario_telemetries.append(scenario_telemetry) diff --git a/run_kraken.py b/run_kraken.py index 4e9f355b..684d47df 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -341,7 +341,7 @@ def main(cfg): # krkn_lib elif scenario_type == "pvc_scenarios": logging.info("Running PVC scenario") - failed_post_scenarios, scenario_telemetries = pvc_scenario.run(scenarios_list, config, kubecli, telemetry_k8s) + failed_post_scenarios, scenario_telemetries = pvc_scenario.run(scenarios_list, config, wait_duration, kubecli, telemetry_k8s) chaos_telemetry.scenarios.extend(scenario_telemetries) # Network scenarios @@ -351,7 +351,7 @@ def main(cfg): failed_post_scenarios, scenario_telemetries = network_chaos.run(scenarios_list, config, wait_duration, kubecli, telemetry_k8s) elif scenario_type == "service_hijacking": logging.info("Running Service Hijacking Chaos") - failed_post_scenarios, scenario_telemetries = service_hijacking_plugin.run(scenarios_list, kubecli, telemetry_k8s) + failed_post_scenarios, scenario_telemetries = service_hijacking_plugin.run(scenarios_list, wait_duration, kubecli, telemetry_k8s) chaos_telemetry.scenarios.extend(scenario_telemetries) # Check for critical alerts when enabled