|
76 | 76 | cache = FactsCache() |
77 | 77 |
|
78 | 78 | DUTHOSTS_FIXTURE_FAILED_RC = 15 |
| 79 | +DUT_CHEK_LIST = ['core_dump_check_pass', 'config_db_check_pass'] |
| 80 | +CACHE_LIST = ['core_dump_check_pass', 'config_db_check_pass', |
| 81 | + 'pre_sanity_recovered', 'post_sanity_recovered', |
| 82 | + 'pre_sanity_check_failed', 'post_sanity_check_failed'] |
79 | 83 |
|
80 | 84 | pytest_plugins = ('tests.common.plugins.ptfadapter', |
81 | 85 | 'tests.common.plugins.ansible_fixtures', |
@@ -914,12 +918,58 @@ def creds_all_duts(duthosts): |
914 | 918 | return creds_all_duts |
915 | 919 |
|
916 | 920 |
|
| 921 | +def log_custom_msg(item): |
| 922 | + # temp log output to track module name |
| 923 | + logger.debug("[log_custom_msg] item: {}".format(item)) |
| 924 | + customMsgDict = {} |
| 925 | + dutChekResults = {} |
| 926 | + for key in DUT_CHEK_LIST: |
| 927 | + if item.session.config.cache.get(key, None): |
| 928 | + dutChekResults[key] = item.session.config.cache.get(key, None) |
| 929 | + item.session.config.cache.set(key, None) |
| 930 | + if dutChekResults: |
| 931 | + customMsgDict['DutChekResult'] = dutChekResults |
| 932 | + # Check pre_sanity_checks results |
| 933 | + preSanityCheckResults = {} |
| 934 | + if item.session.config.cache.get("pre_sanity_check_failed", None): |
| 935 | + preSanityCheckResults['pre_sanity_check_failed'] = True |
| 936 | + item.session.config.cache.set("pre_sanity_check_failed", None) |
| 937 | + # pre_sanity_recovered should be None in healthy case, record either True/False |
| 938 | + if item.session.config.cache.get("pre_sanity_recovered", None) is not None: |
| 939 | + preSanityCheckResults['pre_sanity_recovered'] = item.session.config.cache.get("pre_sanity_recovered", None) |
| 940 | + item.session.config.cache.set("pre_sanity_recovered", None) |
| 941 | + if preSanityCheckResults: |
| 942 | + customMsgDict['PreSanityCheckResults'] = preSanityCheckResults |
| 943 | + # Check post_sanity_checks results |
| 944 | + postSanityCheckResults = {} |
| 945 | + if item.session.config.cache.get("post_sanity_check_failed", None): |
| 946 | + postSanityCheckResults['post_sanity_check_failed'] = True |
| 947 | + item.session.config.cache.set("post_sanity_check_failed", None) |
| 948 | + # post_sanity_recovered should be None in healthy case, record either True/False |
| 949 | + if item.session.config.cache.get("post_sanity_recovered", None) is not None: |
| 950 | + preSanityCheckResults['post_sanity_recovered'] = item.session.config.cache.get("post_sanity_recovered", None) |
| 951 | + item.session.config.cache.set("post_sanity_recovered", None) |
| 952 | + if postSanityCheckResults: |
| 953 | + customMsgDict['PostSanityCheckResults'] = postSanityCheckResults |
| 954 | + # if we have any custom message to log, append it to user_properties |
| 955 | + if customMsgDict: |
| 956 | + logger.debug("customMsgDict: {}".format(customMsgDict)) |
| 957 | + item.user_properties.append(('CustomMsg', json.dumps(customMsgDict))) |
| 958 | + |
| 959 | + |
| 960 | +# log_custog_msg has to be the very last function to be called in every test case. |
| 961 | +# use this hook to call log_custom_msg, so we guarantee its execution and its sequence is the last. |
917 | 962 | @pytest.hookimpl(tryfirst=True, hookwrapper=True) |
918 | 963 | def pytest_runtest_makereport(item, call): |
919 | 964 |
|
| 965 | + logger.debug("debugging - pytest_runtest_makereport call: {}, item_name: {}".format(call.when, item)) |
920 | 966 | if call.when == 'setup': |
921 | 967 | item.user_properties.append(('start', str(datetime.fromtimestamp(call.start)))) |
922 | 968 | elif call.when == 'teardown': |
| 969 | + for key in CACHE_LIST: # temporary log output to track cache status |
| 970 | + if item.session.config.cache.get(key, None): |
| 971 | + logger.debug("debugging - before log [{}] : {}".format(key, item.session.config.cache.get(key, None))) |
| 972 | + log_custom_msg(item) |
923 | 973 | item.user_properties.append(('end', str(datetime.fromtimestamp(call.stop)))) |
924 | 974 |
|
925 | 975 | # Filter out unnecessary logs captured on "stdout" and "stderr" |
@@ -2492,6 +2542,7 @@ def _remove_entry(table_name, key_name, config): |
2492 | 2542 | logger.info("Core dump and config check passed for {}".format(module_name)) |
2493 | 2543 |
|
2494 | 2544 | if check_result: |
| 2545 | + logger.debug("core_dump_and_config_check failed, check_result: {}".format(json.dumps(check_result))) |
2495 | 2546 | request.config.cache.set("core_dump_check_pass", core_dump_check_pass) |
2496 | 2547 | request.config.cache.set("config_db_check_pass", config_db_check_pass) |
2497 | 2548 |
|
|
0 commit comments