Skip to content

Commit

Permalink
Validate mandatory slo fields and compress logging
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyabiradar07 committed Aug 8, 2024
1 parent 7578eea commit 403bacc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/scripts/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
METRIC_PROFILE_NOT_FOUND_MSG = "No metric profiles found!"
INVALID_LIST_METRIC_PROFILE_INPUT_QUERY = "The query param(s) - [%s] is/are invalid"
LIST_METRIC_PROFILES_INVALID_NAME = "Given metric profile name - %s is not valid"
CREATE_METRIC_PROFILE_MISSING_MANDATORY_FIELD_MSG = "Validation failed: JSONObject[\"%s\"] not found."
CREATE_METRIC_PROFILE_MISSING_MANDATORY_PARAMETERS_MSG = "Validation failed: Missing mandatory parameters: [%s] "

# Kruize Recommendations Notification codes
NOTIFICATION_CODE_FOR_RECOMMENDATIONS_AVAILABLE = "111000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
("kind", ERROR_500_STATUS_CODE, ERROR_STATUS),
("metadata", ERROR_500_STATUS_CODE, ERROR_STATUS),
("name", ERROR_500_STATUS_CODE, ERROR_STATUS),
("slo", ERROR_500_STATUS_CODE, ERROR_STATUS)
("slo", ERROR_500_STATUS_CODE, ERROR_STATUS),
("direction", ERROR_STATUS_CODE, ERROR_STATUS),
("objective_function", ERROR_500_STATUS_CODE, ERROR_STATUS),
("function_type", ERROR_STATUS_CODE, ERROR_STATUS),
("function_variables", ERROR_500_STATUS_CODE, ERROR_STATUS),
("name", ERROR_500_STATUS_CODE, ERROR_STATUS),
("datasource", ERROR_500_STATUS_CODE, ERROR_STATUS),
("value_type", ERROR_500_STATUS_CODE, ERROR_STATUS),
("aggregation_functions", ERROR_500_STATUS_CODE, ERROR_STATUS),
("function", ERROR_500_STATUS_CODE, ERROR_STATUS),
("query", ERROR_500_STATUS_CODE, ERROR_STATUS)
]


Expand Down Expand Up @@ -157,7 +167,7 @@ def test_create_multiple_metric_profiles(cluster_type):
assert data['status'] == SUCCESS_STATUS
assert data['message'] == CREATE_METRIC_PROFILE_SUCCESS_MSG % metric_profile_name

response = list_metric_profiles(name=metric_profile_name)
response = list_metric_profiles(name=metric_profile_name, logging=False)
metric_profile_json = response.json()

assert response.status_code == SUCCESS_200_STATUS_CODE
Expand Down Expand Up @@ -221,6 +231,26 @@ def test_create_metric_profiles_mandatory_fields(cluster_type, field, expected_s
json_data['metadata'].pop("name", None)
elif field == "slo":
json_data.pop("slo", None)
elif field == "direction":
json_data['slo'].pop("direction", None)
elif field == "objective_function":
json_data['slo'].pop("objective_function", None)
elif field == "function_type":
json_data['slo']['objective_function'].pop("function_type", None)
elif field == "function_variables":
json_data['slo'].pop("function_variables", None)
elif field == "name":
json_data['slo']['function_variables'].pop("name", None)
elif field == "datasource":
json_data['slo']['function_variables'][0].pop("datasource", None)
elif field == "value_type":
json_data['slo']['function_variables'][0].pop("value_type", None)
elif field == "aggregation_functions":
json_data['slo']['function_variables'][0].pop("aggregation_functions", None)
elif field == "function":
json_data['slo']['function_variables'][0]['aggregation_functions'][0].pop("function", None)
elif field == "query":
json_data['slo']['function_variables'][0]['aggregation_functions'][0].pop("query", None)

print("\n*****************************************")
print(json_data)
Expand All @@ -240,5 +270,10 @@ def test_create_metric_profiles_mandatory_fields(cluster_type, field, expected_s
f"Mandatory field check failed for {field} actual - {response.status_code} expected - {expected_status_code}"
assert data['status'] == expected_status

if response.status_code == ERROR_500_STATUS_CODE:
assert data['message'] == MISSING_MANDATORY_FIELD_MSG % field
else:
assert data['message'] == MISSING_MANDATORY_PARAMETERS_MSG % field

response = delete_metric_profile(input_json_file)
print("delete metric profile = ", response.status_code)

0 comments on commit 403bacc

Please sign in to comment.