diff options
author | chenliangyjy <chenliangyjy@chinamobile.com> | 2020-03-19 10:10:00 +0800 |
---|---|---|
committer | chenliangyjy <chenliangyjy@chinamobile.com> | 2020-03-19 10:45:25 +0800 |
commit | 12c9651ae71ab27287d1fe27e625087e6008f9a0 (patch) | |
tree | aec1504ad1ed789d94f46ede26aa01f22c4ed87a | |
parent | 004298391e45dee9421748bc1312cda5d2af2d43 (diff) |
fix flake8 checking issue of hdv
Signed-off-by: chenliangyjy <chenliangyjy@chinamobile.com>
Change-Id: Ie779c186635e57fe5d900df7326e4a704ebcad42
-rw-r--r-- | tools/hdv/redfish/conf/report_sample.yaml (renamed from tools/hdv/redfish/conf/report.yaml) | 1 | ||||
-rw-r--r-- | tools/hdv/redfish/excel_2_yaml.py | 3 | ||||
-rw-r--r-- | tools/hdv/redfish/hdv.py | 27 | ||||
-rw-r--r-- | tools/hdv/redfish/hdv_redfish.py | 20 | ||||
-rw-r--r-- | tools/hdv/redfish/http_handler.py | 2 | ||||
-rw-r--r-- | tools/hdv/redfish/yaml_utils.py | 2 | ||||
-rw-r--r-- | tox.ini | 2 |
7 files changed, 30 insertions, 27 deletions
diff --git a/tools/hdv/redfish/conf/report.yaml b/tools/hdv/redfish/conf/report_sample.yaml index fc15f65..d396360 100644 --- a/tools/hdv/redfish/conf/report.yaml +++ b/tools/hdv/redfish/conf/report_sample.yaml @@ -1,3 +1,4 @@ +--- - case_name: set asset code case_sn: 1 details_result: '{''count'': ''N/A for this case'', ''info'': [{''return_code'': diff --git a/tools/hdv/redfish/excel_2_yaml.py b/tools/hdv/redfish/excel_2_yaml.py index 3bda3d5..948ead3 100644 --- a/tools/hdv/redfish/excel_2_yaml.py +++ b/tools/hdv/redfish/excel_2_yaml.py @@ -13,7 +13,7 @@ convert excel config to yaml format config: depends.yaml and cases.yaml. import os import yaml from openpyxl.reader.excel import load_workbook -#pylint: disable=E0611 +# pylint: disable=E0611 from log_utils import LOGGER @@ -45,6 +45,7 @@ def load_sheet(excel_file, sheet_index, start_col, end_col): LOGGER.info(rows_list) return rows_list + def create_yaml(id_dict, yaml_file): ''' create yaml diff --git a/tools/hdv/redfish/hdv.py b/tools/hdv/redfish/hdv.py index 80db3c9..e06286e 100644 --- a/tools/hdv/redfish/hdv.py +++ b/tools/hdv/redfish/hdv.py @@ -11,10 +11,10 @@ hdv tools all config files are put under conf/ config.yaml is the global configuration additional config for supporting two modes - - excel: tools will parse the depend_id sheet and cases sheet and \ + - excel: tools will parse the depend_id sheet and cases sheet and execute test case and write report back to excel - - yaml: tools will parse depends.yaml and cases.yaml and execute test case and\ - write a report.yaml + - yaml: tools will parse depends.yaml and cases.yaml and execute test case + and write a report.yaml theory: either test case can be finished by one restful request, or an additional request needed to get dependency parent resource. @@ -23,24 +23,25 @@ hdv tools import argparse from hdv_redfish import run as run_case + def parse_args(): ''' parse arguments ''' parser = argparse.ArgumentParser(description="hdv tool by redfish, \ check readme under ./docs") - parser.add_argument('--version', action='version', \ + parser.add_argument('--version', action='version', version='%(prog)s 0.1', help="show tool version") - parser.add_argument('--config', type=str, default="./conf/config.yaml", \ + parser.add_argument('--config', type=str, default="./conf/config.yaml", help="given global config.yaml file") - parser.add_argument('--file_type', type=str, default="excel", \ + parser.add_argument('--file_type', type=str, default="excel", help="config file type, [yaml|excel],default is excel") - parser.add_argument('--case_yaml', type=str, default="./conf/cases.yaml", \ + parser.add_argument('--case_yaml', type=str, default="./conf/cases.yaml", help="case yaml file, uesd if file_type = yaml") - parser.add_argument('--depends_yaml', type=str, \ - default="./conf/depends.yaml",\ - help="depends yaml file,uesd if file_type = yaml") - parser.add_argument('--case_excel', type=str, default="./conf/cases.xlsx", \ + parser.add_argument('--depends_yaml', type=str, + default="./conf/depends.yaml", + help="depends yaml file,uesd if file_type = yaml") + parser.add_argument('--case_excel', type=str, default="./conf/cases.xlsx", help="excel case file used if file_type = excel") args = parser.parse_args() return args @@ -51,8 +52,8 @@ def main(): main function ''' args = parse_args() - run_case(args.config, args.case_excel, args.depends_yaml, args.case_yaml,\ - args.file_type) + run_case(args.config, args.case_excel, args.depends_yaml, args.case_yaml, + args.file_type) if __name__ == "__main__": diff --git a/tools/hdv/redfish/hdv_redfish.py b/tools/hdv/redfish/hdv_redfish.py index 6d325f6..5fc44ca 100644 --- a/tools/hdv/redfish/hdv_redfish.py +++ b/tools/hdv/redfish/hdv_redfish.py @@ -29,7 +29,6 @@ ACCOUNT_INFO = {} WAIT_INTERVAL = 5 - def parse_config(config_yaml): """ parse setting from config.yaml @@ -428,8 +427,8 @@ def check_component_cnt(expect_return_value, res_list, result): if expect_return_value['count'] == len(res_list): result.update({"count": "Success"}) else: - result.update({"count": \ - "Failure, the actual num is "+ str(len(res_list))}) + result.update({"count": + "Failure, the actual num is " + str(len(res_list))}) else: result.update({"count": "N/A for this case"}) return result @@ -471,7 +470,7 @@ def parse_test_result(expect_return_value, expect_return_code, flag += 1 continue - #parse the actual result according to the expected value hierachy. + # parse the actual result according to the expected value hierachy. ex_value = copy.deepcopy(expect_return_value) exp_act_pairs = {} for key, value in ex_value.items(): @@ -482,7 +481,7 @@ def parse_test_result(expect_return_value, expect_return_code, else: LOGGER.error("%s, %s", ERROR_CODE['E500001'], key) exp_act_pairs[key] = \ - (value, "Can't find the key {} in return value".format(key)) + (value, "Can't find key {} in return value".format(key)) LOGGER.debug("real_result:%s", exp_act_pairs) # comparing expected result with real result. @@ -525,7 +524,7 @@ def execute_final_url(config_file, depends_id, http_handler, def run_test_case_yaml(config_file, case_file, depends_id, http_handler): '''run test case from cases.yaml ''' - LOGGER.info("################# start perform test case ###################") + LOGGER.info("############### start perform test case #################") cases_result = [] cases = read_yaml(case_file) for case in cases: @@ -556,7 +555,7 @@ def run_test_case_yaml(config_file, case_file, depends_id, http_handler): write_result_2_yaml(cases_result) - LOGGER.info("################# end perform test case #####################") + LOGGER.info("############### end perform test case ###################") def read_yaml(file): @@ -573,7 +572,8 @@ def write_result_2_yaml(result): write test result to new report.yaml ''' LOGGER.info("writing to yaml file") - yaml.dump(result, open("./conf/report.yaml", "w")) + yaml.safe_dump(result, open("./conf/report.yaml", "w"), + explicit_start=True) def run_test_case_excel(config_file, case_file, depends_id, http_handler): @@ -581,7 +581,7 @@ def run_test_case_excel(config_file, case_file, depends_id, http_handler): perform the test case one by one, and write test final_result back to the excel. ''' - LOGGER.info("################# start perform test case ###################") + LOGGER.info("############### start perform test case #################") input_file = load_workbook(case_file) input_ws = input_file[input_file.sheetnames[0]] @@ -615,7 +615,7 @@ def run_test_case_excel(config_file, case_file, depends_id, http_handler): config_file, input_ws, row, flag, final_result) row += 1 input_file.save(case_file) - LOGGER.info("################# end perform test case #####################") + LOGGER.info("############### end perform test case ###################") def run(conf_file, case_excel_file=None, depend_yaml_file=None, diff --git a/tools/hdv/redfish/http_handler.py b/tools/hdv/redfish/http_handler.py index 259bcaf..c1b0a13 100644 --- a/tools/hdv/redfish/http_handler.py +++ b/tools/hdv/redfish/http_handler.py @@ -23,7 +23,7 @@ ssl._create_default_https_context = ssl._create_unverified_context HEADERS = { 'Connection': 'keep-alive', - 'User-Agent': \ + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 \ (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36', } diff --git a/tools/hdv/redfish/yaml_utils.py b/tools/hdv/redfish/yaml_utils.py index 21e4fb6..438c150 100644 --- a/tools/hdv/redfish/yaml_utils.py +++ b/tools/hdv/redfish/yaml_utils.py @@ -6,6 +6,7 @@ import yaml # pylint: disable=E0611 from log_utils import LOGGER + def read_yaml(file): '''read a yaml file ''' @@ -18,7 +19,6 @@ def read_yaml(file): def write_yaml(file, dict_data): '''write a yaml file ''' - #yaml.dump(dict_data, open(file, "w"), width = 80) yaml.safe_dump(dict_data, open(file, "w"), explicit_start=True) @@ -17,7 +17,7 @@ files = INFO.yaml tools commands = - yamllint -s {[testenv:yamllint]files} + yamllint -s {[testenv:yamllint]files} -c {toxinidir}/yamllintrc [testenv:bashate] basepython = python3 |