]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/mgr/dashboard/test_mgr_module.py
import 15.2.5
[ceph.git] / ceph / qa / tasks / mgr / dashboard / test_mgr_module.py
CommitLineData
11fdf7f2
TL
1# -*- coding: utf-8 -*-
2from __future__ import absolute_import
3
4import logging
5import requests
6
f6b5b4d7 7from .helper import DashboardTestCase, JAny, JObj, JList, JLeaf
11fdf7f2
TL
8
9logger = logging.getLogger(__name__)
10
11
12class 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
33class MgrModuleTest(MgrModuleTestCase):
f6b5b4d7
TL
34
35 __options_schema = JObj({
36 'name': str,
37 'type': str,
38 'level': str,
39 'flags': int,
40 'default_value': JAny(none=True),
41 'min': JAny(none=False),
42 'max': JAny(none=False),
43 'enum_allowed': JList(str),
44 'desc': str,
45 'long_desc': str,
46 'tags': JList(str),
47 'see_also': JList(str)
48 })
49
11fdf7f2 50 def test_list_disabled_module(self):
eafe8130 51 self._ceph_cmd(['mgr', 'module', 'disable', 'iostat'])
11fdf7f2
TL
52 self.wait_until_rest_api_accessible()
53 data = self._get('/api/mgr/module')
54 self.assertStatus(200)
55 self.assertSchema(
56 data,
57 JList(
58 JObj(sub_elems={
59 'name': JLeaf(str),
60 'enabled': JLeaf(bool),
92f5a8d4 61 'always_on': JLeaf(bool),
11fdf7f2
TL
62 'options': JObj(
63 {},
64 allow_unknown=True,
65 unknown_schema=JObj({
66 'name': str,
67 'type': str,
68 'level': str,
69 'flags': int,
f6b5b4d7 70 'default_value': JAny(none=True),
11fdf7f2
TL
71 'min': JAny(none=False),
72 'max': JAny(none=False),
73 'enum_allowed': JList(str),
74 'see_also': JList(str),
75 'desc': str,
76 'long_desc': str,
77 'tags': JList(str)
78 }))
79 })))
eafe8130 80 module_info = self.find_object_in_list('name', 'iostat', data)
11fdf7f2
TL
81 self.assertIsNotNone(module_info)
82 self.assertFalse(module_info['enabled'])
83
84 def test_list_enabled_module(self):
eafe8130 85 self._ceph_cmd(['mgr', 'module', 'enable', 'iostat'])
11fdf7f2
TL
86 self.wait_until_rest_api_accessible()
87 data = self._get('/api/mgr/module')
88 self.assertStatus(200)
89 self.assertSchema(
90 data,
91 JList(
92 JObj(sub_elems={
93 'name': JLeaf(str),
94 'enabled': JLeaf(bool),
92f5a8d4 95 'always_on': JLeaf(bool),
11fdf7f2
TL
96 'options': JObj(
97 {},
98 allow_unknown=True,
99 unknown_schema=JObj({
100 'name': str,
101 'type': str,
102 'level': str,
103 'flags': int,
f6b5b4d7 104 'default_value': JAny(none=True),
11fdf7f2
TL
105 'min': JAny(none=False),
106 'max': JAny(none=False),
107 'enum_allowed': JList(str),
108 'see_also': JList(str),
109 'desc': str,
110 'long_desc': str,
111 'tags': JList(str)
112 }))
113 })))
eafe8130 114 module_info = self.find_object_in_list('name', 'iostat', data)
11fdf7f2
TL
115 self.assertIsNotNone(module_info)
116 self.assertTrue(module_info['enabled'])
117
11fdf7f2
TL
118 def test_get(self):
119 data = self._get('/api/mgr/module/telemetry')
120 self.assertStatus(200)
121 self.assertSchema(
122 data,
123 JObj(
eafe8130 124 allow_unknown=True,
11fdf7f2 125 sub_elems={
eafe8130
TL
126 'channel_basic': bool,
127 'channel_ident': bool,
128 'channel_crash': bool,
129 'channel_device': bool,
130 'contact': str,
131 'description': str,
132 'enabled': bool,
133 'interval': int,
134 'last_opt_revision': int,
135 'leaderboard': bool,
136 'organization': str,
137 'proxy': str,
138 'url': str
11fdf7f2
TL
139 }))
140
f6b5b4d7
TL
141 def test_module_options(self):
142 data = self._get('/api/mgr/module/telemetry/options')
143 self.assertStatus(200)
144 schema = JObj({
145 'channel_basic': self.__options_schema,
146 'channel_crash': self.__options_schema,
147 'channel_device': self.__options_schema,
148 'channel_ident': self.__options_schema,
149 'contact': self.__options_schema,
150 'description': self.__options_schema,
151 'device_url': self.__options_schema,
152 'enabled': self.__options_schema,
153 'interval': self.__options_schema,
154 'last_opt_revision': self.__options_schema,
155 'leaderboard': self.__options_schema,
156 'log_level': self.__options_schema,
157 'log_to_cluster': self.__options_schema,
158 'log_to_cluster_level': self.__options_schema,
159 'log_to_file': self.__options_schema,
160 'organization': self.__options_schema,
161 'proxy': self.__options_schema,
162 'url': self.__options_schema
163 })
164 self.assertSchema(data, schema)
165
166 def test_module_enable(self):
167 self._post('/api/mgr/module/telemetry/enable')
168 self.assertStatus(200)
169
170 def test_disable(self):
171 self._post('/api/mgr/module/iostat/disable')
172 self.assertStatus(200)
173
11fdf7f2 174 def test_put(self):
f6b5b4d7
TL
175 self.set_config_key('config/mgr/mgr/iostat/log_level', 'critical')
176 self.set_config_key('config/mgr/mgr/iostat/log_to_cluster', 'False')
177 self.set_config_key('config/mgr/mgr/iostat/log_to_cluster_level', 'info')
178 self.set_config_key('config/mgr/mgr/iostat/log_to_file', 'True')
11fdf7f2 179 self._put(
f6b5b4d7 180 '/api/mgr/module/iostat',
11fdf7f2
TL
181 data={
182 'config': {
f6b5b4d7
TL
183 'log_level': 'debug',
184 'log_to_cluster': True,
185 'log_to_cluster_level': 'warning',
186 'log_to_file': False
11fdf7f2
TL
187 }
188 })
189 self.assertStatus(200)
f6b5b4d7 190 data = self._get('/api/mgr/module/iostat')
11fdf7f2 191 self.assertStatus(200)
f6b5b4d7
TL
192 self.assertEqual(data['log_level'], 'debug')
193 self.assertTrue(data['log_to_cluster'])
194 self.assertEqual(data['log_to_cluster_level'], 'warning')
195 self.assertFalse(data['log_to_file'])