]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/dashboard/test_mgr_module.py
0766bfd2b467acd6bdf64a97d7dafbc8a1b871a6
[ceph.git] / ceph / qa / tasks / mgr / dashboard / test_mgr_module.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import logging
5
6 import requests
7
8 from .helper import (DashboardTestCase, JLeaf, JList, JObj,
9 module_options_object_schema, module_options_schema)
10
11 logger = logging.getLogger(__name__)
12
13
14 class MgrModuleTestCase(DashboardTestCase):
15 MGRS_REQUIRED = 1
16
17 def wait_until_rest_api_accessible(self):
18 """
19 Wait until the REST API is accessible.
20 """
21
22 def _check_connection():
23 try:
24 # Try reaching an API endpoint successfully.
25 self._get('/api/mgr/module')
26 if self._resp.status_code == 200:
27 return True
28 except requests.ConnectionError:
29 pass
30 return False
31
32 self.wait_until_true(_check_connection, timeout=30)
33
34
35 class MgrModuleTest(MgrModuleTestCase):
36
37 def test_list_disabled_module(self):
38 self._ceph_cmd(['mgr', 'module', 'disable', 'iostat'])
39 self.wait_until_rest_api_accessible()
40 data = self._get('/api/mgr/module')
41 self.assertStatus(200)
42 self.assertSchema(
43 data,
44 JList(
45 JObj(sub_elems={
46 'name': JLeaf(str),
47 'enabled': JLeaf(bool),
48 'always_on': JLeaf(bool),
49 'options': module_options_schema
50 })))
51 module_info = self.find_object_in_list('name', 'iostat', data)
52 self.assertIsNotNone(module_info)
53 self.assertFalse(module_info['enabled'])
54
55 def test_list_enabled_module(self):
56 self._ceph_cmd(['mgr', 'module', 'enable', 'iostat'])
57 self.wait_until_rest_api_accessible()
58 data = self._get('/api/mgr/module')
59 self.assertStatus(200)
60 self.assertSchema(
61 data,
62 JList(
63 JObj(sub_elems={
64 'name': JLeaf(str),
65 'enabled': JLeaf(bool),
66 'always_on': JLeaf(bool),
67 'options': module_options_schema
68 })))
69 module_info = self.find_object_in_list('name', 'iostat', data)
70 self.assertIsNotNone(module_info)
71 self.assertTrue(module_info['enabled'])
72
73 def test_get(self):
74 data = self._get('/api/mgr/module/telemetry')
75 self.assertStatus(200)
76 self.assertSchema(
77 data,
78 JObj(
79 allow_unknown=True,
80 sub_elems={
81 'channel_basic': bool,
82 'channel_ident': bool,
83 'channel_crash': bool,
84 'channel_device': bool,
85 'channel_perf': bool,
86 'contact': str,
87 'description': str,
88 'enabled': bool,
89 'interval': int,
90 'last_opt_revision': int,
91 'leaderboard': bool,
92 'organization': str,
93 'proxy': str,
94 'url': str
95 }))
96
97 def test_module_options(self):
98 data = self._get('/api/mgr/module/telemetry/options')
99 self.assertStatus(200)
100 schema = JObj({
101 'channel_basic': module_options_object_schema,
102 'channel_crash': module_options_object_schema,
103 'channel_device': module_options_object_schema,
104 'channel_ident': module_options_object_schema,
105 'channel_perf': module_options_object_schema,
106 'contact': module_options_object_schema,
107 'description': module_options_object_schema,
108 'device_url': module_options_object_schema,
109 'enabled': module_options_object_schema,
110 'interval': module_options_object_schema,
111 'last_opt_revision': module_options_object_schema,
112 'leaderboard': module_options_object_schema,
113 'log_level': module_options_object_schema,
114 'log_to_cluster': module_options_object_schema,
115 'log_to_cluster_level': module_options_object_schema,
116 'log_to_file': module_options_object_schema,
117 'organization': module_options_object_schema,
118 'proxy': module_options_object_schema,
119 'url': module_options_object_schema
120 })
121 self.assertSchema(data, schema)
122
123 def test_module_enable(self):
124 self._post('/api/mgr/module/telemetry/enable')
125 self.assertStatus(200)
126
127 def test_disable(self):
128 self._post('/api/mgr/module/iostat/disable')
129 self.assertStatus(200)
130
131 def test_put(self):
132 self.set_config_key('config/mgr/mgr/iostat/log_level', 'critical')
133 self.set_config_key('config/mgr/mgr/iostat/log_to_cluster', 'False')
134 self.set_config_key('config/mgr/mgr/iostat/log_to_cluster_level', 'info')
135 self.set_config_key('config/mgr/mgr/iostat/log_to_file', 'True')
136 self._put(
137 '/api/mgr/module/iostat',
138 data={
139 'config': {
140 'log_level': 'debug',
141 'log_to_cluster': True,
142 'log_to_cluster_level': 'warning',
143 'log_to_file': False
144 }
145 })
146 self.assertStatus(200)
147 data = self._get('/api/mgr/module/iostat')
148 self.assertStatus(200)
149 self.assertEqual(data['log_level'], 'debug')
150 self.assertTrue(data['log_to_cluster'])
151 self.assertEqual(data['log_to_cluster_level'], 'warning')
152 self.assertFalse(data['log_to_file'])