Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep command output when it's killed #5015

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand Down Expand Up @@ -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'
stsewd marked this conversation as resolved.
Show resolved Hide resolved
))
except DockerAPIError:
self.exit_code = -1
if self.output is None or not self.output:
Expand Down
21 changes: 15 additions & 6 deletions readthedocs/rtd_tests/tests/test_doc_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,15 +31,19 @@
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
from readthedocs.rtd_tests.mocks.environment import EnvironmentMockGroup
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')
Expand Down Expand Up @@ -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):
Expand Down