Skip to content

Commit

Permalink
run_kraken.py + arcaflow scenarios refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed Jun 9, 2023
1 parent 383f452 commit 660bd0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
27 changes: 19 additions & 8 deletions kraken/arcaflow_plugin/arcaflow_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

import arcaflow
import os
import yaml
Expand All @@ -6,22 +8,31 @@
from pathlib import Path
from typing import List
from .context_auth import ContextAuth
from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry


def run(scenarios_list: List[str], kubeconfig_path: str):
def run(scenarios_list: List[str], kubeconfig_path: str, telemetry: KrknTelemetry) -> (list[str],list[ScenarioTelemetry]):
scenario_telemetries: list[ScenarioTelemetry] = []
failed_post_scenarios = []
for scenario in scenarios_list:
scenario_telemetry = ScenarioTelemetry()
scenario_telemetry.scenario = scenario
scenario_telemetry.startTimeStamp = time.time()
telemetry.set_parameters_base64(scenario_telemetry,scenario)
engine_args = build_args(scenario)
run_workflow(engine_args, kubeconfig_path)
status_code = run_workflow(engine_args, kubeconfig_path)
scenario_telemetry.endTimeStamp = time.time()
scenario_telemetry.exitStatus = status_code
scenario_telemetries.append(scenario_telemetry)
if status_code != 0:
failed_post_scenarios.append(scenario)
return failed_post_scenarios, scenario_telemetries


def run_workflow(engine_args: arcaflow.EngineArgs, kubeconfig_path: str):
def run_workflow(engine_args: arcaflow.EngineArgs, kubeconfig_path: str) -> int:
set_arca_kubeconfig(engine_args, kubeconfig_path)
exit_status = arcaflow.run(engine_args)
if exit_status != 0:
logging.error(
f"failed to run arcaflow scenario {engine_args.input}"
)
sys.exit(exit_status)
return exit_status


def build_args(input_file: str) -> arcaflow.EngineArgs:
Expand Down
14 changes: 9 additions & 5 deletions run_kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import server as server
import kraken.prometheus.client as promcli
from kraken import plugins
from krkn_lib_kubernetes import KrknLibKubernetes
from krkn_lib_kubernetes import KrknLibKubernetes, KrknTelemetry, ChaosRunTelemetry

KUBE_BURNER_URL = (
"https://github.com/cloud-bulldozer/kube-burner/"
Expand Down Expand Up @@ -102,6 +102,8 @@ def main(cfg):
kubeconfig_path
os.environ["KUBECONFIG"] = str(kubeconfig_path)
kubecli = KrknLibKubernetes(kubeconfig_path=kubeconfig_path)
telemetry = KrknTelemetry()

except NameError:
kubecli.initialize_clients(None)

Expand Down Expand Up @@ -174,7 +176,7 @@ def main(cfg):
# Capture the start time
start_time = int(time.time())
litmus_installed = False

chaos_telemetry = ChaosRunTelemetry()
# Loop to run the chaos starts here
while int(iteration) < iterations and run_signal != "STOP":
# Inject chaos scenarios specified in the config
Expand Down Expand Up @@ -206,9 +208,10 @@ def main(cfg):
)
sys.exit(1)
elif scenario_type == "arcaflow_scenarios":
failed_post_scenarios = arcaflow_plugin.run(
scenarios_list, kubeconfig_path
failed_post_scenarios, scenario_telemetries = arcaflow_plugin.run(
scenarios_list, kubeconfig_path, telemetry
)
chaos_telemetry.scenarios.extend(scenario_telemetries)

elif scenario_type == "plugin_scenarios":
failed_post_scenarios = plugins.run(
Expand Down Expand Up @@ -355,7 +358,8 @@ def main(cfg):

iteration += 1
logging.info("")

# send telemetry
telemetry.send_telemetry(config["telemetry"], chaos_telemetry)
# Capture the end time
end_time = int(time.time())

Expand Down

0 comments on commit 660bd0c

Please sign in to comment.