]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: add test cases for container engine classes
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 20 Sep 2022 19:53:08 +0000 (15:53 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 21 Sep 2022 19:54:00 +0000 (15:54 -0400)
Fixes: https://tracker.ceph.com/issues/57621
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/tests/test_container_engine.py [new file with mode: 0644]

diff --git a/src/cephadm/tests/test_container_engine.py b/src/cephadm/tests/test_container_engine.py
new file mode 100644 (file)
index 0000000..c0e0370
--- /dev/null
@@ -0,0 +1,57 @@
+from unittest import mock
+
+import pytest
+
+from tests.fixtures import with_cephadm_ctx
+
+with mock.patch("builtins.open", create=True):
+    from importlib.machinery import SourceFileLoader
+
+    cephadm = SourceFileLoader("cephadm", "cephadm.py").load_module()
+
+
+def test_container_engine():
+    with pytest.raises(NotImplementedError):
+        cephadm.ContainerEngine()
+
+    class PhonyContainerEngine(cephadm.ContainerEngine):
+        EXE = "true"
+
+    with mock.patch("cephadm.find_program") as find_program:
+        find_program.return_value = "/usr/bin/true"
+        pce = PhonyContainerEngine()
+        assert str(pce) == "true (/usr/bin/true)"
+
+
+def test_podman():
+    with mock.patch("cephadm.find_program") as find_program:
+        find_program.return_value = "/usr/bin/podman"
+        pm = cephadm.Podman()
+        find_program.assert_called()
+        with pytest.raises(RuntimeError):
+            pm.version
+        with mock.patch("cephadm.call_throws") as call_throws:
+            call_throws.return_value = ("4.9.9", None, None)
+            with with_cephadm_ctx([]) as ctx:
+                pm.get_version(ctx)
+        assert pm.version == (4, 9, 9)
+        assert str(pm) == "podman (/usr/bin/podman) version 4.9.9"
+
+
+def test_podman_badversion():
+    with mock.patch("cephadm.find_program") as find_program:
+        find_program.return_value = "/usr/bin/podman"
+        pm = cephadm.Podman()
+        find_program.assert_called()
+        with mock.patch("cephadm.call_throws") as call_throws:
+            call_throws.return_value = ("4.10.beta2", None, None)
+            with with_cephadm_ctx([]) as ctx:
+                with pytest.raises(ValueError):
+                    pm.get_version(ctx)
+
+
+def test_docker():
+    with mock.patch("cephadm.find_program") as find_program:
+        find_program.return_value = "/usr/bin/docker"
+        docker = cephadm.Docker()
+        assert str(docker) == "docker (/usr/bin/docker)"