Skip to content

Commit

Permalink
node scenarios refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed Jun 12, 2023
1 parent fc997fe commit 76d9b5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
34 changes: 26 additions & 8 deletions kraken/node_actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -53,21 +53,39 @@ 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"]:
node_scenario_object = get_node_scenario_object(node_scenario, kubecli)
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
Expand Down
5 changes: 3 additions & 2 deletions run_kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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":
Expand Down

0 comments on commit 76d9b5a

Please sign in to comment.