From f69feebab07a5a98d9867848fc4aef1bba15c256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Aristiz=C3=A1bal?= Date: Wed, 11 Oct 2023 12:45:52 -0500 Subject: [PATCH] Fix MLCube configure silently failing (#494) * Add Data Preparator cookiecutter template * Rename cookiecutter folder * Temporarily remove possibly offending files * Remove cookicutter conditionals * Inclube back missing pieces of template * remove cookiecutter typo * Use project_name attribute * Change cookiecutter fields order * Create empty directories on hook * Fix empty folders paths * Create evaluator mlcube cookiecutter template * Fix JSON Syntax Error * Update template default values * Remove reference to undefined template variable * Implement model mlcube cookiecutter template * Update cookiecutter variable default values * Create medperf CLI command for creating MLCubes * Provide additional options for mlcube create * Start working on tests * Add tests for cube create * Ignore invalid syntax on cookiecutter conditionals * Ignore more flake8 errors * Remove unused import * Empty commit for cloudbuild * Fix inconsistency with labels paths * Update mlcube.yaml so it can be commented on docs * Don't render noqa comments on template * Remove flake8 specific ignores * Exclude templates from lint checks * Remove specific flake8 ignores * Fix labels_paht being passed in he wrong situation * Add requirements to cookiecutters * Set separate labels as true by default * Remove duplicate templates * Abstract field-error dict formatting * Reformat errors dictionary for printing * Raise an error if mlcube configure fails --- cli/medperf/entities/cube.py | 4 ++++ cli/medperf/tests/entities/test_cube.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cli/medperf/entities/cube.py b/cli/medperf/entities/cube.py index f717cfd93..ac2d58b55 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 934d8a89e..aee7f4009 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