From c2c78c62bd99d54b5a4f7277c82aa17860c9e6d2 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Fri, 12 Mar 2021 10:23:12 -0700 Subject: [PATCH] mgr/cephadm: add CEPHADM_STRAY_DAEMON unittest Fixes: https://tracker.ceph.com/issues/49573 Signed-off-by: Michael Fritch (cherry picked from commit 88dc55266958d77ffa1da34a3d20c039cb249ac5) --- src/pybind/mgr/cephadm/tests/test_cephadm.py | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index e6ec2ae243f23..599a106eb84f2 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -374,6 +374,86 @@ class TestCephadm(object): out = cephadm_module.osd_service.find_destroyed_osds() assert out == {'host1': ['0']} + @ pytest.mark.parametrize( + "ceph_services, cephadm_daemons, strays_expected", + # [ ([(daemon_type, daemon_id), ... ], [...], [...]), ... ] + [ + ( + [('mds', 'a'), ('osd', '0'), ('mgr', 'x')], + [], + [('mds', 'a'), ('osd', '0'), ('mgr', 'x')], + ), + ( + [('mds', 'a'), ('osd', '0'), ('mgr', 'x')], + [('mds', 'a'), ('osd', '0'), ('mgr', 'x')], + [], + ), + ( + [('mds', 'a'), ('osd', '0'), ('mgr', 'x')], + [('mds', 'a'), ('osd', '0')], + [('mgr', 'x')], + ), + # https://tracker.ceph.com/issues/49573 + ( + [('rgw-nfs', 'nfs.foo.host1-rgw')], + [], + [('nfs', 'foo.host1')], + ), + ( + [('rgw-nfs', 'nfs.foo.host1-rgw')], + [('nfs', 'foo.host1')], + [], + ), + ( + [], + [('nfs', 'foo.host1')], + [], + ), + ] + ) + def test_check_for_stray_daemons( + self, + cephadm_module, + ceph_services, + cephadm_daemons, + strays_expected + ): + # mock ceph service-map + services = [] + for service in ceph_services: + s = {'type': service[0], 'id': service[1]} + services.append(s) + ls = [{'hostname': 'host1', 'services': services}] + + with mock.patch.object(cephadm_module, 'list_servers', mock.MagicMock()) as list_servers: + list_servers.return_value = ls + list_servers.__iter__.side_effect = ls.__iter__ + + # populate cephadm daemon cache + dm = {} + for daemon_type, daemon_id in cephadm_daemons: + dd = DaemonDescription(daemon_type=daemon_type, daemon_id=daemon_id) + dm[dd.name()] = dd + cephadm_module.cache.update_host_daemons('host1', dm) + + # test + CephadmServe(cephadm_module)._check_for_strays() + + # verify + strays = cephadm_module.health_checks.get('CEPHADM_STRAY_DAEMON') + if not strays: + assert len(strays_expected) == 0 + else: + for dt, di in strays_expected: + name = '%s.%s' % (dt, di) + for detail in strays['detail']: + if name in detail: + strays['detail'].remove(detail) + break + assert name in detail + assert len(strays['detail']) == 0 + assert strays['count'] == len(strays_expected) + @mock.patch("cephadm.module.CephadmOrchestrator.mon_command") def test_find_destroyed_osds_cmd_failure(self, _mon_cmd, cephadm_module): _mon_cmd.return_value = (1, "", "fail_msg") -- 2.39.5