def send_email(test_id=None, test_status=None, start_time=None, email_recipients=None, logdir=None): add_file_logger() from sdcm.send_email import get_running_instances_for_email_report, read_email_data_from_file, build_reporter if not email_recipients: LOGGER.warning("No email recipients. Email will not be sent") return LOGGER.info('Email will be sent to next recipients: %s', email_recipients) if not logdir: logdir = os.path.expanduser('~/sct-results') test_results = None if start_time is None: start_time = format_timestamp(time.time()) else: start_time = format_timestamp(int(start_time)) testrun_dir = get_testrun_dir(test_id=test_id, base_dir=logdir) if testrun_dir: email_results_file = os.path.join(testrun_dir, "email_data.json") test_results = read_email_data_from_file(email_results_file) else: LOGGER.warning("Failed to find test directory for %s", test_id) if test_results: reporter = test_results.get("reporter", "") test_results['nodes'] = get_running_instances_for_email_report( test_results['test_id']) else: LOGGER.warning("Failed to read test results for %s", test_id) reporter = "TestAborted" if not test_status: test_status = 'FAILED' test_results = { "build_url": os.environ.get("BUILD_URL"), "subject": f"{test_status}: {os.environ.get('JOB_NAME')}: {start_time}", } email_recipients = email_recipients.split(',') reporter = build_reporter(reporter, email_recipients, testrun_dir) if not reporter: LOGGER.warning("No reporter found") sys.exit(1) try: reporter.send_report(test_results) except Exception: # pylint: disable=broad-except LOGGER.error("Failed to create email due to the following error:\n%s", traceback.format_exc()) build_reporter( "TestAborted", email_recipients, testrun_dir).send_report({ "build_url": os.environ.get("BUILD_URL"), "subject": f"FAILED: {os.environ.get('JOB_NAME')}: {start_time}", })
def get_email_data(self): scylla_version = self.db_cluster.nodes[0].scylla_version oracle_db_version = self.cs_db_cluster.nodes[ 0].scylla_version if self.cs_db_cluster else "" start_time = format_timestamp(self.start_time) critical = self.get_critical_events() return { "subject": 'Gemini - test results: {}'.format(start_time), "username": get_username(), "gemini_cmd": self.gemini_results['cmd'], "gemini_version": self.loaders.gemini_version, "scylla_version": scylla_version, "scylla_ami_id": self.params.get('ami_id_db_scylla'), "scylla_instance_type": self.params.get('instance_type_db'), "number_of_db_nodes": self.params.get('n_db_nodes'), "number_of_oracle_nodes": self.params.get('n_test_oracle_db_nodes', 1), "oracle_db_version": oracle_db_version, "oracle_ami_id": self.params.get('ami_id_db_oracle'), "oracle_instance_type": self.params.get('instance_type_db_oracle'), "results": self.gemini_results['results'], "status": self.gemini_results['status'], 'test_name': self.id(), 'test_id': self.test_id, 'start_time': start_time, 'end_time': format_timestamp(time.time()), 'build_url': os.environ.get('BUILD_URL', None), 'nemesis_name': self.params.get('nemesis_class_name'), 'nemesis_details': self.get_nemesises_stats(), 'test_status': ("FAILED", critical) if critical else ("No critical errors in critical.log", None), 'nodes': [] }
def get_email_data(self): self.log.info('Prepare data for email') grafana_dataset = self.monitors.get_grafana_screenshot_and_snapshot( self.start_time) if self.monitors else dict() start_time = format_timestamp(self.start_time) config_file_name = ";".join([ os.path.splitext(os.path.basename(f))[0] for f in self.params['config_files'] ]) job_name = os.environ.get('JOB_NAME') subject_name = job_name if job_name else config_file_name critical = self.get_critical_events() return { 'subject': 'Result {}: {}'.format(subject_name, start_time), 'username': get_username(), 'grafana_screenshots': grafana_dataset.get('screenshots', []), 'grafana_snapshots': grafana_dataset.get('snapshots', []), 'test_status': ("FAILED", critical) if critical else ("No critical errors in critical.log", None), 'test_name': self.id(), 'start_time': start_time, 'end_time': format_timestamp(time.time()), 'build_url': os.environ.get('BUILD_URL', None), 'scylla_version': self.db_cluster.nodes[0].scylla_version if self.db_cluster else 'N/A', 'scylla_ami_id': self.params.get('ami_id_db_scylla', '-'), "scylla_instance_type": self.params.get('instance_type_db'), "number_of_db_nodes": self.params.get('n_db_nodes'), 'nemesis_name': self.params.get('nemesis_class_name'), 'nemesis_details': self.get_nemesises_stats(), 'test_id': self.test_id, "nodes": [] }
def send_email(test_id=None, test_status=None, start_time=None, started_by=None, email_recipients=None, logdir=None): if started_by is None: started_by = get_username() add_file_logger() from sdcm.send_email import get_running_instances_for_email_report, read_email_data_from_file, build_reporter if not email_recipients: LOGGER.warning("No email recipients. Email will not be sent") return LOGGER.info('Email will be sent to next recipients: %s', email_recipients) if not logdir: logdir = os.path.expanduser('~/sct-results') test_results = None if start_time is None: start_time = format_timestamp(time.time()) else: start_time = format_timestamp(int(start_time)) testrun_dir = get_testrun_dir(test_id=test_id, base_dir=logdir) if testrun_dir: with open(os.path.join(testrun_dir, 'test_id'), 'r') as file: test_id = file.read().strip() email_results_file = os.path.join(testrun_dir, "email_data.json") test_results = read_email_data_from_file(email_results_file) else: LOGGER.warning("Failed to find test directory for %s", test_id) if test_results: reporter = test_results.get("reporter", "") test_results['nodes'] = get_running_instances_for_email_report(test_id) else: LOGGER.warning("Failed to read test results for %s", test_id) reporter = "TestAborted" if not test_status: test_status = 'ABORTED' test_results = { "build_url": os.environ.get("BUILD_URL"), "subject": f"{test_status}: {os.environ.get('JOB_NAME')}: {start_time}", "start_time": start_time, "end_time": format_timestamp(time.time()), "grafana_screenshots": "", "grafana_snapshots": "", "nodes": "", "test_id": "", "username": "" } if started_by: test_results["username"] = started_by if test_id: test_results.update({ "test_id": test_id, "nodes": get_running_instances_for_email_report(test_id) }) test_results['logs_links'] = list_logs_by_test_id(test_results.get('test_id', test_id)) email_recipients = email_recipients.split(',') reporter = build_reporter(reporter, email_recipients, testrun_dir) if not reporter: LOGGER.warning("No reporter found") sys.exit(1) try: reporter.send_report(test_results) except Exception: # pylint: disable=broad-except LOGGER.error("Failed to create email due to the following error:\n%s", traceback.format_exc()) build_reporter("TestAborted", email_recipients, testrun_dir).send_report({ "build_url": os.environ.get("BUILD_URL"), "subject": f"FAILED: {os.environ.get('JOB_NAME')}: {start_time}", })