Skip to content

Commit

Permalink
adding few more cerberus check updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paigerube14 committed Oct 7, 2024
1 parent efbe66f commit 7e9182c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
81 changes: 42 additions & 39 deletions krkn/cerberus/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
check_application_routes = ""
cerberus_url = None
exit_on_failure = False
cerberus_enabled = False

def set_url(config):
global exit_on_failure
exit_on_failure = get_yaml_item_value(config["kraken"], "exit_on_failure", False)
if config["cerberus"]["cerberus_enabled"]:
global cerberus_enabled
cerberus_enabled = get_yaml_item_value(config["cerberus"],"cerberus_enabled", False)
if cerberus_enabled:
global cerberus_url
cerberus_url = get_yaml_item_value(config["cerberus"],"cerberus_url", "")
global check_application_routes
Expand All @@ -25,50 +28,50 @@ def get_status(start_time, end_time):
cerberus_status = True
check_application_routes = False
application_routes_status = True

if not cerberus_url:
logging.error(
"url where Cerberus publishes True/False signal "
"is not provided."
)
sys.exit(1)
cerberus_status = requests.get(cerberus_url, timeout=60).content
cerberus_status = True if cerberus_status == b"True" else False
if cerberus_enabled:
if not cerberus_url:
logging.error(
"url where Cerberus publishes True/False signal "
"is not provided."
)
sys.exit(1)
cerberus_status = requests.get(cerberus_url, timeout=60).content
cerberus_status = True if cerberus_status == b"True" else False

# Fail if the application routes monitored by cerberus
# experience downtime during the chaos
if check_application_routes:
application_routes_status, unavailable_routes = application_status(
cerberus_url,
start_time,
end_time
)
if not application_routes_status:
# Fail if the application routes monitored by cerberus
# experience downtime during the chaos
if check_application_routes:
application_routes_status, unavailable_routes = application_status(
cerberus_url,
start_time,
end_time
)
if not application_routes_status:
logging.error(
"Application routes: %s monitored by cerberus "
"encountered downtime during the run, failing"
% unavailable_routes
)
else:
logging.info(
"Application routes being monitored "
"didn't encounter any downtime during the run!"
)

if not cerberus_status:
logging.error(
"Application routes: %s monitored by cerberus "
"encountered downtime during the run, failing"
% unavailable_routes
"Received a no-go signal from Cerberus, looks like "
"the cluster is unhealthy. Please check the Cerberus "
"report for more details. Test failed."
)

if not application_routes_status or not cerberus_status:
sys.exit(1)
else:
logging.info(
"Application routes being monitored "
"didn't encounter any downtime during the run!"
"Received a go signal from Ceberus, the cluster is healthy. "
"Test passed."
)

if not cerberus_status:
logging.error(
"Received a no-go signal from Cerberus, looks like "
"the cluster is unhealthy. Please check the Cerberus "
"report for more details. Test failed."
)

if not application_routes_status or not cerberus_status:
sys.exit(1)
else:
logging.info(
"Received a go signal from Ceberus, the cluster is healthy. "
"Test passed."
)
return cerberus_status


Expand Down
1 change: 0 additions & 1 deletion krkn/scenario_plugins/abstract_scenario_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,5 @@ def run_scenarios(
cerberus.publish_kraken_status(start_time, end_time)
logging.info(f"wating {wait_duration} before running the next scenario")
time.sleep(wait_duration)


return failed_scenarios, scenario_telemetries
4 changes: 1 addition & 3 deletions krkn/scenario_plugins/native/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, steps: List[PluginStep]):
def unserialize_scenario(self, file: str) -> Any:
return serialization.load_from_file(abspath(file))

def run(self, file: str, kubeconfig_path: str, kraken_config: str, run_uuid: str):
def run(self, file: str, kubeconfig_path: str, run_uuid: str):
"""
Run executes a series of steps
"""
Expand Down Expand Up @@ -98,8 +98,6 @@ def run(self, file: str, kubeconfig_path: str, kraken_config: str, run_uuid: str
unserialized_input = step.schema.input.unserialize(entry["config"])
if "kubeconfig_path" in step.schema.input.properties:
unserialized_input.kubeconfig_path = kubeconfig_path
if "kraken_config" in step.schema.input.properties:
unserialized_input.kraken_config = kraken_config
output_id, output_data = step.schema(
params=unserialized_input, run_id=run_uuid
)
Expand Down
8 changes: 1 addition & 7 deletions krkn/scenario_plugins/pvc/pvc_scenario_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from krkn_lib.k8s import KrknKubernetes
from krkn_lib.models.telemetry import ScenarioTelemetry
from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift
from krkn_lib.utils import get_yaml_item_value, log_exception
from krkn_lib.utils import get_yaml_item_value

from krkn import cerberus, utils
from krkn.scenario_plugins.abstract_scenario_plugin import AbstractScenarioPlugin


Expand All @@ -18,7 +17,6 @@ def run(
self,
run_uuid: str,
scenario: str,
krkn_config: dict[str, any],
lib_telemetry: KrknTelemetryOpenshift,
scenario_telemetry: ScenarioTelemetry,
) -> int:
Expand Down Expand Up @@ -173,7 +171,6 @@ def run(
)
)

start_time = int(time.time())
# Create temp file in the PVC
full_path = "%s/%s" % (str(mount_path), str(file_name))
command = "fallocate -l $((%s*1024)) %s" % (
Expand Down Expand Up @@ -233,7 +230,6 @@ def run(
)
)

start_time = int(time.time())
# Create temp file in the PVC
full_path = "%s/%s" % (str(mount_path), str(file_name))
command = "fallocate -l $((%s*1024)) %s" % (
Expand Down Expand Up @@ -269,8 +265,6 @@ def run(
file_size_kb,
lib_telemetry.get_lib_kubernetes(),
)
end_time = int(time.time())
cerberus.publish_kraken_status(krkn_config, [], start_time, end_time)
except (RuntimeError, Exception) as e:
logging.error("PvcScenarioPlugin exiting due to Exception %s" % e)
return 1
Expand Down

0 comments on commit 7e9182c

Please sign in to comment.