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

Mlcube download docker cli hints #546

Closed
wants to merge 5 commits into from
Closed
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
17 changes: 14 additions & 3 deletions cli/medperf/entities/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ def _set_image_hash_from_registry(self):
cmd = f"mlcube --log-level {config.loglevel} inspect --mlcube={self.cube_path} --format=yaml"
cmd += f" --platform={config.platform} --output-file {tmp_out_yaml}"
logging.info(f"Running MLCube command: {cmd}")
with spawn_and_kill(cmd, timeout=config.mlcube_inspect_timeout) as proc_wrapper:
cmd_env = {**os.environ}
if config.platform == "docker":
cmd_env["DOCKER_CLI_HINTS"] = "false"
with spawn_and_kill(cmd, timeout=config.mlcube_inspect_timeout, env=cmd_env) as proc_wrapper:
proc = proc_wrapper.proc
combine_proc_sp_text(proc)
if proc.exitstatus != 0:
Expand All @@ -267,7 +270,11 @@ def _get_image_from_registry(self):
if config.platform == "singularity":
cmd += f" -Psingularity.image={self._converted_singularity_image_name}"
logging.info(f"Running MLCube command: {cmd}")
with spawn_and_kill(cmd, timeout=config.mlcube_configure_timeout) as proc_wrapper:

cmd_env = {**os.environ}
if config.platform == "docker":
cmd_env["DOCKER_CLI_HINTS"] = "false"
with spawn_and_kill(cmd, timeout=config.mlcube_configure_timeout, env=cmd_env) as proc_wrapper:
proc = proc_wrapper.proc
combine_proc_sp_text(proc)
if proc.exitstatus != 0:
Expand Down Expand Up @@ -327,6 +334,8 @@ def run(

container_loglevel = config.container_loglevel

cmd_env = {**os.environ}

# TODO: we should override run args instead of what we are doing below
# we shouldn't allow arbitrary run args unless our client allows it
if config.platform == "docker":
Expand All @@ -340,6 +349,8 @@ def run(

if container_loglevel:
cmd += f' -Pdocker.env_args="-e MEDPERF_LOGLEVEL={container_loglevel.upper()}"'

cmd_env['DOCKER_CLI_HINTS'] = 'false'
elif config.platform == "singularity":
# use -e to discard host env vars, -C to isolate the container (see singularity run --help)
run_args = self.get_config("singularity.run_args") or ""
Expand All @@ -363,7 +374,7 @@ def run(
cmd += " -Pplatform.accelerator_count=0"

logging.info(f"Running MLCube command: {cmd}")
with spawn_and_kill(cmd, timeout=timeout) as proc_wrapper:
with spawn_and_kill(cmd, timeout=timeout, env=cmd_env) as proc_wrapper:
proc = proc_wrapper.proc
proc_out = combine_proc_sp_text(proc)

Expand Down
16 changes: 16 additions & 0 deletions cli/medperf/tests/entities/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def setup(request, mocker, comms, fs):
return request.param


def remove_env_from_mock_calls(spy) -> None:
"""
During cube downloading, we pass `env` variable that contains all ENVs from medperf process.
As this is dynamic variable, we don't bother about what is passed there; so we do not want to test it.
Thus, we just remove passed `env` from executed calls, for it not to intersect assertion
"""
for executed_call in spy.mock_calls:
if 'env' in executed_call.kwargs:
executed_call.kwargs.pop('env')


class TestGetFiles:
@pytest.fixture(autouse=True)
def set_common_attributes(self, setup):
Expand Down Expand Up @@ -108,6 +119,7 @@ def test_download_run_files_without_image_configures_mlcube(
cube = Cube.get(self.id)
cube.download_run_files()

remove_env_from_mock_calls(spy)
# Assert
spy.assert_has_calls(expected_cmds)

Expand Down Expand Up @@ -191,6 +203,7 @@ def test_cube_runs_command(self, mocker, timeout, setup, task):
cube = Cube.get(self.id)
cube.run(task, timeout=timeout)

remove_env_from_mock_calls(spy)
# Assert
spy.assert_any_call(expected_cmd, timeout=timeout)

Expand All @@ -214,6 +227,7 @@ def test_cube_runs_command_with_rw_access(self, mocker, setup, task):
cube = Cube.get(self.id)
cube.run(task, read_protected_input=False)

remove_env_from_mock_calls(spy)
# Assert
spy.assert_any_call(expected_cmd, timeout=None)

Expand All @@ -234,6 +248,7 @@ def test_cube_runs_command_with_extra_args(self, mocker, setup, task):
cube = Cube.get(self.id)
cube.run(task, test="test")

remove_env_from_mock_calls(spy)
# Assert
spy.assert_any_call(expected_cmd, timeout=None)

Expand All @@ -257,6 +272,7 @@ def test_cube_runs_command_and_preserves_runtime_args(self, mocker, setup, task)
cube = Cube.get(self.id)
cube.run(task)

remove_env_from_mock_calls(spy)
# Assert
spy.assert_any_call(expected_cmd, timeout=None)

Expand Down
2 changes: 1 addition & 1 deletion cli/medperf/tests/mocks/pexpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def __init__(self, exitstatus, stdout="", pid=123456):
self.stdout = stdout
self.pid = pid

def spawn(self, command: str, timeout: int = 30) -> MockChild:
def spawn(self, command: str, timeout: int = 30, env: dict = None) -> MockChild:
return MockChild(self.exitstatus, self.stdout, self.pid)
Loading