diff --git a/haf/common/database.py b/haf/common/database.py index 17fb4cf..b2d911f 100644 --- a/haf/common/database.py +++ b/haf/common/database.py @@ -143,11 +143,11 @@ def connect_execute(self, sqlconfig: SQLConfig, sqlscript: list, **kwargs)-> tup if commit: self.connect_msql.commit() logger.debug(data, __name__) + self.close() return data except Exception as e: logger.error(str(e), __name__) - if self.connect_msql.open: - self.connect_msql.close() + self.close() return [] def close(self): @@ -156,7 +156,8 @@ def close(self): if self.connect_msql is not None: self.connect_msql.close() except Exception as e: - logger.error(e, __name__) + # logger.error(e, __name__) + pass class SqlServerTool(object): diff --git a/haf/common/httprequest.py b/haf/common/httprequest.py index ab6c596..d01fb4f 100644 --- a/haf/common/httprequest.py +++ b/haf/common/httprequest.py @@ -82,7 +82,7 @@ def get(url, data=None, headers=None, **kwargs): else: data = None - logger.info(f'{key} GET [url] {url}', __name__) + logger.debug(f'{key} GET [url] {url}', __name__) # using requests to Request the url with headers and method get request = ur.Request(url=url, data=data, headers=headers) @@ -94,16 +94,16 @@ def get(url, data=None, headers=None, **kwargs): if response is None: return {"result": "None"} else: - logger.info(f"{key} {str(response)}", __name__) + logger.debug(f"{key} {str(response)}", __name__) return response except ur.URLError as e: - logger.info(f"{key}{str(e)}", __name__) - logger.info(f"{key}{traceback.format_exc()}", __name__) + logger.error(f"{key}{str(e)}", __name__) + logger.error(f"{key}{traceback.format_exc()}", __name__) return e except Exception as ee: - logger.info(f"{key}{str(ee)}") - logger.info(f"{key}{traceback.format_exc()}", __name__) + logger.error(f"{key}{str(ee)}") + logger.error(f"{key}{traceback.format_exc()}", __name__) return ee @staticmethod @@ -130,7 +130,7 @@ def post(url, data=None, headers=None, **kwargs): if response is None: return {"result": "None"} else: - logger.info(f"{key} POST {str(response)}", __name__) + logger.debug(f"{key} POST {str(response)}", __name__) return response except ur.URLError as e: diff --git a/haf/config.py b/haf/config.py index f944ac8..d5317da 100644 --- a/haf/config.py +++ b/haf/config.py @@ -144,7 +144,7 @@ # version define MAIN_VERSION = 2 SUB_VERSION = 9 -FIX_VERSION = 3 +FIX_VERSION = 5 VERSION_TYPE = "haf" PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}" diff --git a/haf/ext/resource/report/base.html b/haf/ext/resource/report/base.html index b9b2f68..0ecb625 100644 --- a/haf/ext/resource/report/base.html +++ b/haf/ext/resource/report/base.html @@ -4,11 +4,26 @@ {% block head %} - + + + + + + - - {% endblock %} - - - {% endblock %} - - - {% endblock %} - - - -
- - - - - - - - - - - - - - - - - {% for suite_summary in results.summary.keys() %} - - - - - - - - - - - - - {% endfor %} - -
Suite NameBase UrlBegin TimeEnd TimeDuration TimePassFailErrorSkipAll
{{suite_summary}}{{results.summary.get(suite_summary).base_url}}{{results.summary.get(suite_summary).begin_time}}{{results.summary.get(suite_summary).end_time}}{{results.summary.get(suite_summary).duration}}{{results.summary.get(suite_summary).passed}}{{results.summary.get(suite_summary).failed}}{{results.summary.get(suite_summary).error}}{{results.summary.get(suite_summary).skip}}{{results.summary.get(suite_summary).all}}
-
- -
- {% block suites %} - {% for suite in results.details.keys() %} -
-
- +
+ {% block suites %} + {% for suite in results.details.keys() %} +
+
+
+
+ {% endfor %} + {% endblock %}
- {% endfor %} - {% endblock %}
-
\ No newline at end of file diff --git a/haf/loader.py b/haf/loader.py index 31b8cad..4379ed7 100644 --- a/haf/loader.py +++ b/haf/loader.py @@ -89,6 +89,7 @@ def run(self): if complete_case_count==self.true_case_count: if self.args.nout: cb.finish() + logger.debug(f"{self.key} all cases run over [{complete_case_count}/{self.true_case_count}]",__name__) self.end_handler() return time.sleep(0.01) @@ -211,7 +212,7 @@ def put_case(self, key: str, lock, case): :param case: :return: ''' - logger.info(f"{self.key} -- put case {case.bench_name} - {case.ids.id}.{case.ids.subid}.{case.ids.name}", __name__) + logger.debug(f"{self.key} -- put case {case.bench_name} - {case.ids.id}.{case.ids.subid}.{case.ids.name}", __name__) self.case_queue.put(case) def end_handler(self, error=None): diff --git a/haf/main.py b/haf/main.py index 20305aa..d57703d 100644 --- a/haf/main.py +++ b/haf/main.py @@ -3,6 +3,8 @@ import os import sys +from haf.utils import Utils + from haf.pluginmanager import PluginManager, plugin_manager from haf.program import Program from haf.helper import Helper @@ -166,23 +168,9 @@ def main_args(): # here : case <- dir/file if args.case: - cases = [] - for case in args.case: - cases.append(case) + case_path = args.case args.case = [] - for path in cases: - if not path.endswith(".py") and not path.endswith(".yml") and not path.endswith(".json") and not path.endswith(".xlsx"): - if os.path.exists(path) and os.path.isdir(path): - file_list = os.listdir(path) - for f in file_list: - if f.startswith("test_") and (f.endswith(".py") or f.endswith(".yml") or f.endswith(".json") or f.endswith(".xlsx")): - args.case.append(os.path.join(path, f)) - else: - print(f"found wrong case path ... {path}") - sys.exit(-2) - else: - args.case.append(path) - + args.case = Utils.load_case_from_dir(case_path) # here filter not in config if isinstance(args.filter_case, str): args.filter_case = args.filter_case.split(',') diff --git a/haf/program.py b/haf/program.py index cf1e801..4ba2bf3 100644 --- a/haf/program.py +++ b/haf/program.py @@ -199,7 +199,7 @@ def only_bus(self, args): self.wait_end_signal(args) sys.exit(0) else: - logger.info("not only bus mode") + logger.debug("not only bus mode") def only_loader(self, args): if args.only_loader: diff --git a/haf/recorder.py b/haf/recorder.py index 35a1b82..e262125 100644 --- a/haf/recorder.py +++ b/haf/recorder.py @@ -75,7 +75,7 @@ def run(self): # get result from runner to recorder if isinstance(result, (HttpApiResult, AppResult, WebResult)): if isinstance(result.case, (HttpApiCase, BaseCase, PyCase, WebCase, AppCase)): - logger.info(f"{self.recorder_key} {result.case.bench_name}.{result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name} is {RESULT_GROUP.get(str(result.result), None)}", __name__) + logger.debug(f"{self.recorder_key} {result.case.bench_name}.{result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name} is {RESULT_GROUP.get(str(result.result), None)}", __name__) else: logger.info(f"{self.recorder_key} recorder ! wrong result!", __name__) logger.info(f"{self.recorder_key} recorder {result.run_error}", __name__) @@ -264,6 +264,7 @@ def publish_to_mysql(self): ''' publish results to mysql database ''' - logger.info("publish result to sql", __name__) - plugin_manager.publish_to_sql(self.args, self.results) + if hasattr(self.args, "sql_publish") and self.args.sql_publish: + logger.info("publish result to sql", __name__) + plugin_manager.publish_to_sql(self.args, self.results) diff --git a/haf/runner.py b/haf/runner.py index 3c61111..24e7a6d 100644 --- a/haf/runner.py +++ b/haf/runner.py @@ -84,7 +84,7 @@ def put_result(self, key: str, lock: m_lock=None, result: HttpApiResult=HttpApi :param result: :return: ''' - logger.info(f"{self.key} : runner {self.pid} put result {result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name}", __name__) + logger.debug(f"{self.key} : runner {self.pid} put result {result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name}", __name__) self.result_handler_queue.put(result) def put_web_message(self, key: str, lock: m_lock=None): @@ -517,6 +517,7 @@ async def run(self, case:PyCase): result.on_case_end() return result except Exception as e: + case.response = getattr(suite, "response", Response()) traceback.print_exc() logger.error(f"{self.key} : {traceback.format_exc()}", __name__) result.result = RESULT_ERROR diff --git a/haf/utils.py b/haf/utils.py index 1733253..fcaffc7 100644 --- a/haf/utils.py +++ b/haf/utils.py @@ -362,7 +362,6 @@ def http_request(request:Request, **kwargs) : elif method == CASE_HTTP_API_METHOD_POST: result = session.post(url, data=data, headers=header) - logger.info("{} {}".format(key, result), __name__) if isinstance(result, rResponse): response.header = result.headers try: @@ -383,6 +382,7 @@ def http_request(request:Request, **kwargs) : method = request.method url = request.url + logger.info(f"{key} {METHOD_GROUP.get(str(method))} {url} with data: {data}, header is: {header}", __name__) response = Response() result = None if method == CASE_HTTP_API_METHOD_GET: @@ -392,7 +392,6 @@ def http_request(request:Request, **kwargs) : if method == CASE_HTTP_API_METHOD_PUT: result = HttpController.put(url, data, header) - logger.info("{} {}".format(key, result), __name__) if isinstance(result, HTTPResponse): response.header = result.headers try: @@ -479,6 +478,27 @@ def get_random_name(): def get_platform(): return platform.system() + @staticmethod + def load_case_from_dir(case_path): + cases = [] + for path in case_path: + if not path.endswith(".py") and not path.endswith(".yml") and \ + not path.endswith(".json") and not path.endswith(".xlsx"): + if os.path.exists(path) and os.path.isdir(path): + file_list = os.listdir(path) + for f in file_list: + if f.startswith("test_") and (f.endswith(".py") or f.endswith(".yml") or f.endswith(".json") or f.endswith(".xlsx")): + cases.append(os.path.join(path, f)) + elif os.path.exists(os.path.join(path, f)) and os.path.isdir(os.path.join(path, f)): + for case in Utils.load_case_from_dir([os.path.join(path, f)]): + cases.append(case) + else: + print(f"found wrong case path ==> [{path}]") + sys.exit(-2) + else: + cases.append(path) + return cases + class LoadFromConfig(object):