]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_services.py
0874c395eb551ed82cad4ca570f5128941dda4db
3 from unittest
.mock
import MagicMock
5 from cephadm
.services
.cephadmservice
import MonService
, MgrService
, MdsService
, RgwService
, \
6 RbdMirrorService
, CrashService
, CephadmService
, AuthEntity
7 from cephadm
.services
.iscsi
import IscsiService
8 from cephadm
.services
.nfs
import NFSService
9 from cephadm
.services
.osd
import RemoveUtil
, OSDRemovalQueue
, OSDService
, OSD
, NotFoundError
10 from cephadm
.services
.monitoring
import GrafanaService
, AlertmanagerService
, PrometheusService
, \
13 from orchestrator
import OrchestratorError
19 self
.check_mon_command
= MagicMock(side_effect
=self
._check
_mon
_command
)
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'
31 class TestCephadmService
:
32 def test_set_service_url_on_dashboard(self
):
33 # pylint: disable=protected-access
35 service_url
= 'http://svc:1000'
36 service
= GrafanaService(mgr
)
37 service
._set
_service
_url
_on
_dashboard
('svc', 'get-cmd', 'set-cmd', service_url
)
38 assert mgr
.config
== service_url
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'})
45 def _get_services(self
, mgr
):
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
)
66 'rbd-mirror': rbd_mirror_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
,
75 return cephadm_services
77 def test_get_auth_entity(self
):
79 cephadm_services
= self
._get
_services
(mgr
)
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")
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")
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")
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")
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")
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")