From db6d0b07b84ef242c10090b1596a7404fb19401b Mon Sep 17 00:00:00 2001 From: Shashank Reddy Boyapally Date: Fri, 13 Sep 2024 12:04:59 -0400 Subject: [PATCH] changed tests and trivial bug fix Signed-off-by: Shashank Reddy Boyapally --- orion.py | 2 +- pkg/algorithms/algorithm.py | 2 +- pkg/runTest.py | 6 +++-- test.bats | 44 +++++++++++++++++++++++++++---------- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/orion.py b/orion.py index 31e81c2..4935372 100644 --- a/orion.py +++ b/orion.py @@ -128,7 +128,7 @@ def cmd_analysis(**kwargs): with open(output_file_name, 'w', encoding="utf-8") as file: file.write(str(result_table)) if regression_flag: - sys.exit(1) + sys.exit(2) ## regression detected diff --git a/pkg/algorithms/algorithm.py b/pkg/algorithms/algorithm.py index 16d3744..dd85e47 100644 --- a/pkg/algorithms/algorithm.py +++ b/pkg/algorithms/algorithm.py @@ -85,7 +85,7 @@ def output_junit(self) -> Tuple[str,str, bool]: Returns: _type_: return """ - test_name, data_json = self.output_json() + test_name, data_json, _ = self.output_json() data_json = json.loads(data_json) data_junit = json_to_junit( test_name=test_name, diff --git a/pkg/runTest.py b/pkg/runTest.py index 769a018..5948651 100644 --- a/pkg/runTest.py +++ b/pkg/runTest.py @@ -1,6 +1,7 @@ """ run test """ +import sys from typing import Any, Dict from fmatch.matcher import Matcher from fmatch.logrus import SingletonLogger @@ -43,15 +44,16 @@ def run(**kwargs: dict[str, Any]) -> dict[str, Any]: #pylint: disable = R0914 kwargs, start_timestamp, ) + if fingerprint_matched_df is None: - return None + sys.exit(3) # No data present if kwargs["hunter_analyze"]: algorithm_name = cnsts.EDIVISIVE elif kwargs["anomaly_detection"]: algorithm_name = cnsts.ISOLATION_FOREST else: - return None + return None, None algorithmFactory = AlgorithmFactory() algorithm = algorithmFactory.instantiate_algorithm( diff --git a/test.bats b/test.bats index a48f0ce..e415f04 100644 --- a/test.bats +++ b/test.bats @@ -6,13 +6,21 @@ run_cmd(){ echo "$@" ${@} + EXIT_CODE=$? + + if [ $EXIT_CODE -eq 2 ]; then + echo "Exit code 2 encountered, regression detected, treating as success" + return 0 + elif [ $EXIT_CODE -eq 3 ]; then + echo "Exit code 3 encountered, not enough data" + return 0 + else + return $EXIT_CODE + fi } setup() { # Make a note of daemon PID - orion daemon --port 8080 & - DAEMON_PID=$! - echo "Orion daemon started with PID $DAEMON_PID" export ES_SERVER="$QE_ES_SERVER" export es_metadata_index="perf_scale_ci*" export es_benchmark_index="ripsaw-kube-burner*" @@ -24,11 +32,11 @@ setup() { } @test "orion cmd payload scale 4.15 " { - run_cmd orion cmd --config "examples/payload-scale-415.yaml" --lookback 5d + run_cmd orion cmd --config "examples/payload-scale-415.yaml" --lookback 5d --hunter-analyze } @test "orion cmd payload scale 4.16 without lookback period " { - run_cmd orion cmd --config "examples/payload-scale-416.yaml" + run_cmd orion cmd --config "examples/payload-scale-416.yaml" --hunter-analyze } @test "orion cmd readout control plane cdv2 with text output " { @@ -45,6 +53,7 @@ setup() { @test "orion cmd readout netperf tcp with junit output " { + export es_benchmark_index="k8s-netperf" run_cmd orion cmd --config "examples/readout-netperf-tcp.yaml" --output-format junit --hunter-analyze --save-output-path=output.xml } @@ -73,23 +82,36 @@ setup() { } @test "orion daemon small scale cluster density with anomaly detection " { + orion daemon --port 8080 & + DAEMON_PID=$! + echo "Orion daemon started with PID $DAEMON_PID" run_cmd curl http://127.0.0.1:8080/daemon/anomaly?convert_tinyurl=True&test_name=small-scale-cluster-density + if [ ! -z "$DAEMON_PID" ]; then + kill $DAEMON_PID + echo "Orion daemon with PID $DAEMON_PID killed" + fi } @test "orion daemon small scale node density cni with changepoint detection " { + orion daemon --port 8080 & + DAEMON_PID=$! + echo "Orion daemon started with PID $DAEMON_PID" run_cmd curl http://127.0.0.1:8080/daemon/changepoint?filter_changepoints=true&test_name=small-scale-node-density-cni + if [ ! -z "$DAEMON_PID" ]; then + kill $DAEMON_PID + echo "Orion daemon with PID $DAEMON_PID killed" + fi } @test "orion daemon trt payload cluster density with version parameter " { + orion daemon --port 8080 & + DAEMON_PID=$! + echo "Orion daemon started with PID $DAEMON_PID" run_cmd curl http://127.0.0.1:8080/daemon/changepoint?version=4.17&filter_changepoints=false&test_name=trt-payload-cluster-density -} - -teardown() { - # Kill the daemon using its PID if [ ! -z "$DAEMON_PID" ]; then kill $DAEMON_PID echo "Orion daemon with PID $DAEMON_PID killed" - else - echo "No daemon PID found" fi } + +