Skip to content

Commit 4940596

Browse files
committed
cephadm: still set keep_container_info key in CoreStatusUpdater when cinfo is None
When testing an unrelated thing with rm-cluster cleaning up OSD devices, I was hitting ``` Traceback (most recent call last): File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/usr/sbin/cephadm/__main__.py", line 5400, in <module> File "/usr/sbin/cephadm/__main__.py", line 5388, in main File "/usr/sbin/cephadm/__main__.py", line 3996, in command_rm_cluster File "/usr/sbin/cephadm/__main__.py", line 4034, in _rm_cluster File "/usr/sbin/cephadm/__main__.py", line 428, in _infer_image File "/usr/sbin/cephadm/cephadmlib/container_lookup.py", line 127, in infer_local_ceph_image File "/usr/sbin/cephadm/cephadmlib/container_lookup.py", line 128, in <listcomp> KeyError: '_container_info' ``` which appears to have been caused by the CoreStatusUpdater only setting the "keep_container_info" key entry when the container info it gets back from get_container_stats is not None. This patch has it set that key entry even when the container info is None, and updates infer_local_ceph_image to be able to handle the container info at that entry being None as well. Signed-off-by: Adam King <[email protected]>
1 parent 5549c10 commit 4940596

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/cephadm/cephadmlib/container_lookup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def infer_local_ceph_image(
134134
images_in_use_by_daemon = set(
135135
d.image_id for d, n in matching_daemons if n == daemon_name
136136
)
137-
images_in_use = set(d.image_id for d, _ in matching_daemons)
137+
images_in_use = set(
138+
d.image_id for d, _ in matching_daemons if d is not None
139+
)
138140

139141
# prioritize images
140142
def _keyfunc(image: ImageInfo) -> Tuple[bool, bool, str]:

src/cephadm/cephadmlib/listing_updaters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def update(
5959
data_dir, identity.fsid, identity.daemon_name
6060
)
6161
cinfo = get_container_stats(ctx, identity)
62+
if self.keep_container_info:
63+
val[self.keep_container_info] = cinfo
6264
if cinfo:
63-
if self.keep_container_info:
64-
val[self.keep_container_info] = cinfo
6565
container_id = cinfo.container_id
6666
image_name = cinfo.image_name
6767
image_id = cinfo.image_id

src/cephadm/tests/test_cephadm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,30 @@ def test_infer_local_ceph_image(self, params, funkypatch):
804804
image = _cephadm.infer_local_ceph_image(ctx, ctx.container_engine)
805805
assert image == expected
806806

807+
def test_infer_local_ceph_image_no_cinfo(self, funkypatch):
808+
ctx = _cephadm.CephadmContext()
809+
ctx.fsid = '00000000-0000-0000-0000-0000deadbeez'
810+
ctx.container_engine = mock_podman()
811+
812+
out = """quay.ceph.io/ceph-ci/ceph@sha256:d6d1f4ab7148145467d9b632efc89d75710196434cba00aec5571b01e15b8a99|1b58ca4f6df|test|2025-01-21 16:54:41 +0000 UTC
813+
quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789|c17226ffd482|test|2025-01-22 16:54:41 +0000 UTC"""
814+
funkypatch.patch('cephadmlib.call_wrappers.call').return_value = (
815+
out,
816+
'',
817+
0,
818+
)
819+
funkypatch.patch(
820+
'cephadmlib.listing_updaters.CoreStatusUpdater'
821+
)().expand.side_effect = lambda ctx, v: v
822+
funkypatch.patch(
823+
'cephadmlib.listing.daemons_matching'
824+
).return_value = [
825+
{'_container_info': None, 'name': 'mon.vm-00'},
826+
{'_container_info': None, 'name': 'mgr.vm-00.cdjeee'}
827+
]
828+
image = _cephadm.infer_local_ceph_image(ctx, ctx.container_engine)
829+
assert image == 'quay.ceph.io/ceph-ci/ceph@sha256:8eb43767c40d3e2d8cdb7577904f5f0b94373afe2dde29672c2b0001bd098789'
830+
807831
@pytest.mark.parametrize('daemon_filter, by_name, daemon_list, container_stats, output',
808832
[
809833
# get container info by type ('mon')

src/cephadm/tests/test_listing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,28 @@ def _fake_call(ctx, cmd, *args, **kwargs):
229229
edl.assert_checked_all()
230230

231231

232+
def test_core_status_update_no_cinfo(cephadm_fs, funkypatch):
233+
_cephadm = import_cephadm()
234+
235+
_get_container_stats = funkypatch.patch('cephadmlib.container_types.get_container_stats')
236+
_get_container_stats.return_value = None
237+
238+
fsid = 'dc93cfee-ddc5-11ef-a056-525400220000'
239+
_cinfo_key = '_keep_container_info'
240+
241+
updater = _cephadm.CoreStatusUpdater(keep_container_info=_cinfo_key)
242+
d_id = _cephadm.DaemonIdentity(
243+
fsid = fsid,
244+
daemon_type = 'mon',
245+
daemon_id = 'host1',
246+
)
247+
val = {}
248+
with with_cephadm_ctx([], mock_cephadm_call_fn=False) as ctx:
249+
updater.update(val, ctx, d_id, f'/var/lib/ceph/{fsid}')
250+
assert _cinfo_key in val
251+
assert val[_cinfo_key] is None
252+
253+
232254
def test_list_daemons_detail_mgrnotrunning(cephadm_fs, funkypatch):
233255
_cephadm = import_cephadm()
234256
_call = funkypatch.patch('cephadmlib.call_wrappers.call')

0 commit comments

Comments
 (0)