1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
8 from .helper
import (DashboardTestCase
, JLeaf
, JList
, JObj
,
9 module_options_object_schema
, module_options_schema
)
11 logger
= logging
.getLogger(__name__
)
14 class MgrModuleTestCase(DashboardTestCase
):
17 def wait_until_rest_api_accessible(self
):
19 Wait until the REST API is accessible.
22 def _check_connection():
24 # Try reaching an API endpoint successfully.
25 self
._get
('/api/mgr/module')
26 if self
._resp
.status_code
== 200:
28 except requests
.ConnectionError
:
32 self
.wait_until_true(_check_connection
, timeout
=30)
35 class MgrModuleTest(MgrModuleTestCase
):
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)
47 'enabled': JLeaf(bool),
48 'always_on': JLeaf(bool),
49 'options': module_options_schema
51 module_info
= self
.find_object_in_list('name', 'iostat', data
)
52 self
.assertIsNotNone(module_info
)
53 self
.assertFalse(module_info
['enabled'])
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)
65 'enabled': JLeaf(bool),
66 'always_on': JLeaf(bool),
67 'options': module_options_schema
69 module_info
= self
.find_object_in_list('name', 'iostat', data
)
70 self
.assertIsNotNone(module_info
)
71 self
.assertTrue(module_info
['enabled'])
74 data
= self
._get
('/api/mgr/module/telemetry')
75 self
.assertStatus(200)
81 'channel_basic': bool,
82 'channel_ident': bool,
83 'channel_crash': bool,
84 'channel_device': bool,
90 'last_opt_revision': int,
97 def test_module_options(self
):
98 data
= self
._get
('/api/mgr/module/telemetry/options')
99 self
.assertStatus(200)
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
121 self
.assertSchema(data
, schema
)
123 def test_module_enable(self
):
124 self
._post
('/api/mgr/module/telemetry/enable')
125 self
.assertStatus(200)
127 def test_disable(self
):
128 self
._post
('/api/mgr/module/iostat/disable')
129 self
.assertStatus(200)
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')
137 '/api/mgr/module/iostat',
140 'log_level': 'debug',
141 'log_to_cluster': True,
142 'log_to_cluster_level': 'warning',
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'])