From: John Mulligan Date: Thu, 30 Jan 2025 00:25:52 +0000 (-0500) Subject: cephadm: use parsed_container_cpu_perc in cephadm.py X-Git-Tag: testing/wip-pdonnell-testing-20250205.170831-debug~3^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=530a81a5a63a6c2cbcc552e9c0fe79b76dcaa869;p=ceph-ci.git cephadm: use parsed_container_cpu_perc in cephadm.py 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 --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 95c5d2d9a14..39262f44c60 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -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]