Fix getting config option value for database

Change-Id: If2d3022a59ba535e1361a3ba9bc9dd983ca25256
Story: 2009051
Task: 42821
This commit is contained in:
Lingxian Kong 2021-07-07 09:34:17 +12:00
parent 437d594e86
commit 69f08ab470
3 changed files with 12 additions and 5 deletions

View File

@ -104,12 +104,15 @@ class ConfigurationManager(object):
self._override_strategy.configure(
base_config_path, owner, group, codec, requires_root)
def get_value(self, key, default=None):
def get_value(self, key, section=None, default=None):
"""Return the current value at a given key or 'default'.
"""
if self._value_cache is None:
self.refresh_cache()
if section:
return self._value_cache.get(section, {}).get(key, default)
return self._value_cache.get(key, default)
def parse_configuration(self):
@ -417,6 +420,7 @@ class ImportOverrideStrategy(ConfigurationOverrideStrategy):
as_root=self._requires_root)
guestagent_utils.update_dict(options, parsed_options)
LOG.debug(f"Parsed overrides options: {parsed_options}")
return parsed_options
@property

View File

@ -173,11 +173,14 @@ class MySqlManager(manager.Manager):
def is_log_enabled(self, logname):
if logname == self.GUEST_LOG_DEFS_GENERAL_LABEL:
value = self.configuration_manager.get_value('general_log', 'off')
value = self.configuration_manager.get_value(
'general_log', section='mysqld', default='off')
LOG.debug(f"The config value of general_log is {value}")
return value == 'on'
elif logname == self.GUEST_LOG_DEFS_SLOW_QUERY_LABEL:
value = self.configuration_manager.get_value('slow_query_log',
'off')
value = self.configuration_manager.get_value(
'slow_query_log', section='mysqld', default='off')
LOG.debug(f"The config value of slow_query_log is {value}")
return value == 'on'
return False

View File

@ -463,7 +463,7 @@ class BaseMySqlApp(service.BaseDbApp):
@classmethod
def get_data_dir(cls):
return cls.configuration_manager.get_value(
MySQLConfParser.SERVER_CONF_SECTION).get('datadir')
'datadir', section=MySQLConfParser.SERVER_CONF_SECTION)
@classmethod
def set_data_dir(cls, value):