diff --git a/src/common/pg_impl.py b/src/common/pg_impl.py index 2bc1211..42d0cf1 100644 --- a/src/common/pg_impl.py +++ b/src/common/pg_impl.py @@ -47,7 +47,7 @@ def __del__(self): def get_environment_type_names(self): """ - gets the test types + gets the test environment types :return: """ @@ -79,7 +79,7 @@ def get_test_names(self): def get_dbms_image_names(self): """ - gets the DBMS types + gets the DBMS image names :return: """ @@ -95,7 +95,7 @@ def get_dbms_image_names(self): def get_os_image_names(self): """ - gets the test types + gets the os image names :return: """ @@ -111,7 +111,7 @@ def get_os_image_names(self): def get_test_request_names(self): """ - gets the test types + gets the irods test request names :return: """ @@ -125,6 +125,22 @@ def get_test_request_names(self): # return the data return ret_val + def get_test_request_name_exists(self, request_name): + """ + gets true/false if the request name already exists + + :return: + """ + + # create the sql + sql: str = f"SELECT public.get_test_request_name_exists('{request_name}');" + + # get the data + ret_val = self.exec_sql('irods-sv', sql) + + # return the data + return ret_val + def get_run_status(self, request_group): """ gets the run status diff --git a/src/common/utils.py b/src/common/utils.py index b20e469..8491f8e 100644 --- a/src/common/utils.py +++ b/src/common/utils.py @@ -13,6 +13,7 @@ from pathlib import Path from enum import Enum from src.common.logger import LoggingUtil +from src.common.pg_impl import PGImplementation class GenUtils: @@ -45,7 +46,7 @@ def get_log_file_list(filter_param: str = ''): # get the log file path log_file_path: str = LoggingUtil.get_log_path() - # if a filter param was declared make it a wildcard + # if a filter param was declared, make it a wildcard if filter_param: filter_param += '*' @@ -60,7 +61,7 @@ def get_log_file_list(filter_param: str = ''): # save the absolute file path, endpoint URL, and file size in a dict ret_val.update({f"{file_path.name}_{counter}": {'file_path': final_path[1:], 'file_size': f'{file_path.stat().st_size} bytes'}}) - # if nothing was found return a message + # if nothing was found, return a message if len(ret_val) == 0 and filter_param: ret_val = {'Warning': f'Nothing found using your filter parameter ({filter_param[:-1]})'} @@ -79,6 +80,42 @@ def check_freeze_status() -> bool: # return to the caller return freeze_mode + @staticmethod + def validate_settings_input(workflow_type, run_status, package_dir, tests, request_group, db_info) -> str: + """ + checks to see if the path passed exists or is using a default + + :return: + """ + ret_val: list = [] + + if not workflow_type: + ret_val.append(['No workflow type found']) + + if not run_status: + ret_val.append('No run status') + + if len(package_dir) != 0 and not os.path.exists(package_dir): + ret_val.append('Invalid package directory') + + if not tests: + ret_val.append('No tests') + + if not request_group: + ret_val.append('No request group') + else: + # does the request group name already exist? + db_ret_val = db_info.get_test_request_name_exists(request_group) + + # check the results + if db_ret_val < 0: + ret_val.append('DB error getting test request name.') + elif db_ret_val: + ret_val.append(f"Test request name '{request_group}' already exists.") + + # return to the caller + return ', '.join(ret_val) + class WorkflowTypeName(str, Enum): """ diff --git a/src/server.py b/src/server.py index 0274f0c..e2ec8d7 100644 --- a/src/server.py +++ b/src/server.py @@ -517,8 +517,11 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName, db_ret_val: int = 0 try: + # get the validation results + validation_msg: str = GenUtils.validate_settings_input(workflow_type, run_status, package_dir, tests, request_group, db_info) + # made sure all the params are valid - if workflow_type and run_status and os_image and tests: # and db_image and test_image and tests + if len(validation_msg) == 0: # convert the string to a dict test_request = json.loads(tests) @@ -579,6 +582,7 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName, # else there were no valid tests requested else: ret_val = {'Error': 'No valid tests found.'} + # else there were no tests requested else: ret_val = {'Error': 'No tests requested.'} @@ -589,7 +593,7 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName, else: ret_val = {'Success': 'Request successfully submitted.'} else: - ret_val = {'Error': 'Invalid or missing input parameters.'} + ret_val = {'Error': validation_msg} except Exception: # return a failure message