def run(self): """Run collect logs process as standalone operation Run collect log operations as standalon process or run as single stage in pipeline for defined cluster sets """ results = {} self.define_test_id() if not self.test_id: LOGGER.warning("No test_id provided or found") return results self.get_running_cluster_sets() local_dir_with_logs = get_testrun_dir(self.sct_result_dir, self.test_id) LOGGER.info("Found sct result directory with logs: %s", local_dir_with_logs) self.create_base_storage_dir(local_dir_with_logs) LOGGER.info("Created directory to storing collected logs: %s", self.storage_dir) for cluster_log_collector, nodes in self.cluster_log_collectors.items( ): log_collector = cluster_log_collector(nodes, test_id=self.test_id, storage_dir=self.storage_dir, params=self.params) LOGGER.info("Start collect logs for cluster %s", log_collector.cluster_log_type) result = log_collector.collect_logs( local_search_path=local_dir_with_logs) results[log_collector.cluster_log_type] = result LOGGER.info("collected data for %s\n%s\n", log_collector.cluster_log_type, result) return results
def send_email(test_id=None, email_recipients=None, logdir=None): from sdcm.send_email import (GeminiEmailReporter, LongevityEmailReporter, UpgradeEmailReporter, get_running_instances_for_email_report, read_email_data_from_file) 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') testrun_dir = get_testrun_dir(test_id=test_id, base_dir=logdir) email_results_file = os.path.join(testrun_dir, "email_data.json") test_results = read_email_data_from_file(email_results_file) if not test_results: LOGGER.warning("File with email results data not found") return reporter = test_results.get('reporter') email_recipients = email_recipients.split(',') if not reporter: LOGGER.warning("No reporter found") else: test_results['nodes'] = get_running_instances_for_email_report(test_results['test_id']) if "Gemini" in reporter: reporter = GeminiEmailReporter(email_recipients, logdir=testrun_dir) reporter.send_report(test_results) elif "Longevity" in reporter: reporter = LongevityEmailReporter(email_recipients, logdir=testrun_dir) reporter.send_report(test_results) elif "Upgrade" in reporter: reporter = UpgradeEmailReporter(email_recipients, logdir=testrun_dir) reporter.send_report(test_results) else: LOGGER.warning("No reporter found")
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 send_email(test_id=None, email_recipients=None, logdir=None): 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') testrun_dir = get_testrun_dir(test_id=test_id, base_dir=logdir) email_results_file = os.path.join(testrun_dir, "email_data.json") test_results = read_email_data_from_file(email_results_file) if not test_results: LOGGER.warning("File with email results data not found") return email_recipients = email_recipients.split(',') reporter = build_reporter(test_results.get("reporter", ""), email_recipients, testrun_dir) if reporter: test_results['nodes'] = get_running_instances_for_email_report(test_results['test_id']) reporter.send_report(test_results) else: LOGGER.warning("No reporter found")
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}", })