def run_test(self, duthost, storm_hndle, expect_regex, syslog_marker, action): """ Storm generation/restoration on all ports and verification Args: duthost (AnsibleHost): DUT instance storm_hndle (PFCMultiStorm): class PFCMultiStorm intance expect_regex (list): list of expect regexs to be matched in the syslog syslog_marker (string): marker prefix written to the syslog action (string): storm/restore action """ loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix=syslog_marker) ignore_file = os.path.join(TEMPLATES_DIR, "ignore_pfc_wd_messages") reg_exp = loganalyzer.parse_regexp_file(src=ignore_file) loganalyzer.ignore_regex.extend(reg_exp) loganalyzer.expect_regex = [] loganalyzer.expect_regex.extend(expect_regex) loganalyzer.match_regex = [] with loganalyzer: if action == "storm": storm_hndle.start_pfc_storm() elif action == "restore": storm_hndle.stop_pfc_storm() time.sleep(5)
def execute_test(self, duthost, syslog_marker, ignore_regex=None, expect_regex=None, expect_errors=False): """ Helper function that loads each template on the DUT and verifies the expected behavior Args: duthost (AnsibleHost): instance syslog_marker (string): marker prefix name to be inserted in the syslog ignore_regex (string): file containing regexs to be ignored by loganalyzer expect_regex (string): regex pattern that is expected to be present in the syslog expect_erros (bool): if the test expects an error msg in the syslog or not. Default: False Returns: None """ loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix=syslog_marker) if ignore_regex: ignore_file = os.path.join(TEMPLATES_DIR, ignore_regex) reg_exp = loganalyzer.parse_regexp_file(src=ignore_file) loganalyzer.ignore_regex.extend(reg_exp) if expect_regex: loganalyzer.expect_regex = [] loganalyzer.expect_regex.extend(expect_regex) loganalyzer.match_regex = [] with loganalyzer(fail=not expect_errors): cmd = "sonic-cfggen -j {}/{}.json --write-to-db".format( DUT_RUN_DIR, syslog_marker) out = duthost.command(cmd) pytest_assert( out["rc"] == 0, "Failed to execute cmd {}: Error: {}".format( cmd, out["stderr"]))