]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | from __future__ import absolute_import |
2 | ||
3 | import json | |
4 | import mock | |
5 | ||
6 | from . import ControllerTestCase | |
7 | from .. import mgr | |
8 | from ..controllers.summary import Summary | |
9 | from ..controllers.rbd_mirroring import RbdMirroringSummary | |
10 | ||
11 | ||
12 | mock_list_servers = [{ | |
13 | 'hostname': 'ceph-host', | |
14 | 'services': [{'id': 3, 'type': 'rbd-mirror'}] | |
15 | }] | |
16 | ||
17 | mock_get_metadata = { | |
18 | 'id': 1, | |
19 | 'instance_id': 3, | |
20 | 'ceph_version': 'ceph version 13.0.0-5719 mimic (dev)' | |
21 | } | |
22 | ||
23 | _status = { | |
24 | 1: { | |
25 | 'callouts': {}, | |
26 | 'image_local_count': 5, | |
27 | 'image_remote_count': 6, | |
28 | 'image_error_count': 7, | |
29 | 'image_warning_count': 8, | |
30 | 'name': 'pool_name' | |
31 | } | |
32 | } | |
33 | ||
34 | mock_get_daemon_status = { | |
35 | 'json': json.dumps(_status) | |
36 | } | |
37 | ||
38 | mock_osd_map = { | |
39 | 'pools': [{ | |
40 | 'pool_name': 'rbd', | |
41 | 'application_metadata': {'rbd'} | |
42 | }] | |
43 | } | |
44 | ||
45 | ||
46 | class RbdMirroringSummaryControllerTest(ControllerTestCase): | |
47 | ||
48 | @classmethod | |
49 | def setup_server(cls): | |
50 | mgr.list_servers.return_value = mock_list_servers | |
92f5a8d4 | 51 | mgr.get_metadata = mock.Mock(return_value=mock_get_metadata) |
11fdf7f2 TL |
52 | mgr.get_daemon_status.return_value = mock_get_daemon_status |
53 | mgr.get.side_effect = lambda key: { | |
54 | 'osd_map': mock_osd_map, | |
55 | 'health': {'json': '{"status": 1}'}, | |
56 | 'fs_map': {'filesystems': []}, | |
57 | 'mgr_map': { | |
58 | 'services': { | |
59 | 'dashboard': 'https://ceph.dev:11000/' | |
60 | }, | |
61 | } | |
62 | }[key] | |
63 | mgr.url_prefix = '' | |
64 | mgr.get_mgr_id.return_value = 0 | |
65 | mgr.have_mon_connection.return_value = True | |
66 | mgr.version = 'ceph version 13.1.0-534-g23d3751b89 ' \ | |
67 | '(23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) ' \ | |
68 | 'nautilus (dev)' | |
69 | ||
70 | # pylint: disable=protected-access | |
71 | RbdMirroringSummary._cp_config['tools.authenticate.on'] = False | |
72 | Summary._cp_config['tools.authenticate.on'] = False | |
73 | # pylint: enable=protected-access | |
74 | ||
75 | cls.setup_controllers([RbdMirroringSummary, Summary], '/test') | |
76 | ||
77 | @mock.patch('dashboard.controllers.rbd_mirroring.rbd') | |
78 | def test_default(self, rbd_mock): # pylint: disable=W0613 | |
79 | self._get('/test/api/block/mirroring/summary') | |
80 | result = self.jsonBody() | |
81 | self.assertStatus(200) | |
82 | self.assertEqual(result['status'], 0) | |
83 | for k in ['daemons', 'pools', 'image_error', 'image_syncing', 'image_ready']: | |
84 | self.assertIn(k, result['content_data']) | |
85 | ||
86 | @mock.patch('dashboard.controllers.BaseController._has_permissions') | |
87 | @mock.patch('dashboard.controllers.rbd_mirroring.rbd') | |
88 | def test_summary(self, rbd_mock, has_perms_mock): # pylint: disable=W0613 | |
89 | """We're also testing `summary`, as it also uses code from `rbd_mirroring.py`""" | |
90 | has_perms_mock.return_value = True | |
91 | self._get('/test/api/summary') | |
92 | self.assertStatus(200) | |
93 | ||
94 | summary = self.jsonBody()['rbd_mirroring'] | |
95 | self.assertEqual(summary, {'errors': 0, 'warnings': 1}) |