diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 9be03b0982..37fc6f3487 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2968,7 +2968,14 @@ class SystemJobSerializer(UnifiedJobSerializer): return res def get_result_stdout(self, obj): - return obj.result_stdout + try: + return obj.result_stdout + except StdoutMaxBytesExceeded as e: + return _( + "Standard Output too large to display ({text_size} bytes), " + "only download supported for sizes over {supported_size} bytes").format( + text_size=e.total, supported_size=e.supported + ) class SystemJobCancelSerializer(SystemJobSerializer): diff --git a/awx/main/tests/functional/api/test_unified_jobs_stdout.py b/awx/main/tests/functional/api/test_unified_jobs_stdout.py index 99b5619a7f..6cec0ab4fe 100644 --- a/awx/main/tests/functional/api/test_unified_jobs_stdout.py +++ b/awx/main/tests/functional/api/test_unified_jobs_stdout.py @@ -158,6 +158,24 @@ def test_text_stdout_from_system_job_events(sqlite_copy_expert, get, admin): assert response.data['result_stdout'].splitlines() == ['Testing %d' % i for i in range(3)] +@pytest.mark.django_db +def test_text_stdout_with_max_stdout(sqlite_copy_expert, get, admin): + job = SystemJob() + job.save() + total_bytes = settings.STDOUT_MAX_BYTES_DISPLAY + 1 + large_stdout = 'X' * total_bytes + SystemJobEvent(system_job=job, stdout=large_stdout, start_line=0).save() + url = reverse('api:system_job_detail', kwargs={'pk': job.pk}) + response = get(url, user=admin, expect=200) + assert response.data['result_stdout'] == ( + 'Standard Output too large to display ({actual} bytes), only download ' + 'supported for sizes over {max} bytes'.format( + actual=total_bytes, + max=settings.STDOUT_MAX_BYTES_DISPLAY + ) + ) + + @pytest.mark.django_db @pytest.mark.parametrize('Parent, Child, relation, view', [ [Job, JobEvent, 'job', 'api:job_stdout'],