From: Tatjana Dehler Date: Fri, 15 Feb 2019 15:55:20 +0000 (+0100) Subject: mgr/dashboard: check config option updatability also for bulk create X-Git-Tag: v14.1.0~62^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F26450%2Fhead;p=ceph.git mgr/dashboard: check config option updatability also for bulk create Fixes: https://tracker.ceph.com/issues/34528 Signed-off-by: Tatjana Dehler --- diff --git a/qa/tasks/mgr/dashboard/test_cluster_configuration.py b/qa/tasks/mgr/dashboard/test_cluster_configuration.py index 052c14bdeeaf..fd9298f56bcb 100644 --- a/qa/tasks/mgr/dashboard/test_cluster_configuration.py +++ b/qa/tasks/mgr/dashboard/test_cluster_configuration.py @@ -181,6 +181,54 @@ class ClusterConfigurationTest(DashboardTestCase): 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 = { + 'clog_to_syslog': {'section': 'global', 'value': 'true'}, # not updatable + 'clog_to_graylog': {'section': 'global', 'value': 'true'} # 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(): + result = self._wait_for_expected_get_result(self._get_config_by_name, config_name, + value) + self.assertEqual(result, value) + + def test_bulk_set_cant_update_at_runtime_partial(self): + config_options = { + 'clog_to_syslog': {'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( + 'clog_to_syslog')) + + # check if config option values are still the original ones + for config_name, value in orig_values.items(): + result = self._wait_for_expected_get_result(self._get_config_by_name, config_name, + value) + self.assertEqual(result, value) + def _validate_single(self, data): self.assertIn('name', data) self.assertIn('daemon_default', data) diff --git a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py index d6314024444c..fcf3f8191454 100644 --- a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py +++ b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py @@ -40,12 +40,7 @@ class ClusterConfiguration(RESTController): def create(self, name, value): # Check if config option is updateable at runtime - config_option = self._get_config_option(name) - if not config_option['can_update_at_runtime']: - raise DashboardException( - msg='Config option {} is not updatable at runtime'.format(name), - code='config_option_not_updatable_at_runtime', - component='cluster_configuration') + self._updateable_at_runtime([name]) # Update config option availSections = ['global', 'mon', 'mgr', 'osd', 'mds', 'client'] @@ -63,6 +58,8 @@ class ClusterConfiguration(RESTController): CephService.send_command('mon', 'config rm', who=section, name=name) def bulk_set(self, options): + self._updateable_at_runtime(options.keys()) + for name, value in options.items(): CephService.send_command('mon', 'config set', who=value['section'], name=name, value=str(value['value'])) @@ -73,3 +70,18 @@ class ClusterConfiguration(RESTController): return self._append_config_option_values([option])[0] raise cherrypy.HTTPError(404) + + def _updateable_at_runtime(self, config_option_names): + not_updateable = [] + + for name in config_option_names: + config_option = self._get_config_option(name) + if not config_option['can_update_at_runtime']: + not_updateable.append(name) + + if not_updateable: + raise DashboardException( + msg='Config option {} is/are not updatable at runtime'.format( + ', '.join(not_updateable)), + code='config_option_not_updatable_at_runtime', + component='cluster_configuration')