diff --git a/paasta_tools/paasta_execute_docker_command.py b/paasta_tools/paasta_execute_docker_command.py index 212d9717a8..0b74abd40e 100755 --- a/paasta_tools/paasta_execute_docker_command.py +++ b/paasta_tools/paasta_execute_docker_command.py @@ -32,6 +32,7 @@ from paasta_tools.mesos_tools import get_container_id_for_mesos_id from paasta_tools.utils import get_docker_client +from paasta_tools.utils import is_using_unprivileged_containers def parse_args(): @@ -68,7 +69,11 @@ def signal_handler(signum, frame): def execute_in_container(docker_client, container_id, cmd, timeout): container_info = docker_client.inspect_container(container_id) - if container_info["ExecIDs"] and len(container_info["ExecIDs"]) > 0: + if ( + container_info["ExecIDs"] + and len(container_info["ExecIDs"]) > 0 + and not is_using_unprivileged_containers() + ): for possible_exec_id in container_info["ExecIDs"]: exec_info = docker_client.exec_inspect(possible_exec_id)["ProcessConfig"] if exec_info["entrypoint"] == "/bin/sh" and exec_info["arguments"] == [ diff --git a/tests/test_paasta_execute_docker_command.py b/tests/test_paasta_execute_docker_command.py index 3b8108511f..01338eead3 100644 --- a/tests/test_paasta_execute_docker_command.py +++ b/tests/test_paasta_execute_docker_command.py @@ -38,6 +38,11 @@ def test_execute_in_container(): ) +@mock.patch( + "paasta_tools.paasta_execute_docker_command.is_using_unprivileged_containers", + lambda: False, + autospec=None, +) def test_execute_in_container_reuses_exec(): fake_container_id = "fake_container_id" fake_execid = "fake_execid" @@ -59,6 +64,11 @@ def test_execute_in_container_reuses_exec(): mock_docker_client.exec_start.assert_called_once_with(fake_execid, stream=False) +@mock.patch( + "paasta_tools.paasta_execute_docker_command.is_using_unprivileged_containers", + lambda: False, + autospec=None, +) def test_execute_in_container_reuses_only_valid_exec(): fake_container_id = "fake_container_id" fake_execid = "fake_execid"