Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion sagemaker-core/src/sagemaker/core/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _get_compose_cmd_prefix():
stderr=subprocess.DEVNULL,
encoding="UTF-8",
)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
logger.info(
"'Docker Compose' is not installed. "
"Proceeding to check for 'docker-compose' CLI."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _get_compose_cmd_prefix(self) -> List[str]:
stderr=subprocess.DEVNULL,
encoding="UTF-8",
)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
logger.info(
"'Docker Compose' is not installed. "
"Proceeding to check for 'docker-compose' CLI."
Expand Down
14 changes: 14 additions & 0 deletions sagemaker-core/tests/unit/local/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,20 @@ def test_get_compose_cmd_prefix_not_installed(self):
with pytest.raises(ImportError, match="Docker Compose is not installed"):
_SageMakerContainer._get_compose_cmd_prefix()

def test_get_compose_cmd_prefix_docker_binary_not_found_falls_back_to_standalone(self):
"""Test _get_compose_cmd_prefix falls back to standalone when docker binary not found"""
with patch("subprocess.check_output", side_effect=FileNotFoundError("No such file or directory: 'docker'")):
with patch("shutil.which", return_value="/usr/local/bin/docker-compose"):
result = _SageMakerContainer._get_compose_cmd_prefix()
assert result == ["docker-compose"]

def test_get_compose_cmd_prefix_docker_binary_not_found_no_standalone_raises(self):
"""Test _get_compose_cmd_prefix raises when docker binary not found and no standalone"""
with patch("subprocess.check_output", side_effect=FileNotFoundError("No such file or directory: 'docker'")):
with patch("shutil.which", return_value=None):
with pytest.raises(ImportError, match="Docker Compose is not installed"):
_SageMakerContainer._get_compose_cmd_prefix()

def test_process_with_multiple_inputs(self, mock_session):
"""Test process method with multiple processing inputs"""
container = _SageMakerContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,59 @@ def test_get_compose_cmd_prefix_docker_compose_v1_rejected(
with pytest.raises(ImportError, match="Docker Compose is not installed"):
container._get_compose_cmd_prefix()

@patch("sagemaker.core.modules.local_core.local_container.subprocess.check_output")
@patch("sagemaker.core.modules.local_core.local_container.shutil.which")
def test_get_compose_cmd_prefix_docker_binary_not_found_falls_back_to_standalone(
self, mock_which, mock_check_output, mock_session, basic_channel
):
"""Test _get_compose_cmd_prefix falls back to standalone when docker binary not found"""
container = _LocalContainer(
training_job_name="test-job",
instance_type="local",
instance_count=1,
image="test-image:latest",
container_root="/tmp/test",
input_data_config=[basic_channel],
environment={},
hyper_parameters={},
container_entrypoint=[],
container_arguments=[],
sagemaker_session=mock_session,
)

mock_check_output.side_effect = FileNotFoundError("No such file or directory: 'docker'")
mock_which.return_value = "/usr/local/bin/docker-compose"

result = container._get_compose_cmd_prefix()

assert result == ["docker-compose"]

@patch("sagemaker.core.modules.local_core.local_container.subprocess.check_output")
@patch("sagemaker.core.modules.local_core.local_container.shutil.which")
def test_get_compose_cmd_prefix_docker_binary_not_found_no_standalone_raises(
self, mock_which, mock_check_output, mock_session, basic_channel
):
"""Test _get_compose_cmd_prefix raises when docker binary not found and no standalone"""
container = _LocalContainer(
training_job_name="test-job",
instance_type="local",
instance_count=1,
image="test-image:latest",
container_root="/tmp/test",
input_data_config=[basic_channel],
environment={},
hyper_parameters={},
container_entrypoint=[],
container_arguments=[],
sagemaker_session=mock_session,
)

mock_check_output.side_effect = FileNotFoundError("No such file or directory: 'docker'")
mock_which.return_value = None

with pytest.raises(ImportError, match="Docker Compose is not installed"):
container._get_compose_cmd_prefix()

def test_init_with_container_entrypoint(self, mock_session, basic_channel):
"""Test initialization with container entrypoint"""
container = _LocalContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def _get_compose_cmd_prefix(self) -> List[str]:
stderr=subprocess.DEVNULL,
encoding="UTF-8",
)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
logger.info(
"'Docker Compose' is not installed. "
"Proceeding to check for 'docker-compose' CLI."
Expand Down
24 changes: 24 additions & 0 deletions sagemaker-train/tests/unit/train/local/test_local_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,27 @@ def test_get_compose_cmd_prefix_standalone_fallback(
mock_which.return_value = "/usr/local/bin/docker-compose"
result = container._get_compose_cmd_prefix()
assert result == ["docker-compose"]

@patch("sagemaker.train.local.local_container.shutil.which")
@patch("sagemaker.train.local.local_container.subprocess.check_output")
def test_get_compose_cmd_prefix_docker_binary_not_found_falls_back_to_standalone(
self, mock_check_output, mock_which, _basic_channel
):
"""When docker binary is not found (FileNotFoundError), falls back to docker-compose standalone."""
container = _make_container(_basic_channel)
mock_check_output.side_effect = FileNotFoundError("No such file or directory: 'docker'")
mock_which.return_value = "/usr/local/bin/docker-compose"
result = container._get_compose_cmd_prefix()
assert result == ["docker-compose"]

@patch("sagemaker.train.local.local_container.shutil.which")
@patch("sagemaker.train.local.local_container.subprocess.check_output")
def test_get_compose_cmd_prefix_docker_binary_not_found_no_standalone_raises(
self, mock_check_output, mock_which, _basic_channel
):
"""When docker binary is not found and no standalone docker-compose, raises ImportError."""
container = _make_container(_basic_channel)
mock_check_output.side_effect = FileNotFoundError("No such file or directory: 'docker'")
mock_which.return_value = None
with pytest.raises(ImportError, match="Docker Compose is not installed"):
container._get_compose_cmd_prefix()
Loading