Skip to content

Commit

Permalink
plugin scenarios refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed Jun 12, 2023
1 parent 7fd63d5 commit 80a0a9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions kraken/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from kraken.plugins.run_python_plugin import run_python_file
from kraken.plugins.network.ingress_shaping import network_chaos
from kraken.plugins.pod_network_outage.pod_network_outage_plugin import pod_outage
from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry


@dataclasses.dataclass
Expand Down Expand Up @@ -218,16 +219,25 @@ def json_schema(self):
)


def run(scenarios: List[str], kubeconfig_path: str, kraken_config: str, failed_post_scenarios: List[str], wait_duration: int) -> List[str]:
def run(scenarios: List[str], kubeconfig_path: str, kraken_config: str, failed_post_scenarios: List[str], wait_duration: int, telemetry: KrknTelemetry) -> (List[str], list[ScenarioTelemetry]):
scenario_telemetries: list[ScenarioTelemetry] = []
for scenario in scenarios:
scenario_telemetry = ScenarioTelemetry()
scenario_telemetry.scenario = scenario
scenario_telemetry.startTimeStamp = time.time()
telemetry.set_parameters_base64(scenario_telemetry, scenario)
logging.info('scenario '+ str(scenario))
try:
PLUGINS.run(scenario, kubeconfig_path, kraken_config)
scenario_telemetry.exitStatus = 0
except Exception as e:
scenario_telemetry.exitStatus = 1
failed_post_scenarios.append(scenario)
logging.error("Error while running {}: {}".format(scenario, e))
return failed_post_scenarios
logging.info("Waiting for the specified duration: %s" % (wait_duration))
scenario_telemetry.endTimeStamp = time.time()
scenario_telemetries.append(scenario_telemetry)
time.sleep(wait_duration)

return failed_post_scenarios
return failed_post_scenarios, scenario_telemetries
3 changes: 2 additions & 1 deletion run_kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def main(cfg):
chaos_telemetry.scenarios.extend(scenario_telemetries)

elif scenario_type == "plugin_scenarios":
failed_post_scenarios = plugins.run(
failed_post_scenarios, scenario_telemetries = plugins.run(
scenarios_list,
kubeconfig_path,
kraken_config,
failed_post_scenarios,
wait_duration,
)
chaos_telemetry.scenarios.extend(scenario_telemetries)
# krkn_lib_kubernetes
elif scenario_type == "container_scenarios":
logging.info("Running container scenarios")
Expand Down

0 comments on commit 80a0a9e

Please sign in to comment.