InitContainer,
SidecarContainer,
extract_uid_gid,
- is_container_running,
+ get_container_stats,
get_mgr_images,
+ is_container_running,
)
from cephadmlib.decorators import (
deprecated_command,
version=version)
else:
d_type, d_id = matching_daemons[0]['name'].split('.', 1)
- out, _, code = get_container_stats(ctx, ctx.container_engine.path, ctx.fsid, d_type, d_id)
- if not code:
- (container_id, image_name, image_id, start, version) = out.strip().split(',')
- return ContainerInfo(container_id, image_name, image_id, start, version)
+ cinfo = get_container_stats(
+ ctx, DaemonIdentity(ctx.fsid, d_type, d_id)
+ )
+ if cinfo:
+ return cinfo
return None
version = None
start_stamp = None
- out, err, code = get_container_stats(ctx, container_path, fsid, daemon_type, daemon_id)
- if not code:
- (container_id, image_name, image_id, start,
- version) = out.strip().split(',')
+ cinfo = get_container_stats(
+ ctx,
+ DaemonIdentity(fsid, daemon_type, daemon_id),
+ container_path=container_path
+ )
+ if cinfo:
+ container_id = cinfo.container_id
+ image_name = cinfo.image_name
+ image_id = cinfo.image_id
+ start = cinfo.start
+ version = cinfo.version
image_id = normalize_container_id(image_id)
daemon_type = name.split('.', 1)[0]
start_stamp = try_convert_datetime(start)
raise Error('Daemon not found: {}. See `cephadm ls`'.format(name))
-def get_container_stats(ctx: CephadmContext, container_path: str, fsid: str, daemon_type: str, daemon_id: str) -> Tuple[str, str, int]:
- """returns container id, image name, image id, created time, and ceph version if available"""
- c = CephContainer.for_daemon(
- ctx, DaemonIdentity(fsid, daemon_type, daemon_id), 'bash'
- )
- out, err, code = '', '', -1
- for name in (c.cname, c.old_cname):
- cmd = [
- container_path, 'inspect',
- '--format', '{{.Id}},{{.Config.Image}},{{.Image}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
- name
- ]
- out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
- if not code:
- break
- return out, err, code
-
-
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
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mgr.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
_cephadm.ContainerInfo('935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972',
'registry.hub.docker.com/rkachach/ceph:custom-v0.5',
'666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4',
{'name': 'mgr.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
_cephadm.ContainerInfo('935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972',
'registry.hub.docker.com/rkachach/ceph:custom-v0.5',
'666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4',
{'name': 'mon.ceph-node-0', 'fsid': '10000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
_cephadm.ContainerInfo('935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972',
'registry.hub.docker.com/rkachach/ceph:custom-v0.5',
'666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4',
{'name': 'mon.ceph-node-0', 'fsid': '00000000-FFFF-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("",
- "",
- 127),
+ None,
None
),
# get container info by name (bad container stats: 127 code)
{'name': 'mgr.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("",
- "",
- 127),
+ None,
None
),
# get container info by invalid name (doens't contain '.')
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
None
),
# get container info by invalid name (empty)
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
None
),
# get container info by invalid type (empty)
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-0000-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
None
),
# get container info by name: no match (invalid fsid)
{'name': 'mon.ceph-node-0', 'fsid': '00000000-1111-0000-0000-0000deadbeef'},
{'name': 'mon.ceph-node-0', 'fsid': '00000000-2222-0000-0000-0000deadbeef'},
],
- ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972,registry.hub.docker.com/rkachach/ceph:custom-v0.5,666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4,2022-04-19 13:45:20.97146228 +0000 UTC,",
- "",
- 0),
+ ("935b549714b8f007c6a4e29c758689cf9e8e69f2e0f51180506492974b90a972", "registry.hub.docker.com/rkachach/ceph:custom-v0.5", "666bbfa87e8df05702d6172cae11dd7bc48efb1d94f1b9e492952f19647199a4", "2022-04-19 13:45:20.97146228 +0000 UTC", ""
+ ),
None
),
# get container info by name: no match
None
),
])
- @mock.patch('cephadm.logger')
- def test_get_container_info(self, _logger, daemon_filter, by_name, daemon_list, container_stats, output):
+ def test_get_container_info(
+ self,
+ daemon_filter,
+ by_name,
+ daemon_list,
+ container_stats,
+ output,
+ funkypatch,
+ ):
ctx = _cephadm.CephadmContext()
ctx.fsid = '00000000-0000-0000-0000-0000deadbeef'
ctx.container_engine = mock_podman()
- with mock.patch('cephadm.list_daemons', return_value=daemon_list):
- with mock.patch('cephadm.get_container_stats', return_value=container_stats):
- assert _cephadm.get_container_info(ctx, daemon_filter, by_name) == output
-
- @mock.patch('cephadm.list_daemons')
- @mock.patch('cephadm.get_container_stats')
- @mock.patch('cephadm.get_container_stats_by_image_name')
- def test_get_container_info_daemon_down(self, _get_stats_by_name, _get_stats, _list_daemons):
+ funkypatch.patch('cephadm.list_daemons').return_value = daemon_list
+ cinfo = (
+ _cephadm.ContainerInfo(*container_stats)
+ if container_stats
+ else None
+ )
+ funkypatch.patch(
+ 'cephadmlib.container_types.get_container_stats'
+ ).return_value = cinfo
+ assert (
+ _cephadm.get_container_info(ctx, daemon_filter, by_name) == output
+ )
+
+ def test_get_container_info_daemon_down(self, funkypatch):
+ _get_stats_by_name = funkypatch.patch('cephadm.get_container_stats_by_image_name')
+ _get_stats = funkypatch.patch('cephadmlib.container_types.get_container_stats')
+ _list_daemons = funkypatch.patch('cephadm.list_daemons')
+
ctx = _cephadm.CephadmContext()
ctx.fsid = '5e39c134-dfc5-11ee-a344-5254000ee071'
ctx.container_engine = mock_podman()
# than it partially being taken from the list_daemons output
up_osd_json = copy.deepcopy(down_osd_json)
up_osd_json['state'] = 'running'
- _get_stats.return_value = (('container_id,image_name,image_id,the_past,'), '', 0)
+ _get_stats.return_value = _cephadm.ContainerInfo('container_id', 'image_name','image_id','the_past','')
_list_daemons.return_value = [down_osd_json, up_osd_json]
expected_container_info = _cephadm.ContainerInfo(