Skip to content
Merged
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 nemo_run/core/execution/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def run(self, client: "DockerClient", id: str) -> "Container":
detach=True,
remove=True,
name=self.name,
hostname=self.name,
hostname=self.name[-32:],
network=self.executor.network,
working_dir=f"/{RUNDIR_NAME}/code",
labels={
Expand Down
74 changes: 74 additions & 0 deletions test/core/execution/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,80 @@ def test_delete_error(self, mock_docker_client, mock_container):
container.get_container.assert_called_once_with(client=mock_docker_client, id="job123")
mock_container.remove.assert_called_once_with(force=True)

@patch("nemo_run.core.execution.docker.ensure_network")
def test_run_with_short_container_name(self, mock_ensure_network, mock_docker_client):
"""Test run method with container name <= 32 characters."""
executor = DockerExecutor(container_image="test:latest")
executor.experiment_id = "exp123"

container = DockerContainer(
name="short-name",
command=["python", "script.py"],
executor=executor,
extra_env={},
)

mock_docker_client.containers.run.return_value = MagicMock()

container.run(mock_docker_client, "job123")

# Verify hostname is set to the full name
call_kwargs = mock_docker_client.containers.run.call_args[1]
assert call_kwargs["hostname"] == "short-name"
assert len(call_kwargs["hostname"]) <= 32

@patch("nemo_run.core.execution.docker.ensure_network")
def test_run_with_long_container_name(self, mock_ensure_network, mock_docker_client):
"""Test run method with container name > 32 characters."""
executor = DockerExecutor(container_image="test:latest")
executor.experiment_id = "exp123"

# Create a name that's longer than 32 characters
long_name = "this-is-a-very-long-container-name-that-exceeds-thirty-two-characters"
assert len(long_name) > 32

container = DockerContainer(
name=long_name,
command=["python", "script.py"],
executor=executor,
extra_env={},
)

mock_docker_client.containers.run.return_value = MagicMock()

container.run(mock_docker_client, "job123")

# Verify hostname is truncated to last 32 characters
call_kwargs = mock_docker_client.containers.run.call_args[1]
assert call_kwargs["hostname"] == long_name[-32:]
assert len(call_kwargs["hostname"]) == 32

@patch("nemo_run.core.execution.docker.ensure_network")
def test_run_with_exactly_32_char_name(self, mock_ensure_network, mock_docker_client):
"""Test run method with container name exactly 32 characters."""
executor = DockerExecutor(container_image="test:latest")
executor.experiment_id = "exp123"

# Create a name that's exactly 32 characters
exact_name = "a" * 32
assert len(exact_name) == 32

container = DockerContainer(
name=exact_name,
command=["python", "script.py"],
executor=executor,
extra_env={},
)

mock_docker_client.containers.run.return_value = MagicMock()

container.run(mock_docker_client, "job123")

# Verify hostname is set to the full name
call_kwargs = mock_docker_client.containers.run.call_args[1]
assert call_kwargs["hostname"] == exact_name
assert len(call_kwargs["hostname"]) == 32


class TestDockerJobRequest:
def test_init(self, docker_executor):
Expand Down
Loading