summaryrefslogtreecommitdiffstats
path: root/qa/tasks/mgr/dashboard/test_cluster_configuration.py
blob: 9c8245d238d1f26a2f142ba9f09d1c4fcbfe79d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
from __future__ import absolute_import

from .helper import DashboardTestCase


class ClusterConfigurationTest(DashboardTestCase):

    def test_list(self):
        data = self._get('/api/cluster_conf')
        self.assertStatus(200)
        self.assertIsInstance(data, list)
        self.assertGreater(len(data), 1000)
        for conf in data:
            self._validate_single(conf)

    def test_get(self):
        data = self._get('/api/cluster_conf/admin_socket')
        self.assertStatus(200)
        self._validate_single(data)
        self.assertIn('enum_values', data)

        data = self._get('/api/cluster_conf/fantasy_name')
        self.assertStatus(404)

    def test_get_specific_db_config_option(self):
        config_name = 'mon_allow_pool_delete'

        orig_value = self._get_config_by_name(config_name)

        self._ceph_cmd(['config', 'set', 'mon', config_name, 'true'])
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            [{'section': 'mon', 'value': 'true'}],
            timeout=30,
            period=1)

        self._ceph_cmd(['config', 'set', 'mon', config_name, 'false'])
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            [{'section': 'mon', 'value': 'false'}],
            timeout=30,
            period=1)

        # restore value
        if orig_value:
            self._ceph_cmd(['config', 'set', 'mon', config_name, orig_value[0]['value']])

    def test_filter_config_options(self):
        config_names = ['osd_scrub_during_recovery', 'osd_scrub_begin_hour', 'osd_scrub_end_hour']
        data = self._get('/api/cluster_conf/filter?names={}'.format(','.join(config_names)))
        self.assertStatus(200)
        self.assertIsInstance(data, list)
        self.assertEqual(len(data), 3)
        for conf in data:
            self._validate_single(conf)
            self.assertIn(conf['name'], config_names)

    def test_filter_config_options_empty_names(self):
        self._get('/api/cluster_conf/filter?names=')
        self.assertStatus(404)
        self.assertEqual(self._resp.json()['detail'], 'Config options `` not found')

    def test_filter_config_options_unknown_name(self):
        self._get('/api/cluster_conf/filter?names=abc')
        self.assertStatus(404)
        self.assertEqual(self._resp.json()['detail'], 'Config options `abc` not found')

    def test_filter_config_options_contains_unknown_name(self):
        config_names = ['osd_scrub_during_recovery', 'osd_scrub_begin_hour', 'abc']
        data = self._get('/api/cluster_conf/filter?names={}'.format(','.join(config_names)))
        self.assertStatus(200)
        self.assertIsInstance(data, list)
        self.assertEqual(len(data), 2)
        for conf in data:
            self._validate_single(conf)
            self.assertIn(conf['name'], config_names)

    def test_create(self):
        config_name = 'debug_ms'
        orig_value = self._get_config_by_name(config_name)

        # remove all existing settings for equal preconditions
        self._clear_all_values_for_config_option(config_name)

        expected_result = [{'section': 'mon', 'value': '0/3'}]

        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': expected_result
        })
        self.assertStatus(201)
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            expected_result,
            timeout=30,
            period=1)

        # reset original value
        self._clear_all_values_for_config_option(config_name)
        self._reset_original_values(config_name, orig_value)

    def test_delete(self):
        config_name = 'debug_ms'
        orig_value = self._get_config_by_name(config_name)

        # set a config option
        expected_result = [{'section': 'mon', 'value': '0/3'}]
        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': expected_result
        })
        self.assertStatus(201)
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            expected_result,
            timeout=30,
            period=1)

        # delete it and check if it's deleted
        self._delete('/api/cluster_conf/{}?section={}'.format(config_name, 'mon'))
        self.assertStatus(204)
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            None,
            timeout=30,
            period=1)

        # reset original value
        self._clear_all_values_for_config_option(config_name)
        self._reset_original_values(config_name, orig_value)

    def test_create_cant_update_at_runtime(self):
        config_name = 'public_bind_addr'  # not updatable
        config_value = [{'section': 'global', 'value': 'true'}]
        orig_value = self._get_config_by_name(config_name)

        # try to set config option and check if it fails
        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': config_value
        })
        self.assertStatus(400)
        self.assertError(code='config_option_not_updatable_at_runtime',
                         component='cluster_configuration',
                         detail='Config option {} is/are not updatable at runtime'.format(
                             config_name))

        # check if config option value is still the original one
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            orig_value,
            timeout=30,
            period=1)

    def test_create_two_values(self):
        config_name = 'debug_ms'
        orig_value = self._get_config_by_name(config_name)

        # remove all existing settings for equal preconditions
        self._clear_all_values_for_config_option(config_name)

        expected_result = [{'section': 'mon', 'value': '0/3'},
                           {'section': 'osd', 'value': '0/5'}]

        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': expected_result
        })
        self.assertStatus(201)
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            expected_result,
            timeout=30,
            period=1)

        # reset original value
        self._clear_all_values_for_config_option(config_name)
        self._reset_original_values(config_name, orig_value)

    def test_create_can_handle_none_values(self):
        config_name = 'debug_ms'
        orig_value = self._get_config_by_name(config_name)

        # remove all existing settings for equal preconditions
        self._clear_all_values_for_config_option(config_name)

        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': [{'section': 'mon', 'value': '0/3'},
                      {'section': 'osd', 'value': None}]
        })
        self.assertStatus(201)

        expected_result = [{'section': 'mon', 'value': '0/3'}]
        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            expected_result,
            timeout=30,
            period=1)

        # reset original value
        self._clear_all_values_for_config_option(config_name)
        self._reset_original_values(config_name, orig_value)

    def test_create_can_handle_boolean_values(self):
        config_name = 'mon_allow_pool_delete'
        orig_value = self._get_config_by_name(config_name)

        # remove all existing settings for equal preconditions
        self._clear_all_values_for_config_option(config_name)

        expected_result = [{'section': 'mon', 'value': 'true'}]

        self._post('/api/cluster_conf', {
            'name': config_name,
            'value': [{'section': 'mon', 'value': True}]})
        self.assertStatus(201)

        self.wait_until_equal(
            lambda: self._get_config_by_name(config_name),
            expected_result,
            timeout=30,
            period=1)

        # reset original value
        self._clear_all_values_for_config_option(config_name)
        self._reset_original_values(config_name, orig_value)

    def test_bulk_set(self):
        expected_result = {
            'osd_max_backfills': {'section': 'osd', 'value': '1'},
            'osd_recovery_max_active': {'section': 'osd', 'value': '3'},
            'osd_recovery_max_single_start': {'section': 'osd', 'value': '1'},
            'osd_recovery_sleep': {'section': 'osd', 'value': '2.000000'}
        }
        orig_values = dict()

        for config_name in expected_result:
            orig_values[config_name] = self._get_config_by_name(config_name)

            # remove all existing settings for equal preconditions
            self._clear_all_values_for_config_option(config_name)

        self._put('/api/cluster_conf', {'options': expected_result})
        self.assertStatus(200)

        for config_name, value in expected_result.items():
            self.wait_until_equal(
                lambda: self._get_config_by_name(config_name),
                [value],
                timeout=30,
                period=1)

            # reset original value
            self._clear_all_values_for_config_option(config_name)
            self._reset_original_values(config_name, orig_values[config_name])

    def test_bulk_set_cant_update_at_runtime(self):
        config_options = {
            'public_bind_addr': {'section': 'global', 'value': '1.2.3.4:567'},  # not updatable
            'public_network': {'section': 'global', 'value': '10.0.0.0/8'}  # not updatable
        }
        orig_values = dict()

        for config_name in config_options:
            orig_values[config_name] = self._get_config_by_name(config_name)

        # try to set config options and see if it fails
        self._put('/api/cluster_conf', {'options': config_options})
        self.assertStatus(400)
        self.assertError(code='config_option_not_updatable_at_runtime',
                         component='cluster_configuration',
                         detail='Config option {} is/are not updatable at runtime'.format(
                             ', '.join(config_options.keys())))

        # check if config option values are still the original ones
        for config_name, value in orig_values.items():
            self.wait_until_equal(
                lambda: self._get_config_by_name(config_name),
                value,
                timeout=30,
                period=1)

    def test_bulk_set_cant_update_at_runtime_partial(self):
        config_options = {
            'public_bind_addr': {'section': 'global', 'value': 'true'},  # not updatable
            'log_to_stderr': {'section': 'global', 'value': 'true'}  # updatable
        }
        orig_values = dict()

        for config_name in config_options:
            orig_values[config_name] = self._get_config_by_name(config_name)

        # try to set config options and see if it fails
        self._put('/api/cluster_conf', {'options': config_options})
        self.assertStatus(400)
        self.assertError(code='config_option_not_updatable_at_runtime',
                         component='cluster_configuration',
                         detail='Config option {} is/are not updatable at runtime'.format(
                             'public_bind_addr'))

        # check if config option values are still the original ones
        for config_name, value in orig_values.items():
            self.wait_until_equal(
                lambda: self._get_config_by_name(config_name),
                value,
                timeout=30,
                period=1)

    def test_check_existence(self):
        """
        This test case is intended to check the existence of all hard coded config options used by
        the dashboard.
        If you include further hard coded options in the dashboard, feel free to add them to the
        list.
        """
        hard_coded_options = [
            'osd_max_backfills',  # osd-recv-speed
            'osd_recovery_max_active',  # osd-recv-speed
            'osd_recovery_max_single_start',  # osd-recv-speed
            'osd_recovery_sleep',  # osd-recv-speed
            'osd_scrub_during_recovery',  # osd-pg-scrub
            'osd_scrub_begin_hour',  # osd-pg-scrub
            'osd_scrub_end_hour',  # osd-pg-scrub
            'osd_scrub_begin_week_day',  # osd-pg-scrub
            'osd_scrub_end_week_day',  # osd-pg-scrub
            'osd_scrub_min_interval',  # osd-pg-scrub
            'osd_scrub_max_interval',  # osd-pg-scrub
            'osd_deep_scrub_interval',  # osd-pg-scrub
            'osd_scrub_auto_repair',  # osd-pg-scrub
            'osd_max_scrubs',  # osd-pg-scrub
            'osd_scrub_priority',  # osd-pg-scrub
            'osd_scrub_sleep',  # osd-pg-scrub
            'osd_scrub_auto_repair_num_errors',  # osd-pg-scrub
            'osd_debug_deep_scrub_sleep',  # osd-pg-scrub
            'osd_deep_scrub_keys',  # osd-pg-scrub
            'osd_deep_scrub_large_omap_object_key_threshold',  # osd-pg-scrub
            'osd_deep_scrub_large_omap_object_value_sum_threshold',  # osd-pg-scrub
            'osd_deep_scrub_randomize_ratio',  # osd-pg-scrub
            'osd_deep_scrub_stride',  # osd-pg-scrub
            'osd_deep_scrub_update_digest_min_age',  # osd-pg-scrub
            'osd_requested_scrub_priority',  # osd-pg-scrub
            'osd_scrub_backoff_ratio',  # osd-pg-scrub
            'osd_scrub_chunk_max',  # osd-pg-scrub
            'osd_scrub_chunk_min',  # osd-pg-scrub
            'osd_scrub_cost',  # osd-pg-scrub
            'osd_scrub_interval_randomize_ratio',  # osd-pg-scrub
            'osd_scrub_invalid_stats',  # osd-pg-scrub
            'osd_scrub_load_threshold',  # osd-pg-scrub
            'osd_scrub_max_preemptions',  # osd-pg-scrub
            'mon_allow_pool_delete'  # pool-list
        ]

        for config_option in hard_coded_options:
            self._get('/api/cluster_conf/{}'.format(config_option))
            self.assertStatus(200)

    def _validate_single(self, data):
        self.assertIn('name', data)
        self.assertIn('daemon_default', data)
        self.assertIn('long_desc', data)
        self.assertIn('level', data)
        self.assertIn('default', data)
        self.assertIn('see_also', data)
        self.assertIn('tags', data)
        self.assertIn('min', data)
        self.assertIn('max', data)
        self.assertIn('services', data)
        self.assertIn('type', data)
        self.assertIn('desc', data)
        self.assertIn(data['type'], ['str', 'bool', 'float', 'int', 'size', 'uint', 'addr',
                                     'addrvec', 'uuid', 'secs', 'millisecs'])

        if 'value' in data:
            self.assertIn('source', data)
            self.assertIsInstance(data['value'], list)

            for entry in data['value']:
                self.assertIsInstance(entry, dict)
                self.assertIn('section', entry)
                self.assertIn('value', entry)

    def _get_config_by_name(self, conf_name):
        data = self._get('/api/cluster_conf/{}'.format(conf_name))
        if 'value' in data:
            return data['value']
        return None

    def _clear_all_values_for_config_option(self, config_name):
        values = self._get_config_by_name(config_name)
        if values:
            for value in values:
                self._ceph_cmd(['config', 'rm', value['section'], config_name])

    def _reset_original_values(self, config_name, orig_values):
        if orig_values:
            for value in orig_values:
                self._ceph_cmd(['config', 'set', value['section'], config_name, value['value']])