From 3c2dc54768fd16214a9c007a6a33a73a1df452cb Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 27 May 2024 17:33:28 +0530 Subject: [PATCH 01/12] Add testcases for list metadata API --- tests/scripts/helpers/kruize.py | 34 ++- .../helpers/list_metadata_json_schema.py | 36 +++ .../helpers/list_metadata_json_validate.py | 68 +++++ tests/scripts/helpers/utils.py | 3 + .../rest_apis/test_list_metadata.py | 254 ++++++++++++++++++ 5 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 tests/scripts/helpers/list_metadata_json_schema.py create mode 100644 tests/scripts/helpers/list_metadata_json_validate.py create mode 100644 tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py diff --git a/tests/scripts/helpers/kruize.py b/tests/scripts/helpers/kruize.py index 029e6eaba..c7b588055 100644 --- a/tests/scripts/helpers/kruize.py +++ b/tests/scripts/helpers/kruize.py @@ -330,4 +330,36 @@ def delete_metadata(input_json_file, invalid_header=False): print(response) print("Response status code = ", response.status_code) - return response \ No newline at end of file + return response + + +# Description: This function obtains the metadata from Kruize Autotune using GET dsmetadata API +# Input Parameters: datasource name, cluster name, namespace, verbose - flag indicating granularity of data to be listed +def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=None): + print("\nListing the metadata...") + + query_params = {} + + if datasource is not None: + query_params['datasource'] = datasource + if cluster_name is not None: + query_params['cluster_name'] = cluster_name + if namespace is not None: + query_params['namespace'] = namespace + if verbose is not None: + query_params['verbose'] = verbose + + query_string = "&".join(f"{key}={value}" for key, value in query_params.items()) + + url = URL + "/dsmetadata" + if query_string: + url += "?" + query_string + print("URL = ", url) + print("PARAMS = ", query_params) + response = requests.get(url) + + print("Response status code = ", response.status_code) + print("\n************************************************************") + print(response.text) + print("\n************************************************************") + return response diff --git a/tests/scripts/helpers/list_metadata_json_schema.py b/tests/scripts/helpers/list_metadata_json_schema.py new file mode 100644 index 000000000..56b846153 --- /dev/null +++ b/tests/scripts/helpers/list_metadata_json_schema.py @@ -0,0 +1,36 @@ +list_metadata_json_schema = { + "type": "object", + "properties": { + "datasources": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "datasource_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "clusters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "cluster_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + } + }, + "required": ["cluster_name"] + } + } + } + }, + "required": ["datasource_name", "clusters"] + } + } + } + }, + "required": ["datasources"] +} diff --git a/tests/scripts/helpers/list_metadata_json_validate.py b/tests/scripts/helpers/list_metadata_json_validate.py new file mode 100644 index 000000000..b8a58c2d5 --- /dev/null +++ b/tests/scripts/helpers/list_metadata_json_validate.py @@ -0,0 +1,68 @@ +""" +Copyright (c) 2024, 2024 Red Hat, IBM Corporation and others. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import json +import jsonschema +from jsonschema import FormatChecker +from jsonschema.exceptions import ValidationError +from helpers.import_metadata_json_schema import import_metadata_json_schema + +JSON_NULL_VALUES = ("is not of type 'string'", "is not of type 'integer'", "is not of type 'number'") +VALUE_MISSING = " cannot be empty or null!" + +def validate_list_metadata_json(list_metadata_json, json_schema): + errorMsg = "" + try: + # create a validator with the format checker + print("Validating json against the json schema...") + validator = jsonschema.Draft7Validator(json_schema, format_checker=FormatChecker()) + + # validate the JSON data against the schema + errors = "" + errors = list(validator.iter_errors(list_metadata_json)) + print("Validating json against the json schema...done") + errorMsg = validate_list_metadata_json_values(list_metadata_json) + + if errors: + custom_err = ValidationError(errorMsg) + errors.append(custom_err) + return errors + else: + return errorMsg + except ValidationError as err: + print("Received a VaidationError") + + # Check if the exception is due to empty or null required parameters and prepare the response accordingly + if any(word in err.message for word in JSON_NULL_VALUES): + errorMsg = "Parameters" + VALUE_MISSING + return errorMsg + # Modify the error response in case of additional properties error + elif str(err.message).__contains__('('): + errorMsg = str(err.message).split('(') + return errorMsg[0] + else: + return err.message + +def validate_list_metadata_json_values(metadata): + validationErrorMsg = "" + + for key in metadata.keys(): + + # Check if any of the key is empty or null + if not (str(metadata[key]) and str(metadata[key]).strip()): + validationErrorMsg = ",".join([validationErrorMsg, "Parameters" + VALUE_MISSING]) + + return validationErrorMsg.lstrip(',') + diff --git a/tests/scripts/helpers/utils.py b/tests/scripts/helpers/utils.py index 53b0899c7..a550af6eb 100644 --- a/tests/scripts/helpers/utils.py +++ b/tests/scripts/helpers/utils.py @@ -50,6 +50,9 @@ PERFORMANCE_RECOMMENDATIONS_AVAILABLE = "Performance Recommendations Available" CONTAINER_AND_EXPERIMENT_NAME = " for container : %s for experiment: %s.]" LIST_DATASOURCES_ERROR_MSG = "Given datasource name - \" %s \" either does not exist or is not valid" +LIST_METADATA_DATASOURCE_NAME_ERROR_MSG = "Metadata for a given datasource name - \" %s \" either does not exist or is not valid" +LIST_METADATA_ERROR_MSG = ("Metadata for a given datasource - \" %s \", cluster name - \" %s \", namespace - \"%s \" " + "either does not exist or is not valid") # Kruize Recommendations Notification codes NOTIFICATION_CODE_FOR_RECOMMENDATIONS_AVAILABLE = "111000" diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py new file mode 100644 index 000000000..85bcb4aa2 --- /dev/null +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -0,0 +1,254 @@ +""" +Copyright (c) 2024, 2024 Red Hat, IBM Corporation and others. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import pytest +import json +import sys + +sys.path.append("../../") + +from helpers.fixtures import * +from helpers.kruize import * +from helpers.utils import * +from helpers.import_metadata_json_validate import * +from helpers.list_metadata_json_validate import * +from helpers.list_metadata_json_schema import * +from jinja2 import Environment, FileSystemLoader + +@pytest.mark.sanity +def test_list_metadata_valid_datasource(cluster_type): + """ + Test Description: This test validates GET /dsmetadata by passing an valid datasource name + """ + input_json_file = "../json_files/import_metadata.json" + + form_kruize_url(cluster_type) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + import_metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(import_metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + + response = list_metadata(datasource) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_schema) + assert errorMsg == "" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +def test_list_metadata_without_parameters(cluster_type): + """ + Test Description: This test validates GET /dsmetadata without passing any parameters + """ + input_json_file = "../json_files/import_metadata.json" + + form_kruize_url(cluster_type) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + response = list_metadata() + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + datasource = "null" + assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource + + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +@pytest.mark.parametrize("test_name, expected_status_code, datasource", + [ + ("blank_datasource", 400, ""), + ("null_datasource", 400, "null"), + ("invalid_datasource", 400, "xyz") + ] + ) +def test_list_metadata_invalid_datasource(test_name, expected_status_code, datasource, cluster_type): + """ + Test Description: This test validates the response status code of list metadata API against + invalid input (blank, null, empty) for the json parameters. + """ + print("\n****************************************************") + print("Test datasource_name = ", datasource) + print("****************************************************\n") + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + response = list_metadata(datasource=datasource) + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + cluster_name = "null" + namespace = "null" + assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +@pytest.mark.parametrize("test_name, expected_status_code, cluster_name", + [ + ("blank_cluster_name", 400, ""), + ("null_cluster_name", 400, "null"), + ("invalid_cluster_name", 400, "xyz") + ] + ) +def test_list_metadata_datasource_invalid_cluster_name(test_name, expected_status_code, cluster_name, cluster_type): + """ + Test Description: This test validates the response status code of list metadata API against + invalid input (blank, null, empty) for the json parameters. + """ + print("\n****************************************************") + print("Test cluster_name = ", cluster_name) + print("****************************************************\n") + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + namespace = "null" + response = list_metadata(datasource=datasource, cluster_name=cluster_name) + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +@pytest.mark.parametrize("test_name, expected_status_code, namespace", + [ + ("blank_namespace", 400, ""), + ("null_namespace", 400, "null"), + ("invalid_namespace", 400, "xyz") + ] + ) +def test_list_metadata_datasource_cluster_name_invalid_namespace(test_name, expected_status_code, namespace, cluster_type): + """ + Test Description: This test validates the response status code of list metadata API against + invalid input (blank, null, empty) for the json parameters. + """ + print("\n****************************************************") + print("Test namespace = ", namespace) + print("****************************************************\n") + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + # Currently only default cluster_name is supported by kruize + cluster_name = "default" + response = list_metadata(datasource=datasource, cluster_name=cluster_name, namespace=namespace) + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +def test_list_metadata_without_import_action(cluster_type): + """ + Test Description: This test validates GET /dsmetadata without importing metadata + """ + input_json_file = "../json_files/import_metadata.json" + + form_kruize_url(cluster_type) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + cluster_name = "null" + namespace = "null" + + response = list_metadata(datasource=datasource) + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) From 8673217cafe574df8139cf2b09a23d284a3cba98 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 28 May 2024 18:35:03 +0530 Subject: [PATCH 02/12] Add json schemas for verbose parameter --- ...son_cluster_name_without_verbose_schema.py | 51 +++++++++++ .../list_metadata_json_verbose_true_schema.py | 88 +++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/scripts/helpers/list_metadata_json_cluster_name_without_verbose_schema.py create mode 100644 tests/scripts/helpers/list_metadata_json_verbose_true_schema.py diff --git a/tests/scripts/helpers/list_metadata_json_cluster_name_without_verbose_schema.py b/tests/scripts/helpers/list_metadata_json_cluster_name_without_verbose_schema.py new file mode 100644 index 000000000..61dbb5012 --- /dev/null +++ b/tests/scripts/helpers/list_metadata_json_cluster_name_without_verbose_schema.py @@ -0,0 +1,51 @@ +list_metadata_json_cluster_name_without_verbose_schema = { + "type": "object", + "properties": { + "datasources": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "datasource_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "clusters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "cluster_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "namespaces": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "namespace": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + } + }, + "required": ["namespace"] + } + } + } + }, + "required": ["cluster_name", "namespaces"] + } + } + } + }, + "required": ["datasource_name", "clusters"] + } + } + } + }, + "required": ["datasources"] +} diff --git a/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py b/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py new file mode 100644 index 000000000..5f0588816 --- /dev/null +++ b/tests/scripts/helpers/list_metadata_json_verbose_true_schema.py @@ -0,0 +1,88 @@ +list_metadata_json_verbose_true_schema = { + "type": "object", + "properties": { + "datasources": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "datasource_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "clusters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "cluster_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "namespaces": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "namespace": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "workloads": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "workload_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "workload_type": { + "type": "string" + }, + "containers": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "type": "object", + "properties": { + "container_name": { + "type": "string", + "pattern": "^[a-zA-Z0-9_-]+$" + }, + "container_image_name": { + "type": "string" + } + }, + "required": ["container_name", + "container_image_name"] + } + } + } + }, + "required": ["workload_name", "workload_type", "containers"] + } + } + } + }, + "required": ["namespace"] + } + } + } + }, + "required": ["cluster_name", "namespaces"] + } + } + } + }, + "required": ["datasource_name", "clusters"] + } + } + } + }, + "required": ["datasources"] +} From a921fcfb0febaddb5da9d47faf37fc4695a6ceb2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 28 May 2024 18:37:16 +0530 Subject: [PATCH 03/12] Add parametrized tests with verbose --- tests/scripts/helpers/utils.py | 26 +++ .../rest_apis/test_list_metadata.py | 188 +++++++++++++++++- 2 files changed, 213 insertions(+), 1 deletion(-) diff --git a/tests/scripts/helpers/utils.py b/tests/scripts/helpers/utils.py index a550af6eb..0a8bb1be3 100644 --- a/tests/scripts/helpers/utils.py +++ b/tests/scripts/helpers/utils.py @@ -860,3 +860,29 @@ def validate_recommendation_for_cpu_mem_optimised(recommendations: dict, current assert recommendations["recommendation_engines"][profile]["config"]["limits"]["cpu"]["amount"] == current["limits"]["cpu"]["amount"] assert recommendations["recommendation_engines"][profile]["config"]["requests"]["memory"]["amount"] == current["requests"]["memory"]["amount"] assert recommendations["recommendation_engines"][profile]["config"]["limits"]["memory"]["amount"] == current["limits"]["memory"]["amount"] + + +def validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=None, namespace=None): + datasources = list_metadata_json.get('datasources', {}) + + if len(datasources) != 1: + return False + + # Loop through the datasources dictionary + for key, value in datasources.items(): + assert import_metadata_json['datasource_name'] == value.get('datasource_name') + + if cluster_name is not None: + # Extract clusters from the current datasource + clusters = value.get('clusters', {}) + + for clusters_key, clusters_value in clusters.items(): + assert cluster_name == clusters_value.get('cluster_name'), f"Invalid cluster name: {cluster_name}" + + # If namespace is provided, perform namespace validation + if namespace is not None: + # Extract namespaces from the current cluster + namespaces = clusters[cluster_name].get('namespaces', {}) + + for namespaces_key, namespaces_value in namespaces.items(): + assert namespace == namespaces_value.get('namespace'), f"Invalid namespace: {namespace}" diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py index 85bcb4aa2..d3b1577b6 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -25,12 +25,14 @@ from helpers.import_metadata_json_validate import * from helpers.list_metadata_json_validate import * from helpers.list_metadata_json_schema import * +from helpers.list_metadata_json_verbose_true_schema import * +from helpers.list_metadata_json_cluster_name_without_verbose_schema import * from jinja2 import Environment, FileSystemLoader @pytest.mark.sanity def test_list_metadata_valid_datasource(cluster_type): """ - Test Description: This test validates GET /dsmetadata by passing an valid datasource name + Test Description: This test validates GET /dsmetadata by passing a valid datasource name """ input_json_file = "../json_files/import_metadata.json" @@ -252,3 +254,187 @@ def test_list_metadata_without_import_action(cluster_type): list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + + +@pytest.mark.sanity +def test_list_metadata_without_cluster_name(cluster_type): + """ + Test Description: This test validates GET /dsmetadata with datasource, namespace and without passing cluster name + """ + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + namespace = "monitoring" + + response = list_metadata(datasource=datasource, namespace=namespace) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_schema) + assert errorMsg == "" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.sanity +@pytest.mark.parametrize("verbose", ["true", "false"]) +def test_list_metadata_datasource_and_verbose(verbose, cluster_type): + """ + Test Description: This test validates GET /dsmetadata by passing a valid datasource name and verbose as true or false + """ + + print("\n****************************************************") + print("Test verbose = ", verbose) + print("****************************************************\n") + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + + response = list_metadata(datasource=datasource, verbose=verbose) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + if verbose == "true": + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_verbose_true_schema) + assert errorMsg == "" + else: + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_schema) + assert errorMsg == "" + + # Validate the json values + import_metadata_json = read_json_data_from_file(input_json_file) + validate_list_metadata_parameters(import_metadata_json, list_metadata_json) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.sanity +@pytest.mark.parametrize("verbose", ["true", "false"]) +def test_list_metadata_datasource_cluster_name_and_verbose(verbose, cluster_type): + """ + Test Description: This test validates GET /dsmetadata by passing a valid datasource, cluster name and verbose as + true or false + """ + + print("\n****************************************************") + print("Test verbose = ", verbose) + print("****************************************************\n") + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + # Currently only default cluster is supported by Kruize + cluster_name = "default" + + response = list_metadata(datasource=datasource, cluster_name=cluster_name, verbose=verbose) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + if verbose == "true": + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_verbose_true_schema) + assert errorMsg == "" + else: + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_cluster_name_without_verbose_schema) + assert errorMsg == "" + + # Validate the json values + import_metadata_json = read_json_data_from_file(input_json_file) + validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + +@pytest.mark.sanity +def test_list_metadata_datasource_cluster_name_and_namespace(cluster_type): + """ + Test Description: This test validates GET /dsmetadata by passing a valid datasource, cluster name, namespace and + Note: Verbose is set to be true by default when namespace parameter is passed + """ + + form_kruize_url(cluster_type) + input_json_file = "../json_files/import_metadata.json" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + # Currently only default cluster is supported by Kruize + cluster_name = "default" + namespace = "monitoring" + + response = list_metadata(datasource=datasource, cluster_name=cluster_name, namespace=namespace) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + # Validate the json against the json schema + errorMsg = validate_list_metadata_json(list_metadata_json, list_metadata_json_verbose_true_schema) + assert errorMsg == "" + + # Validate the json values + import_metadata_json = read_json_data_from_file(input_json_file) + validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name, namespace=namespace) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) From 9b533df3a555bfa8bbfbdf2f3a79abde1e889f99 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 28 May 2024 19:21:59 +0530 Subject: [PATCH 04/12] Update tests with delete metadata case and add logging --- tests/scripts/helpers/kruize.py | 9 ++--- .../rest_apis/test_list_metadata.py | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/tests/scripts/helpers/kruize.py b/tests/scripts/helpers/kruize.py index c7b588055..9bf240540 100644 --- a/tests/scripts/helpers/kruize.py +++ b/tests/scripts/helpers/kruize.py @@ -335,7 +335,7 @@ def delete_metadata(input_json_file, invalid_header=False): # Description: This function obtains the metadata from Kruize Autotune using GET dsmetadata API # Input Parameters: datasource name, cluster name, namespace, verbose - flag indicating granularity of data to be listed -def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=None): +def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=None, logging=True): print("\nListing the metadata...") query_params = {} @@ -359,7 +359,8 @@ def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=No response = requests.get(url) print("Response status code = ", response.status_code) - print("\n************************************************************") - print(response.text) - print("\n************************************************************") + if logging: + print("\n************************************************************") + print(response.text) + print("\n************************************************************") return response diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py index d3b1577b6..6515fa85c 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -438,3 +438,38 @@ def test_list_metadata_datasource_cluster_name_and_namespace(cluster_type): response = delete_metadata(input_json_file) print("delete metadata = ", response.status_code) + + +@pytest.mark.negative +def test_list_metadata_after_deleting_metadata(cluster_type): + """ + Test Description: This test validates GET /dsmetadata after deleting imported metadata + """ + input_json_file = "../json_files/import_metadata.json" + + form_kruize_url(cluster_type) + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + # Import metadata using the specified json + response = import_metadata(input_json_file) + metadata_json = response.json() + + # Validate the json against the json schema + errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) + assert errorMsg == "" + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + cluster_name = "null" + namespace = "null" + + response = list_metadata(datasource=datasource) + + list_metadata_json = response.json() + assert response.status_code == ERROR_STATUS_CODE + assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) From 9d603a2dc88cc8176733be0a564efa72f2ba9d26 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 29 May 2024 11:50:46 +0530 Subject: [PATCH 05/12] Update test documentation --- .../Local_monitoring_tests.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/scripts/local_monitoring_tests/Local_monitoring_tests.md b/tests/scripts/local_monitoring_tests/Local_monitoring_tests.md index 7d23513bf..599297096 100644 --- a/tests/scripts/local_monitoring_tests/Local_monitoring_tests.md +++ b/tests/scripts/local_monitoring_tests/Local_monitoring_tests.md @@ -21,6 +21,27 @@ Here are the test scenarios: - Test with invalid values such as blank, null or an invalid value for various keys in the dsmetadata input request json - Validate error messages when the mandatory fields are missing +### **List Metadata API tests** + +Here are the test scenarios: + +- List dsmetadata specifying a valid datasource +- List dsmetadata for a datasource with parameters by specifying the following parameters: + - /dsmetadata?datasource=&verbose=false + - /dsmetadata?datasource=&verbose=true + - /dsmetadata?datasource=&cluster_name=&verbose=false + - /dsmetadata?datasource=&cluster_name=&verbose=true + - /dsmetadata?datasource=&cluster_name=&namespace=&verbose=false + - /dsmetadata?datasource=&cluster_name=&namespace=&verbose=true +- List dsmetadata with invalid parameter values for datasource, cluster_name and namespace + - Non-existing datasource + - Non-existing cluster_name + - Non-existing namespace +- List dsmetadata without specifying any parameters +- List dsmetadata after creating a datasource but without importing metadata +- List dsmetadata with datasource and namespace but without cluster_name +- List the dsmetadata after deleting imported metadata + The above tests are developed using pytest framework and the tests are run using shell script wrapper that does the following: - Deploys kruize in non-CRD mode using the [deploy script](https://github.com/kruize/autotune/blob/master/deploy.sh) from the autotune repo - Creates a resource optimization performance profile using the [createPerformanceProfile API](/design/PerformanceProfileAPI.md) From c3268d656951068e41f307219c6aaf6be927a444 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 31 May 2024 13:19:04 +0530 Subject: [PATCH 06/12] Update response error messages and parameters --- .../helpers/list_datasources_json_schema.py | 2 +- tests/scripts/helpers/utils.py | 7 +++-- .../rest_apis/test_list_metadata.py | 30 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/scripts/helpers/list_datasources_json_schema.py b/tests/scripts/helpers/list_datasources_json_schema.py index 3b14c4069..b05ec100e 100644 --- a/tests/scripts/helpers/list_datasources_json_schema.py +++ b/tests/scripts/helpers/list_datasources_json_schema.py @@ -26,7 +26,7 @@ "format": "uri" } }, - "required": ["name", "provider", "serviceName", "namespace", "url"] + "required": ["name", "provider", "url"] } } }, diff --git a/tests/scripts/helpers/utils.py b/tests/scripts/helpers/utils.py index 0a8bb1be3..d1572aac8 100644 --- a/tests/scripts/helpers/utils.py +++ b/tests/scripts/helpers/utils.py @@ -49,10 +49,11 @@ COST_RECOMMENDATIONS_AVAILABLE = "Cost Recommendations Available" PERFORMANCE_RECOMMENDATIONS_AVAILABLE = "Performance Recommendations Available" CONTAINER_AND_EXPERIMENT_NAME = " for container : %s for experiment: %s.]" -LIST_DATASOURCES_ERROR_MSG = "Given datasource name - \" %s \" either does not exist or is not valid" -LIST_METADATA_DATASOURCE_NAME_ERROR_MSG = "Metadata for a given datasource name - \" %s \" either does not exist or is not valid" -LIST_METADATA_ERROR_MSG = ("Metadata for a given datasource - \" %s \", cluster name - \" %s \", namespace - \"%s \" " +LIST_DATASOURCES_ERROR_MSG = "Given datasource name - %s either does not exist or is not valid" +LIST_METADATA_DATASOURCE_NAME_ERROR_MSG = "Metadata for a given datasource name - %s either does not exist or is not valid" +LIST_METADATA_ERROR_MSG = ("Metadata for a given datasource - %s, cluster name - %s, namespace - %s " "either does not exist or is not valid") +LIST_METADATA_DATASOURCE_NAME_CLUSTER_NAME_ERROR_MSG = "Metadata for a given datasource name - %s, cluster_name - %s either does not exist or is not valid" # Kruize Recommendations Notification codes NOTIFICATION_CODE_FOR_RECOMMENDATIONS_AVAILABLE = "111000" diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py index 6515fa85c..ebb467b9d 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -132,9 +132,7 @@ def test_list_metadata_invalid_datasource(test_name, expected_status_code, datas list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE - cluster_name = "null" - namespace = "null" - assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource response = delete_metadata(input_json_file) @@ -174,12 +172,12 @@ def test_list_metadata_datasource_invalid_cluster_name(test_name, expected_statu json_data = json.load(open(input_json_file)) datasource = json_data['datasource_name'] - namespace = "null" + response = list_metadata(datasource=datasource, cluster_name=cluster_name) list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE - assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_CLUSTER_NAME_ERROR_MSG % (datasource, cluster_name) response = delete_metadata(input_json_file) @@ -235,7 +233,8 @@ def test_list_metadata_datasource_cluster_name_invalid_namespace(test_name, expe @pytest.mark.negative def test_list_metadata_without_import_action(cluster_type): """ - Test Description: This test validates GET /dsmetadata without importing metadata + Test Description: This test validates GET /dsmetadata without importing metadata - resulting in an error on + trying to list metadata as there is no metadata imported """ input_json_file = "../json_files/import_metadata.json" @@ -246,14 +245,12 @@ def test_list_metadata_without_import_action(cluster_type): json_data = json.load(open(input_json_file)) datasource = json_data['datasource_name'] - cluster_name = "null" - namespace = "null" response = list_metadata(datasource=datasource) list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE - assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource @pytest.mark.sanity @@ -278,7 +275,10 @@ def test_list_metadata_without_cluster_name(cluster_type): json_data = json.load(open(input_json_file)) datasource = json_data['datasource_name'] - namespace = "monitoring" + if cluster_type == "minikube": + namespace = "monitoring" + elif cluster_type == "openshift": + namespace = "openshift-monitoring" response = list_metadata(datasource=datasource, namespace=namespace) @@ -421,7 +421,11 @@ def test_list_metadata_datasource_cluster_name_and_namespace(cluster_type): datasource = json_data['datasource_name'] # Currently only default cluster is supported by Kruize cluster_name = "default" - namespace = "monitoring" + + if cluster_type == "minikube": + namespace = "monitoring" + elif cluster_type == "openshift": + namespace = "openshift-monitoring" response = list_metadata(datasource=datasource, cluster_name=cluster_name, namespace=namespace) @@ -465,11 +469,9 @@ def test_list_metadata_after_deleting_metadata(cluster_type): json_data = json.load(open(input_json_file)) datasource = json_data['datasource_name'] - cluster_name = "null" - namespace = "null" response = list_metadata(datasource=datasource) list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE - assert list_metadata_json['message'] == LIST_METADATA_ERROR_MSG % (datasource, cluster_name, namespace) + assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource From 2a4989ded714089d987b93a09bb62c3de06c5677 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Jun 2024 13:42:01 +0530 Subject: [PATCH 07/12] Update repeated metadata import testcase --- tests/scripts/helpers/utils.py | 46 ++++++++++++++++++- .../local_monitoring_tests/requirements.txt | 3 +- .../rest_apis/test_import_metadata.py | 46 ++++++++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/tests/scripts/helpers/utils.py b/tests/scripts/helpers/utils.py index d1572aac8..b469f8734 100644 --- a/tests/scripts/helpers/utils.py +++ b/tests/scripts/helpers/utils.py @@ -21,6 +21,7 @@ import time import math from datetime import datetime, timedelta +from kubernetes import client, config SUCCESS_STATUS_CODE = 201 SUCCESS_200_STATUS_CODE = 200 @@ -885,5 +886,46 @@ def validate_list_metadata_parameters(import_metadata_json, list_metadata_json, # Extract namespaces from the current cluster namespaces = clusters[cluster_name].get('namespaces', {}) - for namespaces_key, namespaces_value in namespaces.items(): - assert namespace == namespaces_value.get('namespace'), f"Invalid namespace: {namespace}" + assert namespace in [ns.get('namespace') for ns in namespaces.values()], f"Invalid namespace: {namespace}" + + +def create_namespace(namespace_name): + # Load kube config + config.load_kube_config() + + # Create a V1Namespace object + namespace = client.V1Namespace( + metadata=client.V1ObjectMeta(name=namespace_name) + ) + + # Create a Kubernetes API client + api_instance = client.CoreV1Api() + + # Create the namespace + try: + api_instance.create_namespace(namespace) + + print(f"Namespace '{namespace_name}' created successfully.") + except client.exceptions.ApiException as e: + if e.status == 409: + print(f"Namespace '{namespace_name}' already exists.") + else: + print(f"Error creating namespace: {e}") + + +def delete_namespace(namespace_name): + # Load kube config + config.load_kube_config() + + # Create a Kubernetes API client + api_instance = client.CoreV1Api() + + # Delete the namespace + try: + api_instance.delete_namespace(name=namespace_name) + print(f"Namespace '{namespace_name}' deleted successfully.") + except client.exceptions.ApiException as e: + if e.status == 404: + print(f"Namespace '{namespace_name}' not found.") + else: + print(f"Exception deleting namespace: {e}") \ No newline at end of file diff --git a/tests/scripts/local_monitoring_tests/requirements.txt b/tests/scripts/local_monitoring_tests/requirements.txt index b14263e72..a60c2f97a 100644 --- a/tests/scripts/local_monitoring_tests/requirements.txt +++ b/tests/scripts/local_monitoring_tests/requirements.txt @@ -1,4 +1,5 @@ pytest requests jinja2 -pytest-html==3.2.0 \ No newline at end of file +pytest-html==3.2.0 +kubernetes \ No newline at end of file diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py index b68627683..a85b1cfe3 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py @@ -161,6 +161,9 @@ def test_repeated_metadata_import(cluster_type): response = delete_metadata(input_json_file) print("delete metadata = ", response.status_code) + create_namespace("testing") + time.sleep(30) + # Import metadata using the specified json response = import_metadata(input_json_file) metadata_json = response.json() @@ -171,6 +174,29 @@ def test_repeated_metadata_import(cluster_type): errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) assert errorMsg == "" + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + # Currently only default cluster_name is supported by kruize + cluster_name = "default" + response = list_metadata(datasource=datasource, cluster_name=cluster_name) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + # Validate the json values + import_metadata_json = read_json_data_from_file(input_json_file) + validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name, namespace="testing") + + response = delete_metadata(input_json_file) + print("delete metadata = ", response.status_code) + + delete_namespace("testing") + time.sleep(15) + + create_namespace("repeated-metadata-import") + create_namespace("local-monitoring-test") + time.sleep(30) + # Import metadata using the specified json response = import_metadata(input_json_file) metadata_json = response.json() @@ -181,5 +207,23 @@ def test_repeated_metadata_import(cluster_type): errorMsg = validate_import_metadata_json(metadata_json, import_metadata_json_schema) assert errorMsg == "" + json_data = json.load(open(input_json_file)) + datasource = json_data['datasource_name'] + # Currently only default cluster_name is supported by kruize + cluster_name = "default" + response = list_metadata(datasource=datasource, cluster_name=cluster_name) + + list_metadata_json = response.json() + assert response.status_code == SUCCESS_200_STATUS_CODE + + # Validate the json values + import_metadata_json = read_json_data_from_file(input_json_file) + validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name, namespace="repeated-metadata-import") + validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name, namespace="local-monitoring-test") + + #validate namespaces response = delete_metadata(input_json_file) - print("delete metadata = ", response.status_code) \ No newline at end of file + print("delete metadata = ", response.status_code) + + delete_namespace("repeated-metadata-import") + delete_namespace("local-monitoring-test") \ No newline at end of file From 7677066741b2369a5432810154e14792dbed4447 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Jun 2024 14:11:53 +0530 Subject: [PATCH 08/12] Update rm requirements --- tests/scripts/remote_monitoring_tests/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/remote_monitoring_tests/requirements.txt b/tests/scripts/remote_monitoring_tests/requirements.txt index 1b6deedb9..a60c2f97a 100644 --- a/tests/scripts/remote_monitoring_tests/requirements.txt +++ b/tests/scripts/remote_monitoring_tests/requirements.txt @@ -2,3 +2,4 @@ pytest requests jinja2 pytest-html==3.2.0 +kubernetes \ No newline at end of file From 158461b8135a104e6f5c14ff3112c57d77e2b48d Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Jun 2024 17:12:52 +0530 Subject: [PATCH 09/12] Add missing EOF --- tests/scripts/helpers/kruize.py | 1 + .../local_monitoring_tests/rest_apis/test_list_metadata.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/scripts/helpers/kruize.py b/tests/scripts/helpers/kruize.py index 9bf240540..25cb7856d 100644 --- a/tests/scripts/helpers/kruize.py +++ b/tests/scripts/helpers/kruize.py @@ -364,3 +364,4 @@ def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=No print(response.text) print("\n************************************************************") return response + diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py index ebb467b9d..b4118da2a 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -475,3 +475,4 @@ def test_list_metadata_after_deleting_metadata(cluster_type): list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource + From c562b1cccc7ca9af63b35c22382e43086aa2fd1d Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Jun 2024 19:18:38 +0530 Subject: [PATCH 10/12] fix eof --- tests/scripts/helpers/kruize.py | 1 - .../local_monitoring_tests/rest_apis/test_list_metadata.py | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/scripts/helpers/kruize.py b/tests/scripts/helpers/kruize.py index 25cb7856d..9bf240540 100644 --- a/tests/scripts/helpers/kruize.py +++ b/tests/scripts/helpers/kruize.py @@ -364,4 +364,3 @@ def list_metadata(datasource=None, cluster_name=None, namespace=None, verbose=No print(response.text) print("\n************************************************************") return response - diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py index b4118da2a..ebb467b9d 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_list_metadata.py @@ -475,4 +475,3 @@ def test_list_metadata_after_deleting_metadata(cluster_type): list_metadata_json = response.json() assert response.status_code == ERROR_STATUS_CODE assert list_metadata_json['message'] == LIST_METADATA_DATASOURCE_NAME_ERROR_MSG % datasource - From 3be5146bcdd74b566cd664c42e949c92c3aad8a2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Jun 2024 19:53:58 +0530 Subject: [PATCH 11/12] format missing eof --- tests/scripts/helpers/utils.py | 2 +- tests/scripts/local_monitoring_tests/requirements.txt | 2 +- .../local_monitoring_tests/rest_apis/test_import_metadata.py | 2 +- tests/scripts/remote_monitoring_tests/requirements.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/scripts/helpers/utils.py b/tests/scripts/helpers/utils.py index b469f8734..3899875c4 100644 --- a/tests/scripts/helpers/utils.py +++ b/tests/scripts/helpers/utils.py @@ -928,4 +928,4 @@ def delete_namespace(namespace_name): if e.status == 404: print(f"Namespace '{namespace_name}' not found.") else: - print(f"Exception deleting namespace: {e}") \ No newline at end of file + print(f"Exception deleting namespace: {e}") diff --git a/tests/scripts/local_monitoring_tests/requirements.txt b/tests/scripts/local_monitoring_tests/requirements.txt index a60c2f97a..f3a073a07 100644 --- a/tests/scripts/local_monitoring_tests/requirements.txt +++ b/tests/scripts/local_monitoring_tests/requirements.txt @@ -2,4 +2,4 @@ pytest requests jinja2 pytest-html==3.2.0 -kubernetes \ No newline at end of file +kubernetes diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py index a85b1cfe3..598c4d05f 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py @@ -226,4 +226,4 @@ def test_repeated_metadata_import(cluster_type): print("delete metadata = ", response.status_code) delete_namespace("repeated-metadata-import") - delete_namespace("local-monitoring-test") \ No newline at end of file + delete_namespace("local-monitoring-test") diff --git a/tests/scripts/remote_monitoring_tests/requirements.txt b/tests/scripts/remote_monitoring_tests/requirements.txt index a60c2f97a..f3a073a07 100644 --- a/tests/scripts/remote_monitoring_tests/requirements.txt +++ b/tests/scripts/remote_monitoring_tests/requirements.txt @@ -2,4 +2,4 @@ pytest requests jinja2 pytest-html==3.2.0 -kubernetes \ No newline at end of file +kubernetes From f785bed90d45880404ee20bd9f7856aa72636ab7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 Jun 2024 16:21:23 +0530 Subject: [PATCH 12/12] Remove manual delete between repeated metadata imports --- .../local_monitoring_tests/rest_apis/test_import_metadata.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py index 598c4d05f..29fde5099 100644 --- a/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py +++ b/tests/scripts/local_monitoring_tests/rest_apis/test_import_metadata.py @@ -187,9 +187,6 @@ def test_repeated_metadata_import(cluster_type): import_metadata_json = read_json_data_from_file(input_json_file) validate_list_metadata_parameters(import_metadata_json, list_metadata_json, cluster_name=cluster_name, namespace="testing") - response = delete_metadata(input_json_file) - print("delete metadata = ", response.status_code) - delete_namespace("testing") time.sleep(15)