From e31985ba26b74306074585cc65bcef62762aaae9 Mon Sep 17 00:00:00 2001 From: Diane Feddema Date: Mon, 7 Aug 2023 13:25:39 -0600 Subject: [PATCH] Add podman unit tests (#312) Podman unit tests for docker runner. --- .../mlcube_docker/tests/test_docker_runner.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/runners/mlcube_docker/mlcube_docker/tests/test_docker_runner.py b/runners/mlcube_docker/mlcube_docker/tests/test_docker_runner.py index 1134c93..c2bc608 100644 --- a/runners/mlcube_docker/mlcube_docker/tests/test_docker_runner.py +++ b/runners/mlcube_docker/mlcube_docker/tests/test_docker_runner.py @@ -10,6 +10,8 @@ from mlcube.shell import Shell _HAVE_DOCKER: bool = Shell.run(["docker", "--version"], on_error="ignore") == 0 +_HAVE_PODMAN: bool = Shell.run(["podman", "--version"], on_error="ignore") == 0 + _MLCUBE_DEFAULT_ENTRY_POINT = """ docker: @@ -54,13 +56,13 @@ def setUp(self) -> None: def tearDown(self) -> None: Shell.sync_workspace = self.sync_workspace - @unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.") - def test_mlcube_default_entrypoints(self): + def default_entry_points(self, executable: str) -> None: with patch("io.open", mock_open(read_data=_MLCUBE_DEFAULT_ENTRY_POINT)): mlcube: DictConfig = MLCubeConfig.create_mlcube_config( "/some/path/to/mlcube.yaml", runner_config=Config.DEFAULT, runner_cls=DockerRun, + mlcube_cli_args=OmegaConf.create({"docker": {"docker": executable}}), ) self.assertEqual(mlcube.runner.image, "ubuntu:18.04") self.assertDictEqual( @@ -76,13 +78,13 @@ def test_mlcube_default_entrypoints(self): DockerRun(mlcube, task="ls").run() DockerRun(mlcube, task="pwd").run() - @unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.") - def test_mlcube_custom_entrypoints(self): + def custom_entry_points(self, executable: str) -> None: with patch("io.open", mock_open(read_data=_MLCUBE_CUSTOM_ENTRY_POINTS)): mlcube: DictConfig = MLCubeConfig.create_mlcube_config( "/some/path/to/mlcube.yaml", runner_config=Config.DEFAULT, runner_cls=DockerRun, + mlcube_cli_args=OmegaConf.create({"docker": {"docker": executable}}), ) self.assertEqual(mlcube.runner.image, "ubuntu:18.04") self.assertDictEqual( @@ -100,3 +102,19 @@ def test_mlcube_custom_entrypoints(self): self._check_inspect_output(DockerRun(mlcube, task=None).inspect()) DockerRun(mlcube, task="ls").run() DockerRun(mlcube, task="free").run() + + @unittest.skipUnless(_HAVE_PODMAN, reason="No podman available.") + def test_default_entrypoints_with_podman(self): + self.default_entry_points("podman") + + @unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.") + def test_default_entrypoints_with_docker(self): + self.default_entry_points("docker") + + @unittest.skipUnless(_HAVE_PODMAN, reason="No podman available.") + def test_custom_entrypoints_with_podman(self): + self.custom_entry_points("podman") + + @unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.") + def test_custom_entrypoints_with_docker(self): + self.custom_entry_points("docker")