]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: use get_container_image_stats in cephadm.py 61601/head
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 31 Jan 2025 00:04:56 +0000 (19:04 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 5 Feb 2025 18:13:06 +0000 (13:13 -0500)
Replace the existing get_container_stats_by_image_name with a version
from container_engines.py that returns the parsed results of the container
status command (as a ContainerInfo, None on error).

Fix up a few tests. Part of the test is somewhat pointless now as the
input and the output are both the same ContainerInfo, but this was never
a great test to test parsing anyway.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index 2a8f5e042bdc88e037b0266f8f73ffc9d137afce..6dc1d5cdfa08c9bcf3528f873f9e9c3cd9c98ad2 100755 (executable)
@@ -89,8 +89,9 @@ from cephadmlib.container_engines import (
     Podman,
     check_container_engine,
     find_container_engine,
-    parsed_container_mem_usage,
     parsed_container_cpu_perc,
+    parsed_container_image_stats,
+    parsed_container_mem_usage,
     pull_command,
     registry_login,
 )
@@ -500,16 +501,9 @@ def get_container_info(ctx: CephadmContext, daemon_filter: str, by_name: bool) -
             # container will not help us. If we have the image name from the list_daemons output
             # we can try that.
             image_name = matching_daemons[0]['container_image_name']
-            out, _, code = get_container_stats_by_image_name(ctx, ctx.container_engine.path, image_name)
-            if not code:
-                # keep in mind, the daemon container is not running, so no container id here
-                (image_id, start, version) = out.strip().split(',')
-                return ContainerInfo(
-                    container_id='',
-                    image_name=image_name,
-                    image_id=image_id,
-                    start=start,
-                    version=version)
+            cinfo = parsed_container_image_stats(ctx, image_name)
+            if cinfo:
+                return cinfo
         else:
             d_type, d_id = matching_daemons[0]['name'].split('.', 1)
             cinfo = get_container_stats(
@@ -3646,18 +3640,6 @@ def get_daemon_description(ctx, fsid, name, detail=False, legacy_dir=None):
         return d
     raise Error('Daemon not found: {}. See `cephadm ls`'.format(name))
 
-
-def get_container_stats_by_image_name(ctx: CephadmContext, container_path: str, image_name: str) -> Tuple[str, str, int]:
-    """returns image id, created time, and ceph version if available"""
-    out, err, code = '', '', -1
-    cmd = [
-        container_path, 'image', 'inspect',
-        '--format', '{{.Id}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
-        image_name
-    ]
-    out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
-    return out, err, code
-
 ##################################
 
 
index de4eddc2f72670b24af33e4f80cd196101896c30..f33f269c78e3bf90450d96da535bf774d433e84a 100644 (file)
@@ -803,7 +803,7 @@ class TestCephAdm(object):
         )
 
     def test_get_container_info_daemon_down(self, funkypatch):
-        _get_stats_by_name = funkypatch.patch('cephadm.get_container_stats_by_image_name')
+        _get_stats_by_name = funkypatch.patch('cephadmlib.container_engines.parsed_container_image_stats')
         _get_stats = funkypatch.patch('cephadmlib.container_types.get_container_stats')
         _list_daemons = funkypatch.patch('cephadm.list_daemons')
 
@@ -845,9 +845,6 @@ class TestCephAdm(object):
                 "configured": "2024-03-11T17:37:28.494075Z"
         }
         _list_daemons.return_value = [down_osd_json]
-        _get_stats_by_name.return_value = (('a03c201ff4080204949932f367545cd381c4acee0d48dbc15f2eac1e35f22318,'
-                                   '2023-11-28 21:34:38.045413692 +0000 UTC,'),
-                                   '', 0)
 
         expected_container_info = _cephadm.ContainerInfo(
             container_id='',
@@ -855,6 +852,10 @@ class TestCephAdm(object):
             image_id='a03c201ff4080204949932f367545cd381c4acee0d48dbc15f2eac1e35f22318',
             start='2023-11-28 21:34:38.045413692 +0000 UTC',
             version='')
+        # refactoring get_container_stats_by_image_name into
+        # parsed_container_image_stats has made this part of the test somewhat
+        # redundant
+        _get_stats_by_name.return_value = expected_container_info
 
         assert _cephadm.get_container_info(ctx, 'osd.2', by_name=True) == expected_container_info
         assert not _get_stats.called, 'only get_container_stats_by_image_name should have been called'