Skip to content

Commit

Permalink
Merge pull request #169 from hautof/dev-3.0.0
Browse files Browse the repository at this point in the history
add more infos to report of api cases
  • Loading branch information
tsbxmw authored May 29, 2019
2 parents 107ab71 + c8f4a6f commit 0633275
Show file tree
Hide file tree
Showing 10 changed files with 899 additions and 748 deletions.
7 changes: 4 additions & 3 deletions haf/common/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions haf/common/httprequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
1,565 changes: 852 additions & 713 deletions haf/ext/resource/report/base.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion haf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 4 additions & 16 deletions haf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(',')
Expand Down
2 changes: 1 addition & 1 deletion haf/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions haf/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)

3 changes: 2 additions & 1 deletion haf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions haf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 0633275

Please sign in to comment.