From 007a4972efb3f40c0345b8c2b541535586f12ebf Mon Sep 17 00:00:00 2001 From: Timothy Q Nguyen Date: Tue, 30 Dec 2025 11:03:34 -0800 Subject: [PATCH] cephadm/tests: updated test for crash daemon I added some monkeypatch attributes in order for the make check to succeed with the new crash daemon. This is necessary as the crash daemon will try to access uid and gid and create a directory, but in testing these don't exist and need to be substituted. Signed-off-by: Timothy Q Nguyen --- src/cephadm/cephadmlib/daemons/ceph.py | 19 +++++++++++++++---- src/cephadm/tests/test_daemon_form.py | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cephadm/cephadmlib/daemons/ceph.py b/src/cephadm/cephadmlib/daemons/ceph.py index a4b10487b37f..ed30715841c7 100644 --- a/src/cephadm/cephadmlib/daemons/ceph.py +++ b/src/cephadm/cephadmlib/daemons/ceph.py @@ -52,7 +52,10 @@ class Ceph(ContainerDaemonForm): @classmethod def for_daemon_type(cls, daemon_type: str) -> bool: # TODO: figure out a way to un-special-case osd - return daemon_type in cls._daemons and daemon_type not in ('osd', 'crash') + return daemon_type in cls._daemons and daemon_type not in ( + 'osd', + 'crash', + ) def __init__(self, ctx: CephadmContext, ident: DaemonIdentity) -> None: self.ctx = ctx @@ -335,6 +338,7 @@ class OSD(Ceph): def osd_fsid(self) -> Optional[str]: return self._osd_fsid + @register_daemon_form class Crash(Ceph): @classmethod @@ -352,11 +356,18 @@ class Crash(Ceph): def create(cls, ctx: CephadmContext, ident: DaemonIdentity) -> 'Ceph': (uid, gid) = extract_uid_gid(ctx) data_dir_base = f'{ctx.data_dir}/{ident.fsid}' - makedirs(os.path.join(data_dir_base, 'crash'), uid, gid, DATA_DIR_MODE) - makedirs(os.path.join(data_dir_base, 'crash', 'posted'), uid, gid, - DATA_DIR_MODE) + makedirs( + os.path.join(data_dir_base, 'crash'), uid, gid, DATA_DIR_MODE + ) + makedirs( + os.path.join(data_dir_base, 'crash', 'posted'), + uid, + gid, + DATA_DIR_MODE, + ) return cls(ctx, ident) + @register_daemon_form class CephExporter(ContainerDaemonForm): """Defines a Ceph exporter container""" diff --git a/src/cephadm/tests/test_daemon_form.py b/src/cephadm/tests/test_daemon_form.py index a2d1773f1c84..0a929e31f4bc 100644 --- a/src/cephadm/tests/test_daemon_form.py +++ b/src/cephadm/tests/test_daemon_form.py @@ -72,6 +72,9 @@ def test_can_create_all_daemon_forms(monkeypatch): } _os_path_isdir = mock.MagicMock(return_value=True) monkeypatch.setattr('os.path.isdir', _os_path_isdir) + monkeypatch.setattr('cephadmlib.daemons.ceph.extract_uid_gid', + lambda ctx: (167, 167)) + monkeypatch.setattr('os.chown', lambda *args, **kwargs: None) dtypes = _cephadm.get_supported_daemons() for daemon_type in dtypes: if daemon_type == 'agent': -- 2.47.3