]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/cephadm/tests/test_services.py
Import ceph 15.2.8
[ceph.git] / ceph / src / pybind / mgr / cephadm / tests / test_services.py
CommitLineData
f91f0fd5
TL
1import pytest
2
e306af50
TL
3from unittest.mock import MagicMock
4
f91f0fd5
TL
5from cephadm.services.cephadmservice import MonService, MgrService, MdsService, RgwService, \
6 RbdMirrorService, CrashService, CephadmService, AuthEntity
7from cephadm.services.iscsi import IscsiService
8from cephadm.services.nfs import NFSService
9from cephadm.services.osd import RemoveUtil, OSDQueue, OSDService, OSD, NotFoundError
10from cephadm.services.monitoring import GrafanaService, AlertmanagerService, PrometheusService, \
11 NodeExporterService
12
13from orchestrator import OrchestratorError
e306af50
TL
14
15
16class FakeMgr:
17 def __init__(self):
18 self.config = ''
19 self.check_mon_command = MagicMock(side_effect=self._check_mon_command)
20
21 def _check_mon_command(self, cmd_dict):
22 prefix = cmd_dict.get('prefix')
23 if prefix == 'get-cmd':
24 return 0, self.config, ''
25 if prefix == 'set-cmd':
26 self.config = cmd_dict.get('value')
27 return 0, 'value set', ''
28 return -1, '', 'error'
29
30
31class TestCephadmService:
32 def test_set_service_url_on_dashboard(self):
33 # pylint: disable=protected-access
34 mgr = FakeMgr()
35 service_url = 'http://svc:1000'
f6b5b4d7 36 service = GrafanaService(mgr)
e306af50
TL
37 service._set_service_url_on_dashboard('svc', 'get-cmd', 'set-cmd', service_url)
38 assert mgr.config == service_url
39
40 # set-cmd should not be called if value doesn't change
41 mgr.check_mon_command.reset_mock()
42 service._set_service_url_on_dashboard('svc', 'get-cmd', 'set-cmd', service_url)
43 mgr.check_mon_command.assert_called_once_with({'prefix': 'get-cmd'})
f91f0fd5
TL
44
45 def _get_services(self, mgr):
46 # services:
47 osd_service = OSDService(mgr)
48 nfs_service = NFSService(mgr)
49 mon_service = MonService(mgr)
50 mgr_service = MgrService(mgr)
51 mds_service = MdsService(mgr)
52 rgw_service = RgwService(mgr)
53 rbd_mirror_service = RbdMirrorService(mgr)
54 grafana_service = GrafanaService(mgr)
55 alertmanager_service = AlertmanagerService(mgr)
56 prometheus_service = PrometheusService(mgr)
57 node_exporter_service = NodeExporterService(mgr)
58 crash_service = CrashService(mgr)
59 iscsi_service = IscsiService(mgr)
60 cephadm_services = {
61 'mon': mon_service,
62 'mgr': mgr_service,
63 'osd': osd_service,
64 'mds': mds_service,
65 'rgw': rgw_service,
66 'rbd-mirror': rbd_mirror_service,
67 'nfs': nfs_service,
68 'grafana': grafana_service,
69 'alertmanager': alertmanager_service,
70 'prometheus': prometheus_service,
71 'node-exporter': node_exporter_service,
72 'crash': crash_service,
73 'iscsi': iscsi_service,
74 }
75 return cephadm_services
76
77 def test_get_auth_entity(self):
78 mgr = FakeMgr()
79 cephadm_services = self._get_services(mgr)
80
81 for daemon_type in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]:
82 assert "client.%s.id1" % (daemon_type) == \
83 cephadm_services[daemon_type].get_auth_entity("id1", "host")
84 assert "client.%s.id1" % (daemon_type) == \
85 cephadm_services[daemon_type].get_auth_entity("id1", "")
86 assert "client.%s.id1" % (daemon_type) == \
87 cephadm_services[daemon_type].get_auth_entity("id1")
88
89 assert "client.crash.host" == \
90 cephadm_services["crash"].get_auth_entity("id1", "host")
91 with pytest.raises(OrchestratorError):
92 t = cephadm_services["crash"].get_auth_entity("id1", "")
93 t = cephadm_services["crash"].get_auth_entity("id1")
94
95 assert "mon." == cephadm_services["mon"].get_auth_entity("id1", "host")
96 assert "mon." == cephadm_services["mon"].get_auth_entity("id1", "")
97 assert "mon." == cephadm_services["mon"].get_auth_entity("id1")
98
99 assert "mgr.id1" == cephadm_services["mgr"].get_auth_entity("id1", "host")
100 assert "mgr.id1" == cephadm_services["mgr"].get_auth_entity("id1", "")
101 assert "mgr.id1" == cephadm_services["mgr"].get_auth_entity("id1")
102
103 for daemon_type in ["osd", "mds"]:
104 assert "%s.id1" % daemon_type == \
105 cephadm_services[daemon_type].get_auth_entity("id1", "host")
106 assert "%s.id1" % daemon_type == \
107 cephadm_services[daemon_type].get_auth_entity("id1", "")
108 assert "%s.id1" % daemon_type == \
109 cephadm_services[daemon_type].get_auth_entity("id1")
110
111 with pytest.raises(AttributeError):
112 for daemon_type in ['grafana', 'alertmanager', 'prometheus', 'node-exporter']:
113 cephadm_services[daemon_type].get_auth_entity("id1", "host")
114 cephadm_services[daemon_type].get_auth_entity("id1", "")
115 cephadm_services[daemon_type].get_auth_entity("id1")