From 8f459ad3db46444d3eae99867d35dd64b2e21ce0 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 21 Sep 2023 16:21:25 -0400 Subject: cephadm: add test_daemon_form.py Signed-off-by: John Mulligan --- src/cephadm/tests/test_daemon_form.py | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/cephadm/tests/test_daemon_form.py diff --git a/src/cephadm/tests/test_daemon_form.py b/src/cephadm/tests/test_daemon_form.py new file mode 100644 index 00000000000..428183aaa3e --- /dev/null +++ b/src/cephadm/tests/test_daemon_form.py @@ -0,0 +1,86 @@ +from unittest import mock + +import pytest + +from .fixtures import import_cephadm + +from cephadmlib import daemon_form +from cephadmlib import daemon_identity + +_cephadm = import_cephadm() + + +@pytest.mark.parametrize( + 'daemon_type,cls', + [ + ('container', _cephadm.CustomContainer), + ('grafana', _cephadm.Monitoring), + ('iscsi', _cephadm.CephIscsi), + ('jaeger-agent', _cephadm.Tracing), + ('jaeger-query', _cephadm.Tracing), + ('mds', _cephadm.Ceph), + ('mon', _cephadm.Ceph), + ('nfs', _cephadm.NFSGanesha), + ('nvmeof', _cephadm.CephNvmeof), + ('osd', _cephadm.OSD), + ('prometheus', _cephadm.Monitoring), + ('snmp-gateway', _cephadm.SNMPGateway), + ], +) +def test_choose_daemon_form(daemon_type, cls): + daemon_form.choose(daemon_type) == cls + + +def test_choose_daemon_form_error(): + with pytest.raises(daemon_form.UnexpectedDaemonTypeError): + daemon_form.choose('__nope__nope__') + + +@pytest.mark.parametrize( + 'dt,is_sdf', + [ + ('haproxy', True), + ('iscsi', False), + ('keepalived', True), + ('mon', False), + ('nfs', False), + ('nvmeof', True), + ('osd', True), + ], +) +def test_is_sysctl_daemon_form(dt, is_sdf): + uuid = 'daeb985e-58c7-11ee-a536-201e8814f771' + ctx = mock.MagicMock() + ctx.config_blobs = { + 'files': _dmock(), + 'pool': 'swimming', + 'destination': 'earth', + } + ident = daemon_identity.DaemonIdentity(uuid, dt, 'abc') + inst = daemon_form.create(ctx, ident) + assert isinstance(inst, daemon_form.SysctlDaemonForm) == is_sdf + + +def test_can_create_all_daemon_forms(): + uuid = 'daeb985e-58c7-11ee-a536-201e8814f771' + ctx = mock.MagicMock() + ctx.config_blobs = { + 'files': _dmock(), + 'pool': 'swimming', + 'destination': 'earth', + } + dtypes = _cephadm.get_supported_daemons() + for daemon_type in dtypes: + if daemon_type == 'agent': + # skip agent because it is special & not currently a daemonform + continue + ident = daemon_identity.DaemonIdentity(uuid, daemon_type, 'xyz') + inst = daemon_form.create(ctx, ident) + assert inst.identity.daemon_type == daemon_type + + +def _dmock(): + dmock = mock.MagicMock() + dmock.__contains__.return_value = True + dmock.__getitem__.return_value = '' + return dmock -- cgit v1.2.3