]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import absolute_import | |
3 | ||
4 | import logging | |
5 | import requests | |
6 | ||
7 | from .helper import DashboardTestCase, JAny, JObj, JList, JLeaf | |
8 | ||
9 | logger = logging.getLogger(__name__) | |
10 | ||
11 | ||
12 | class MgrModuleTestCase(DashboardTestCase): | |
13 | MGRS_REQUIRED = 1 | |
14 | ||
11fdf7f2 TL |
15 | def wait_until_rest_api_accessible(self): |
16 | """ | |
17 | Wait until the REST API is accessible. | |
18 | """ | |
19 | ||
20 | def _check_connection(): | |
21 | try: | |
22 | # Try reaching an API endpoint successfully. | |
23 | self._get('/api/mgr/module') | |
24 | if self._resp.status_code == 200: | |
25 | return True | |
26 | except requests.ConnectionError: | |
27 | pass | |
28 | return False | |
29 | ||
30 | self.wait_until_true(_check_connection, timeout=30) | |
31 | ||
32 | ||
33 | class MgrModuleTest(MgrModuleTestCase): | |
34 | def test_list_disabled_module(self): | |
eafe8130 | 35 | self._ceph_cmd(['mgr', 'module', 'disable', 'iostat']) |
11fdf7f2 TL |
36 | self.wait_until_rest_api_accessible() |
37 | data = self._get('/api/mgr/module') | |
38 | self.assertStatus(200) | |
39 | self.assertSchema( | |
40 | data, | |
41 | JList( | |
42 | JObj(sub_elems={ | |
43 | 'name': JLeaf(str), | |
44 | 'enabled': JLeaf(bool), | |
45 | 'options': JObj( | |
46 | {}, | |
47 | allow_unknown=True, | |
48 | unknown_schema=JObj({ | |
49 | 'name': str, | |
50 | 'type': str, | |
51 | 'level': str, | |
52 | 'flags': int, | |
53 | 'default_value': JAny(none=False), | |
54 | 'min': JAny(none=False), | |
55 | 'max': JAny(none=False), | |
56 | 'enum_allowed': JList(str), | |
57 | 'see_also': JList(str), | |
58 | 'desc': str, | |
59 | 'long_desc': str, | |
60 | 'tags': JList(str) | |
61 | })) | |
62 | }))) | |
eafe8130 | 63 | module_info = self.find_object_in_list('name', 'iostat', data) |
11fdf7f2 TL |
64 | self.assertIsNotNone(module_info) |
65 | self.assertFalse(module_info['enabled']) | |
66 | ||
67 | def test_list_enabled_module(self): | |
eafe8130 | 68 | self._ceph_cmd(['mgr', 'module', 'enable', 'iostat']) |
11fdf7f2 TL |
69 | self.wait_until_rest_api_accessible() |
70 | data = self._get('/api/mgr/module') | |
71 | self.assertStatus(200) | |
72 | self.assertSchema( | |
73 | data, | |
74 | JList( | |
75 | JObj(sub_elems={ | |
76 | 'name': JLeaf(str), | |
77 | 'enabled': JLeaf(bool), | |
78 | 'options': JObj( | |
79 | {}, | |
80 | allow_unknown=True, | |
81 | unknown_schema=JObj({ | |
82 | 'name': str, | |
83 | 'type': str, | |
84 | 'level': str, | |
85 | 'flags': int, | |
86 | 'default_value': JAny(none=False), | |
87 | 'min': JAny(none=False), | |
88 | 'max': JAny(none=False), | |
89 | 'enum_allowed': JList(str), | |
90 | 'see_also': JList(str), | |
91 | 'desc': str, | |
92 | 'long_desc': str, | |
93 | 'tags': JList(str) | |
94 | })) | |
95 | }))) | |
eafe8130 | 96 | module_info = self.find_object_in_list('name', 'iostat', data) |
11fdf7f2 TL |
97 | self.assertIsNotNone(module_info) |
98 | self.assertTrue(module_info['enabled']) | |
99 | ||
100 | ||
101 | class MgrModuleTelemetryTest(MgrModuleTestCase): | |
102 | def test_get(self): | |
103 | data = self._get('/api/mgr/module/telemetry') | |
104 | self.assertStatus(200) | |
105 | self.assertSchema( | |
106 | data, | |
107 | JObj( | |
eafe8130 | 108 | allow_unknown=True, |
11fdf7f2 | 109 | sub_elems={ |
eafe8130 TL |
110 | 'channel_basic': bool, |
111 | 'channel_ident': bool, | |
112 | 'channel_crash': bool, | |
113 | 'channel_device': bool, | |
114 | 'contact': str, | |
115 | 'description': str, | |
116 | 'enabled': bool, | |
117 | 'interval': int, | |
118 | 'last_opt_revision': int, | |
119 | 'leaderboard': bool, | |
120 | 'organization': str, | |
121 | 'proxy': str, | |
122 | 'url': str | |
11fdf7f2 TL |
123 | })) |
124 | ||
125 | def test_put(self): | |
126 | self.set_config_key('config/mgr/mgr/telemetry/contact', '') | |
127 | self.set_config_key('config/mgr/mgr/telemetry/description', '') | |
128 | self.set_config_key('config/mgr/mgr/telemetry/enabled', 'True') | |
129 | self.set_config_key('config/mgr/mgr/telemetry/interval', '72') | |
130 | self.set_config_key('config/mgr/mgr/telemetry/leaderboard', 'False') | |
131 | self.set_config_key('config/mgr/mgr/telemetry/organization', '') | |
132 | self.set_config_key('config/mgr/mgr/telemetry/proxy', '') | |
133 | self.set_config_key('config/mgr/mgr/telemetry/url', '') | |
134 | self._put( | |
135 | '/api/mgr/module/telemetry', | |
136 | data={ | |
137 | 'config': { | |
138 | 'contact': 'tux@suse.com', | |
139 | 'description': 'test', | |
140 | 'enabled': False, | |
141 | 'interval': 4711, | |
142 | 'leaderboard': True, | |
143 | 'organization': 'SUSE Linux', | |
144 | 'proxy': 'foo', | |
145 | 'url': 'https://foo.bar/report' | |
146 | } | |
147 | }) | |
148 | self.assertStatus(200) | |
149 | data = self._get('/api/mgr/module/telemetry') | |
150 | self.assertStatus(200) | |
151 | self.assertEqual(data['contact'], 'tux@suse.com') | |
152 | self.assertEqual(data['description'], 'test') | |
153 | self.assertFalse(data['enabled']) | |
154 | self.assertEqual(data['interval'], 4711) | |
155 | self.assertTrue(data['leaderboard']) | |
156 | self.assertEqual(data['organization'], 'SUSE Linux') | |
157 | self.assertEqual(data['proxy'], 'foo') | |
158 | self.assertEqual(data['url'], 'https://foo.bar/report') |