Skip to content
Snippets Groups Projects
Commit d62880f4 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Adds validation for database name and retention policy in the Graph API

parent b9d6ebde
No related branches found
No related tags found
No related merge requests found
...@@ -69,7 +69,10 @@ class TestGraphAPI(object): ...@@ -69,7 +69,10 @@ class TestGraphAPI(object):
None, "not a timestamp", "A bad request error must have been raised in case of invalid URL parameters."), None, "not a timestamp", "A bad request error must have been raised in case of invalid URL parameters."),
('{"database": "TestInfluxDB", "retention_policy": "autogen", "service_function_chain_instance": "sfc_1", "service_functions": {"nginx": {"measurement_name": "nginx", "response_time_field": "mean(avg_processing_time)"}, "minio": {"measurement_name": "minio_http", "response_time_field": "mean(total_processing_time)/mean(total_requests_count)"}, "apache": {"measurement_name": "apache", "response_time_field": "mean(avg_processing_time)"}}}', ('{"database": "TestInfluxDB", "retention_policy": "autogen", "service_function_chain_instance": "sfc_1", "service_functions": {"nginx": {"measurement_name": "nginx", "response_time_field": "mean(avg_processing_time)"}, "minio": {"measurement_name": "minio_http", "response_time_field": "mean(total_processing_time)/mean(total_requests_count)"}, "apache": {"measurement_name": "apache", "response_time_field": "mean(avg_processing_time)"}}}',
2131212, None, "A bad request error must have been raised in case of invalid URL parameters."), 2131212, None, "A bad request error must have been raised in case of invalid URL parameters."),
('{"database": "DB-not-exists", "retention_policy": "autogen", "service_function_chain_instance": "sfc_1", "service_functions": {"nginx": {"measurement_name": "nginx", "response_time_field": "mean(avg_processing_time)"}, "minio": {"measurement_name": "minio_http", "response_time_field": "mean(total_processing_time)/mean(total_requests_count)"}, "apache": {"measurement_name": "apache", "response_time_field": "mean(avg_processing_time)"}}}',
2131212, 2131212, "A bad request error must have been raised in case of a non-existing database."),
('{"database": "TestInfluxDB", "retention_policy-invalid": "autogen", "service_function_chain_instance": "sfc_1", "service_functions": {"nginx": {"measurement_name": "nginx", "response_time_field": "mean(avg_processing_time)"}, "minio": {"measurement_name": "minio_http", "response_time_field": "mean(total_processing_time)/mean(total_requests_count)"}, "apache": {"measurement_name": "apache", "response_time_field": "mean(avg_processing_time)"}}}',
2131212, 2131212, "A bad request error must have been raised in case of a non-existing retention policy."),
]) ])
def test_build_error_handling(self, body, from_timestamp, to_timestamp, error_msg): def test_build_error_handling(self, body, from_timestamp, to_timestamp, error_msg):
""" """
......
...@@ -74,6 +74,14 @@ class GraphAPI(object): ...@@ -74,6 +74,14 @@ class GraphAPI(object):
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password'])
influx_client = InfluxDBClient(host=self.request.registry.settings['influx_host'], port=self.request.registry.settings['influx_port'], timeout=10) influx_client = InfluxDBClient(host=self.request.registry.settings['influx_host'], port=self.request.registry.settings['influx_port'], timeout=10)
database_name = json_queries["database"]
if database_name not in [db["name"] for db in influx_client.get_list_database()]:
raise HTTPBadRequest("Database {0} not found.".format(database_name))
retention_policy = json_queries["retention_policy"]
if retention_policy not in [rp["name"] for rp in influx_client.get_list_retention_policies(database_name)]:
raise HTTPBadRequest("Retention policy {0} for database {1} not found.".format(retention_policy, database_name))
from_timestamp = params['from'] * 10**9 from_timestamp = params['from'] * 10**9
to_timestamp = params['to'] * 10**9 to_timestamp = params['to'] * 10**9
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment