- config = self.configs[alert["way"]]
-
- if alert["type"] == "failed-tests":
- text, html = self._create_alert_message(alert)
- file_name = "{0}/{1}".format(config["output-dir"],
- config["output-file"])
- logging.info("Writing the file '{0}.txt' ...".format(file_name))
- try:
- with open("{0}.txt".format(file_name), 'w') as txt_file:
- txt_file.write(text)
- except IOError:
- logging.error("Not possible to write the file '{0}.txt'.".
- format(file_name))
- logging.info("Writing the file '{0}.html' ...".format(file_name))
- try:
- with open("{0}.html".format(file_name), 'w') as html_file:
- html_file.write(html)
- except IOError:
- logging.error("Not possible to write the file '{0}.html'.".
- format(file_name))
- else:
- raise AlertingError("Alert of type '{0}' is not implemented.".
- format(alert["type"]))
+ if alert[u"type"] != u"failed-tests":
+ raise AlertingError(
+ f"Alert of type {alert[u'type']} is not implemented."
+ )
+
+ text = u""
+ for idx, test_set in enumerate(alert.get(u"include", [])):
+ build, version, passed, failed, failed_tests = \
+ self._get_compressed_failed_tests(alert, test_set)
+ if build is None:
+ ret_code, build_nr, _ = get_last_completed_build_number(
+ self._spec.environment[u"urls"][u"URL[JENKINS,CSIT]"],
+ alert[u"urls"][idx].split(u'/')[-1])
+ if ret_code != 0:
+ build_nr = u''
+ text += (
+ f"\n\nNo input data available for "
+ f"{u'-'.join(test_set.split('-')[-2:])}. See CSIT build "
+ f"{alert[u'urls'][idx]}/{build_nr} for more information.\n"
+ )
+ continue
+ text += (
+ f"\n\n{test_set.split('-')[-2]}-{test_set.split('-')[-1]}, "
+ f"{failed} tests failed, "
+ f"{passed} tests passed, CSIT build: "
+ f"{alert[u'urls'][idx]}/{build}, VPP version: {version}\n\n"
+ )
+
+ class MaxLens():
+ """Class to store the max lengths of strings displayed in
+ failed tests list.
+ """
+ def __init__(self, tst_name, nics, framesizes, cores):
+ """Initialisation.
+
+ :param tst_name: Name of the test.
+ :param nics: NICs used in the test.
+ :param framesizes: Frame sizes used in the tests
+ :param cores: Cores used in th test.
+ """
+ self.name = tst_name
+ self.nics = nics
+ self.frmsizes = framesizes
+ self.cores = cores
+
+ max_len = MaxLens(0, 0, 0, 0)
+
+ for name, params in failed_tests.items():
+ failed_tests[name][u"nics"] = u",".join(sorted(params[u"nics"]))
+ failed_tests[name][u"framesizes"] = \
+ u",".join(sorted(params[u"framesizes"]))
+ failed_tests[name][u"cores"] = \
+ u",".join(sorted(params[u"cores"]))
+ if len(name) > max_len.name:
+ max_len.name = len(name)
+ if len(failed_tests[name][u"nics"]) > max_len.nics:
+ max_len.nics = len(failed_tests[name][u"nics"])
+ if len(failed_tests[name][u"framesizes"]) > max_len.frmsizes:
+ max_len.frmsizes = len(failed_tests[name][u"framesizes"])
+ if len(failed_tests[name][u"cores"]) > max_len.cores:
+ max_len.cores = len(failed_tests[name][u"cores"])
+
+ for name, params in failed_tests.items():
+ text += (
+ f"{name + u' ' * (max_len.name - len(name))} "
+ f"{params[u'nics']}"
+ f"{u' ' * (max_len.nics - len(params[u'nics']))} "
+ f"{params[u'framesizes']}"
+ f"{u' ' * (max_len.frmsizes-len(params[u'framesizes']))} "
+ f"{params[u'cores']}"
+ f"{u' ' * (max_len.cores - len(params[u'cores']))}\n"
+ )
+
+ gression_hdr = (
+ f"\n\n{test_set.split(u'-')[-2]}-{test_set.split(u'-')[-1]}, "
+ f"CSIT build: {alert[u'urls'][idx]}/{build}, "
+ f"VPP version: {version}\n\n"
+ )
+ # Add list of regressions:
+ self._list_gressions(alert, idx, gression_hdr, u"regressions")
+
+ # Add list of progressions:
+ self._list_gressions(alert, idx, gression_hdr, u"progressions")
+
+ text += f"\nFor detailed information visit: {alert[u'url-details']}\n"
+ file_name = f"{self.configs[alert[u'way']][u'output-dir']}/" \
+ f"{self.configs[alert[u'way']][u'output-file']}"
+ logging.info(f"Writing the file {file_name}.txt ...")
+
+ try:
+ with open(f"{file_name}.txt", u'w') as txt_file:
+ txt_file.write(text)
+ except IOError:
+ logging.error(f"Not possible to write the file {file_name}.txt.")