]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add test_daemon_form.py
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 21 Sep 2023 20:21:25 +0000 (16:21 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 4 Oct 2023 19:17:57 +0000 (15:17 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/tests/test_daemon_form.py [new file with mode: 0644]

diff --git a/src/cephadm/tests/test_daemon_form.py b/src/cephadm/tests/test_daemon_form.py
new file mode 100644 (file)
index 0000000..428183a
--- /dev/null
@@ -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