]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/cephadm/tests/test_services.py
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / cephadm / tests / test_services.py
CommitLineData
e306af50
TL
1from unittest.mock import MagicMock
2
3from cephadm.services.cephadmservice import CephadmService
4
5
6class FakeMgr:
7 def __init__(self):
8 self.config = ''
9 self.check_mon_command = MagicMock(side_effect=self._check_mon_command)
10
11 def _check_mon_command(self, cmd_dict):
12 prefix = cmd_dict.get('prefix')
13 if prefix == 'get-cmd':
14 return 0, self.config, ''
15 if prefix == 'set-cmd':
16 self.config = cmd_dict.get('value')
17 return 0, 'value set', ''
18 return -1, '', 'error'
19
20
21class TestCephadmService:
22 def test_set_service_url_on_dashboard(self):
23 # pylint: disable=protected-access
24 mgr = FakeMgr()
25 service_url = 'http://svc:1000'
26 service = CephadmService(mgr)
27 service._set_service_url_on_dashboard('svc', 'get-cmd', 'set-cmd', service_url)
28 assert mgr.config == service_url
29
30 # set-cmd should not be called if value doesn't change
31 mgr.check_mon_command.reset_mock()
32 service._set_service_url_on_dashboard('svc', 'get-cmd', 'set-cmd', service_url)
33 mgr.check_mon_command.assert_called_once_with({'prefix': 'get-cmd'})