]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: podman inspect: image field was called `ImageID`:
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 13 Jan 2020 13:34:03 +0000 (14:34 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 21 Jan 2020 11:50:34 +0000 (12:50 +0100)
See https://github.com/containers/libpod/pull/4195

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index d4424846a2df9850dc5c792a85a6e19c0e327dab..a3f79c7bdec6cdab121ae65b2b0f6a87e22fe669 100755 (executable)
@@ -590,6 +590,29 @@ def pathify(p):
         return os.path.join(os.getcwd(), p)
     return p
 
+
+def get_podman_version():
+    # type: () -> Tuple[int, ...]
+    if 'podman' not in container_path:
+        raise ValueError('not using podman')
+    out, _, _ = call_throws([container_path, '--version'])
+    return _parse_podman_version(out)
+
+def _parse_podman_version(out):
+    # type: (str) -> Tuple[int, ...]
+    _, _, version_str = out.strip().split()
+
+    def to_int(val, org_e=None):
+        if not val and org_e:
+            raise org_e
+        try:
+            return int(val)
+        except ValueError as e:
+            return to_int(val[0:-1], org_e or e)
+
+    return tuple(map(to_int, version_str.split('.')))
+
+
 def get_hostname():
     # type: () -> str
     return socket.gethostname()
@@ -2179,10 +2202,16 @@ def list_daemons(detail=True, legacy_dir=None):
                         image_name = None
                         image_id = None
                         version = None
+
+                        if 'podman' in container_path and get_podman_version() < (1, 6, 2):
+                            image_field = '.ImageID'
+                        else:
+                            image_field = '.Image'
+
                         out, err, code = call(
                             [
                                 container_path, 'inspect',
-                                '--format', '{{.Id}},{{.Config.Image}},{{.Image}}',
+                                '--format', '{{.Id}},{{.Config.Image}},{{%s}}' % image_field,
                                 'ceph-%s-%s' % (fsid, j)
                             ],
                             verbose_on_failure=False)
index d9bc45ce6f19c70bdce1fde5002ed71a0cef36f8..79b6db418253426a8d98472455ad679becd02a17 100644 (file)
@@ -13,9 +13,9 @@ else:
     import imp
     cd = imp.load_source('cephadm', 'cephadm')
 
-class TestCephAdm(unittest.TestCase):
+class TestCephAdm(object):
     def test_is_fsid(self):
-        self.assertFalse(cd.is_fsid('no-uuid'))
+        assert not cd.is_fsid('no-uuid')
 
     def test__get_parser_image(self):
         p = cd._get_parser()
@@ -34,3 +34,15 @@ class TestCephAdm(unittest.TestCase):
 
         with pytest.raises(SystemExit):
             p.parse_args(['deploy', '--name', 'wrong', '--fsid', 'fsid'])
+
+    @pytest.mark.parametrize("test_input, expected", [
+        ("podman version 1.6.2", (1,6,2)),
+        ("podman version 1.6.2-stable2", (1,6,2)),
+    ])
+    def test_parse_podman_version(self, test_input, expected):
+        assert cd._parse_podman_version(test_input) == expected
+
+    def test_parse_podman_version_invalid(self):
+        with pytest.raises(ValueError) as res:
+            cd._parse_podman_version('podman version inval.id')
+        assert 'inval' in str(res.value)