diff --git a/tmt/steps/report/reportportal.py b/tmt/steps/report/reportportal.py index 41e67280fa..70ef54d95d 100644 --- a/tmt/steps/report/reportportal.py +++ b/tmt/steps/report/reportportal.py @@ -47,6 +47,12 @@ def _filter_invalid_chars(data: str) -> str: '', data) +def _filter_log_per_size(data: str, limit: int) -> str: + size = len(log) + if size > limit: + return (f"Log file was not uploaded to ReportPortal because its size {size} bytes" + f"exceeds {self.data.log_size_limit} bytes.") + return log @dataclasses.dataclass class ReportReportPortalData(tmt.steps.report.ReportStepData): @@ -142,6 +148,14 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData): (e.g. 'Idle'). 'To Investigate' is used by default. """) + log_size_limit: Optional[str] = field( + option="--log-size-limit", + metavar="LOG_SIZE_LIMIT", + default=_str_env_to_default('log_size_limit', '1048576'), + help=""" + Size limit in bytes for log upload to ReportPortal. The default is 1048576 bytes (1 MB). + """) + exclude_variables: str = field( option="--exclude-variables", metavar="PATTERN", @@ -590,15 +604,20 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None: response = self.rp_api_post( session=session, path="log/entry", - json={"message": _filter_invalid_chars(log), + json={"message": _filter_invalid_chars( + _filter_log_per_size(log, + int(self.data.log_size_limit))), "itemUuid": item_uuid, "launchUuid": launch_uuid, "level": level, "time": result.end_time}) # Write out failures + failures = result.failures(log) if index == 0 and status == "FAILED": - message = _filter_invalid_chars(result.failures(log)) + message = _filter_invalid_chars( + _filter_log_per_size(result.failures(log), + int(self.data.log_size_limit))) response = self.rp_api_post( session=session, path="log/entry",