from os.path import isdir
from collections import OrderedDict
-from utils import execute_command
+from utils import get_last_completed_build_number
from errors import PresentationError
# Implemented alerts:
self._ALERTS = ("failed-tests", )
+ self._spec = spec
+
try:
- self._spec = spec.alerting
+ self._spec_alert = spec.alerting
except KeyError as err:
raise AlertingError("Alerting is not configured, skipped.",
repr(err),
self._path_failed_tests = spec.environment["paths"]["DIR[STATIC,VPP]"]
# Verify and validate input specification:
- self.configs = self._spec.get("configurations", None)
+ self.configs = self._spec_alert.get("configurations", None)
if not self.configs:
raise AlertingError("No alert configuration is specified.")
for config_type, config_data in self.configs.iteritems():
raise AlertingError("Alert of type '{0}' is not implemented.".
format(config_type))
- self.alerts = self._spec.get("alerts", None)
+ self.alerts = self._spec_alert.get("alerts", None)
if not self.alerts:
raise AlertingError("No alert is specified.")
for alert, alert_data in self.alerts.iteritems():
"""
for alert, alert_data in self.alerts.iteritems():
- if alert_data["way"] == "email":
- text, html = self._create_alert_message(alert_data)
- conf = self.configs["email"]
- self._send_email(server=conf["server"],
- addr_from=conf["address-from"],
- addr_to=conf["address-to"],
- subject=alert_data["title"],
- text=text,
- html=html)
- elif alert_data["way"] == "jenkins":
+ if alert_data["way"] == "jenkins":
self._generate_email_body(alert_data)
- # TODO: Remove when not needed
- self._generate_files_for_jenkins(alert_data)
else:
raise AlertingError("Alert with way '{0}' is not implemented.".
format(alert_data["way"]))
:type alert: dict
:type test_set: str
:type sort: bool
- :returns: CSIT build number, VPP version, Number of failed tests,
- Compressed failed tests.
- :rtype: tuple(str, str, int, OrderedDict)
+ :returns: CSIT build number, VPP version, Number of passed tests,
+ Number of failed tests, Compressed failed tests.
+ :rtype: tuple(str, str, int, int, OrderedDict)
"""
directory = self.configs[alert["way"]]["output-dir"]
failed_tests = OrderedDict()
+ file_path = "{0}/{1}.txt".format(directory, test_set)
version = ""
try:
- with open("{0}/{1}.txt".format(directory, test_set), 'r') as f_txt:
+ with open(file_path, 'r') as f_txt:
for idx, line in enumerate(f_txt):
if idx == 0:
build = line[:-1]
if idx == 1:
version = line[:-1]
continue
+ if idx == 2:
+ passed = line[:-1]
+ continue
+ if idx == 3:
+ failed = line[:-1]
+ continue
try:
test = line[:-1].split('-')
nic = test[0]
failed_tests[name]["framesizes"].append(framesize)
if cores not in failed_tests[name]["cores"]:
failed_tests[name]["cores"].append(cores)
- except IOError as err:
- logging.error(repr(err))
+ except IOError:
+ logging.error("No such file or directory: {file}".
+ format(file=file_path))
return None, None, None, None
if sort:
sorted_failed_tests = OrderedDict()
keys.sort()
for key in keys:
sorted_failed_tests[key] = failed_tests[key]
- return build, version, idx-1, sorted_failed_tests
+ return build, version, passed, failed, sorted_failed_tests
else:
- return build, version, idx-1, failed_tests
+ return build, version, passed, failed, failed_tests
def _generate_email_body(self, alert):
"""Create the file which is used in the generated alert.
text = ""
for idx, test_set in enumerate(alert.get("include", [])):
- build, version, nr, failed_tests = \
+ 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["urls"]["URL[JENKINS,CSIT]"],
+ alert["urls"][idx].split('/')[-1])
+ if ret_code != 0:
+ build_nr = ''
+ text += "\n\nNo input data available for '{set}'. See CSIT " \
+ "build {link}/{build} for more information.\n".\
+ format(set='-'.join(test_set.split('-')[-2:]),
+ link=alert["urls"][idx],
+ build=build_nr)
continue
text += ("\n\n{topo}-{arch}, "
- "{nr} tests failed, "
+ "{failed} tests failed, "
+ "{passed} tests passed, "
"CSIT build: {link}/{build}, "
"VPP version: {version}\n\n".
format(topo=test_set.split('-')[-2],
arch=test_set.split('-')[-1],
- nr=nr,
+ failed=failed,
+ passed=passed,
link=alert["urls"][idx],
build=build,
version=version))
+ regression_hdr = ("\n\n{topo}-{arch}, "
+ "CSIT build: {link}/{build}, "
+ "VPP version: {version}\n\n"
+ .format(topo=test_set.split('-')[-2],
+ arch=test_set.split('-')[-1],
+ link=alert["urls"][idx],
+ build=build,
+ version=version
+ ))
max_len_name = 0
max_len_nics = 0
max_len_framesizes = 0
cores=params["cores"] +
" " * (max_len_cores - len(params["cores"])))
+ # Add list of regressions:
+ file_name = "{0}/cpta-regressions-{1}.txt".\
+ format(config["output-dir"], alert["urls"][idx].split('/')[-1])
+ try:
+ with open(file_name, 'r') as txt_file:
+ file_content = txt_file.read()
+ reg_file_name = "{dir}/trending-regressions.txt". \
+ format(dir=config["output-dir"])
+ with open(reg_file_name, 'a+') as reg_file:
+ reg_file.write(regression_hdr)
+ if file_content:
+ reg_file.write(file_content)
+ else:
+ reg_file.write("No regressions")
+ except IOError as err:
+ logging.warning(repr(err))
+
+ # Add list of progressions:
+ file_name = "{0}/cpta-progressions-{1}.txt".\
+ format(config["output-dir"], alert["urls"][idx].split('/')[-1])
+ try:
+ with open(file_name, 'r') as txt_file:
+ file_content = txt_file.read()
+ pro_file_name = "{dir}/trending-progressions.txt". \
+ format(dir=config["output-dir"])
+ with open(pro_file_name, 'a+') as pro_file:
+ pro_file.write(regression_hdr)
+ if file_content:
+ pro_file.write(file_content)
+ else:
+ pro_file.write("No progressions")
+ except IOError as err:
+ logging.warning(repr(err))
+
text += "\nFor detailed information visit: {url}\n".\
format(url=alert["url-details"])
file_name = "{0}/{1}".format(config["output-dir"],
- config["output-file"])
+ config["output-file"])
logging.info("Writing the file '{0}.txt' ...".format(file_name))
try:
except IOError:
logging.error("Not possible to write the file '{0}.txt'.".
format(file_name))
-
- def _generate_files_for_jenkins(self, alert):
- """Create the file which is used in the generated alert.
-
- # TODO: Remove when not needed.
-
- :param alert: Files are created for this alert.
- :type alert: dict
- """
-
- config = self.configs[alert["way"]]
-
- zip_file = config.get("zip-output", None)
- if zip_file:
- logging.info("Writing the file '{0}/{1}' ...".
- format(config["output-dir"], zip_file))
- execute_command("tar czvf {dir}/{zip} --directory={dir} "
- "{input}.txt".
- format(dir=config["output-dir"],
- zip=zip_file,
- input=config["output-file"]))