]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_host.py
6 from unittest
import mock
8 from orchestrator
import HostSpec
10 from . import ControllerTestCase
11 from ..controllers
.host
import get_hosts
, Host
15 class HostControllerTest(ControllerTestCase
):
16 URL_HOST
= '/api/host'
19 def setup_server(cls
):
20 # pylint: disable=protected-access
21 Host
._cp
_config
['tools.authenticate.on'] = False
22 cls
.setup_controllers([Host
])
24 @mock.patch('dashboard.controllers.host.get_hosts')
25 def test_host_list(self
, mock_get_hosts
):
30 'ceph': True, 'orchestrator': False
36 'ceph': False, 'orchestrator': True
42 'ceph': True, 'orchestrator': True
47 def _get_hosts(from_ceph
=True, from_orchestrator
=True):
50 _hosts
.append(hosts
[0])
52 _hosts
.append(hosts
[1])
53 _hosts
.append(hosts
[2])
55 mock_get_hosts
.side_effect
= _get_hosts
57 self
._get
(self
.URL_HOST
)
58 self
.assertStatus(200)
59 self
.assertJsonBody(hosts
)
61 self
._get
('{}?sources=ceph'.format(self
.URL_HOST
))
62 self
.assertStatus(200)
63 self
.assertJsonBody([hosts
[0]])
65 self
._get
('{}?sources=orchestrator'.format(self
.URL_HOST
))
66 self
.assertStatus(200)
67 self
.assertJsonBody(hosts
[1:])
69 self
._get
('{}?sources=ceph,orchestrator'.format(self
.URL_HOST
))
70 self
.assertStatus(200)
71 self
.assertJsonBody(hosts
)
74 class TestHosts(unittest
.TestCase
):
76 @mock.patch('dashboard.controllers.orchestrator.OrchClient.instance')
77 def test_get_hosts(self
, instance
):
78 mgr
.list_servers
.return_value
= [{'hostname': 'node1'}, {'hostname': 'localhost'}]
80 fake_client
= mock
.Mock()
81 fake_client
.available
.return_value
= True
82 fake_client
.hosts
.list.return_value
= [
83 HostSpec('node1'), HostSpec('node2')]
84 instance
.return_value
= fake_client
87 self
.assertEqual(len(hosts
), 3)
89 'localhost': {'ceph': True, 'orchestrator': False},
90 'node1': {'ceph': True, 'orchestrator': True},
91 'node2': {'ceph': False, 'orchestrator': True}
94 hostname
= host
['hostname']
95 sources
= host
['sources']
96 self
.assertDictEqual(sources
, check_sources
[hostname
])