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,
)
# 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(
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
-
##################################
)
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')
"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='',
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'