From e0403e792469d6ae3f2568ea81df64c55203da28 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 18 Dec 2018 19:29:48 -0500 Subject: [PATCH 1/2] Keep command output when it's killed --- readthedocs/doc_builder/environments.py | 39 ++++++++++++++----- .../rtd_tests/tests/test_doc_building.py | 21 +++++++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py index 1a4d71daf32..8bd3bb486e3 100644 --- a/readthedocs/doc_builder/environments.py +++ b/readthedocs/doc_builder/environments.py @@ -3,10 +3,13 @@ """Documentation Builder Environments.""" from __future__ import ( - absolute_import, division, print_function, unicode_literals) + absolute_import, + division, + print_function, + unicode_literals, +) import logging -import json import os import re import socket @@ -32,13 +35,28 @@ from readthedocs.restapi.client import api as api_v2 from .constants import ( - DOCKER_HOSTNAME_MAX_LEN, DOCKER_IMAGE, DOCKER_LIMITS, DOCKER_OOM_EXIT_CODE, - DOCKER_SOCKET, DOCKER_TIMEOUT_EXIT_CODE, DOCKER_VERSION, - MKDOCS_TEMPLATE_DIR, SPHINX_TEMPLATE_DIR) + DOCKER_HOSTNAME_MAX_LEN, + DOCKER_IMAGE, + DOCKER_LIMITS, + DOCKER_OOM_EXIT_CODE, + DOCKER_SOCKET, + DOCKER_TIMEOUT_EXIT_CODE, + DOCKER_VERSION, + MKDOCS_TEMPLATE_DIR, + SPHINX_TEMPLATE_DIR, +) from .exceptions import ( - BuildEnvironmentCreationFailed, BuildEnvironmentError, - BuildEnvironmentException, BuildEnvironmentWarning, BuildTimeoutError, - ProjectBuildsSkippedError, VersionLockedError, YAMLParseError, MkDocsYAMLParseError) + BuildEnvironmentCreationFailed, + BuildEnvironmentError, + BuildEnvironmentException, + BuildEnvironmentWarning, + BuildTimeoutError, + MkDocsYAMLParseError, + ProjectBuildsSkippedError, + VersionLockedError, + YAMLParseError, +) + log = logging.getLogger(__name__) @@ -295,8 +313,9 @@ def run(self): # is in the last 15 lines of the command's output killed_in_output = 'Killed' in '\n'.join(self.output.splitlines()[-15:]) if self.exit_code == DOCKER_OOM_EXIT_CODE or (self.exit_code == 1 and killed_in_output): - self.output = _('Command killed due to excessive memory ' - 'consumption\n') + self.output += str(_( + 'Command killed due to excessive memory consumption\n' + )) except DockerAPIError: self.exit_code = -1 if self.output is None or not self.output: diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py index 08e96e58d0f..6a954de74d6 100644 --- a/readthedocs/rtd_tests/tests/test_doc_building.py +++ b/readthedocs/rtd_tests/tests/test_doc_building.py @@ -6,7 +6,11 @@ * the Command wrappers encapsulate the bytes and expose unicode """ from __future__ import ( - absolute_import, division, print_function, unicode_literals) + absolute_import, + division, + print_function, + unicode_literals, +) import json import os @@ -27,8 +31,11 @@ from readthedocs.builds.models import Version from readthedocs.doc_builder.config import load_yaml_config from readthedocs.doc_builder.environments import ( - BuildCommand, DockerBuildCommand, DockerBuildEnvironment, - LocalBuildEnvironment) + BuildCommand, + DockerBuildCommand, + DockerBuildEnvironment, + LocalBuildEnvironment, +) from readthedocs.doc_builder.exceptions import BuildEnvironmentError from readthedocs.doc_builder.python_environments import Conda, Virtualenv from readthedocs.projects.models import Project @@ -36,6 +43,7 @@ from readthedocs.rtd_tests.mocks.paths import fake_paths_lookup from readthedocs.rtd_tests.tests.test_config_integration import create_load + DUMMY_BUILD_ID = 123 SAMPLE_UNICODE = u'HérÉ îß sömê ünïçó∂é' SAMPLE_UTF8_BYTES = SAMPLE_UNICODE.encode('utf-8') @@ -1127,9 +1135,10 @@ def test_command_oom_kill(self): cmd.build_env.get_client.return_value = self.mocks.docker_client type(cmd.build_env).container_id = PropertyMock(return_value='foo') cmd.run() - self.assertEqual( - str(cmd.output), - u'Command killed due to excessive memory consumption\n') + self.assertIn( + 'Command killed due to excessive memory consumption\n', + str(cmd.output) + ) class TestPythonEnvironment(TestCase): From 27568668b0a7e48f4f962b09280e7dd421bda4f6 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 20 Dec 2018 20:01:36 -0500 Subject: [PATCH 2/2] Add line breaks --- readthedocs/doc_builder/environments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py index 8bd3bb486e3..d48fc73641f 100644 --- a/readthedocs/doc_builder/environments.py +++ b/readthedocs/doc_builder/environments.py @@ -314,7 +314,7 @@ def run(self): killed_in_output = 'Killed' in '\n'.join(self.output.splitlines()[-15:]) if self.exit_code == DOCKER_OOM_EXIT_CODE or (self.exit_code == 1 and killed_in_output): self.output += str(_( - 'Command killed due to excessive memory consumption\n' + '\n\nCommand killed due to excessive memory consumption\n' )) except DockerAPIError: self.exit_code = -1