]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: use parsed_container_cpu_perc in cephadm.py
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 30 Jan 2025 00:25:52 +0000 (19:25 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 30 Jan 2025 00:49:29 +0000 (19:49 -0500)
Replace the use of _parse_cpu_perc and related command calls with
parsed_container_mem_usage.  This needs no additional test updates
because the test updates in the previous patch that added
parsed_container_mem_usage covered all of that already.

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

index 95c5d2d9a148ec61ed46fe74dfff0c6507a2288b..39262f44c602d77415a4f2e7f7be7def50141006 100755 (executable)
@@ -89,6 +89,7 @@ from cephadmlib.container_engines import (
     check_container_engine,
     find_container_engine,
     parsed_container_mem_usage,
+    parsed_container_cpu_perc,
     pull_command,
     registry_login,
 )
@@ -3448,13 +3449,7 @@ def list_daemons(
     seen_memusage = {}  # type: Dict[str, int]
     seen_cpuperc = {}  # type: Dict[str, str]
     seen_memusage_cid_len, seen_memusage = parsed_container_mem_usage(ctx)
-
-    out, err, code = call(
-        ctx,
-        [container_path, 'stats', '--format', '{{.ID}},{{.CPUPerc}}', '--no-stream'],
-        verbosity=CallVerbosity.QUIET
-    )
-    seen_cpuperc_cid_len, seen_cpuperc = _parse_cpu_perc(code, out)
+    seen_cpuperc_cid_len, seen_cpuperc = parsed_container_cpu_perc(ctx)
 
     # /var/lib/ceph
     if os.path.exists(data_dir):
@@ -3657,22 +3652,6 @@ def list_daemons(
     return ls
 
 
-def _parse_cpu_perc(code: int, out: str) -> Tuple[int, Dict[str, str]]:
-    seen_cpuperc = {}
-    seen_cpuperc_cid_len = 0
-    if not code:
-        for line in out.splitlines():
-            (cid, cpuperc) = line.split(',')
-            try:
-                seen_cpuperc[cid] = cpuperc
-                if not seen_cpuperc_cid_len:
-                    seen_cpuperc_cid_len = len(cid)
-            except ValueError:
-                logger.info('unable to parse cpu percentage line\n>{}'.format(line))
-                pass
-    return seen_cpuperc_cid_len, seen_cpuperc
-
-
 def get_daemon_description(ctx, fsid, name, detail=False, legacy_dir=None):
     # type: (CephadmContext, str, str, bool, Optional[str]) -> Dict[str, str]