diff --git a/cli/medperf/entities/cube.py b/cli/medperf/entities/cube.py index a957555b1..2e33f6406 100644 --- a/cli/medperf/entities/cube.py +++ b/cli/medperf/entities/cube.py @@ -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 diff --git a/cli/medperf/tests/entities/test_cube.py b/cli/medperf/tests/entities/test_cube.py index 44dacc9ec..eb0196a44 100644 --- a/cli/medperf/tests/entities/test_cube.py +++ b/cli/medperf/tests/entities/test_cube.py @@ -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