Skip to content

Commit

Permalink
Raise an error if mlcube configure fails
Browse files Browse the repository at this point in the history
  • Loading branch information
aristizabal95 committed Oct 10, 2023
1 parent 90b5cb3 commit 27b57d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/medperf/entities/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def download_image(self):
cmd = f"mlcube configure --mlcube={self.cube_path}"
with pexpect.spawn(cmd, timeout=config.mlcube_configure_timeout) as proc:
proc_out = proc.read()
if proc.exitstatus != 0:
raise ExecutionError(
"There was an error while retrieving the MLCube image"
)
logging.debug(proc_out)

# Retrieve image hash from MLCube
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 @@ -100,6 +100,22 @@ def test_get_cube_without_image_configures_mlcube(self, mocker, setup, fs):
# Assert
spy.assert_has_calls(expected_cmds)

@pytest.mark.parametrize("setup", [{"remote": [NO_IMG_CUBE]}], indirect=True)
def test_get_cube_stops_execution_if_configure_fails(self, mocker, setup, fs):
# Arrange
tmp_path = "tmp_path"
mocker.patch(PATCH_CUBE.format("generate_tmp_path"), return_value=tmp_path)
# This is the side effect of mlcube inspect
fs.create_file(
"tmp_path", contents=yaml.dump({"hash": NO_IMG_CUBE["image_hash"]})
)
mpexpect = MockPexpect(1, "expected_hash")
mocker.patch("pexpect.spawn", side_effect=mpexpect.spawn)

# Act & Assert
with pytest.raises(ExecutionError):
Cube.get(self.id)

@pytest.mark.parametrize("setup", [{"remote": [NO_IMG_CUBE]}], indirect=True)
def test_get_cube_without_image_fails_with_wrong_hash(self, mocker, setup, fs):
# Arrange
Expand Down

0 comments on commit 27b57d6

Please sign in to comment.