Fix determining save_output_streams value through configuration

This commit is contained in:
Darko Poljak 2018-03-01 20:00:54 +01:00
parent 23292e5cad
commit 2dfbd89c5e
3 changed files with 21 additions and 6 deletions

View file

@ -78,6 +78,9 @@ class OptionBase:
else: else:
return newval return newval
def should_override(self, currval, newval):
return True
class StringOption(OptionBase): class StringOption(OptionBase):
def __init__(self, name): def __init__(self, name):
@ -98,8 +101,12 @@ class StringOption(OptionBase):
class BooleanOption(OptionBase): class BooleanOption(OptionBase):
BOOLEAN_STATES = configparser.ConfigParser.BOOLEAN_STATES BOOLEAN_STATES = configparser.ConfigParser.BOOLEAN_STATES
def __init__(self, name): # If default_overrides is False then previous config value will not be
# overriden with default_value.
def __init__(self, name, default_overrides=True, default_value=True):
super().__init__(name) super().__init__(name)
self.default_overrides = default_overrides
self.default_value = default_value
def get_converter(self): def get_converter(self):
def boolean_converter(val): def boolean_converter(val):
@ -113,6 +120,11 @@ class BooleanOption(OptionBase):
def translate(self, val): def translate(self, val):
return self.BOOLEAN_STATES[val] return self.BOOLEAN_STATES[val]
def should_override(self, currval, newval):
if not self.default_overrides:
return newval != self.default_value
return True
class IntOption(OptionBase): class IntOption(OptionBase):
def __init__(self, name): def __init__(self, name):
@ -286,7 +298,8 @@ class Configuration(metaclass=Singleton):
'parallel': JobsOption('parallel'), 'parallel': JobsOption('parallel'),
'verbosity': VerbosityOption(), 'verbosity': VerbosityOption(),
'archiving': ArchivingOption(), 'archiving': ArchivingOption(),
'save_output_streams': BooleanOption('save_output_streams'), 'save_output_streams': BooleanOption('save_output_streams',
default_overrides=False),
}, },
} }
@ -434,6 +447,7 @@ class Configuration(metaclass=Singleton):
else: else:
currval = None currval = None
option_object = self.CONFIG_FILE_OPTIONS[section][option] option_object = self.CONFIG_FILE_OPTIONS[section][option]
if option_object.should_override(currval, newval):
config[section][option] = option_object.update_value( config[section][option] = option_object.update_value(
currval, newval, update_appends) currval, newval, update_appends)

View file

@ -1208,7 +1208,7 @@ class ConfigurationTestCase(test.CdistTestCase):
expected_config_dict = { expected_config_dict = {
'GLOBAL': { 'GLOBAL': {
'save_output_streams': True, 'save_output_streams': False,
'verbosity': 0, 'verbosity': 0,
}, },
} }

View file

@ -11,6 +11,7 @@ next:
* Core: Fix main and inventory parent argparse options (Darko Poljak) * Core: Fix main and inventory parent argparse options (Darko Poljak)
* Core: Fix lost error info with parallel jobs (option -j) (Darko Poljak) * Core: Fix lost error info with parallel jobs (option -j) (Darko Poljak)
* Core: Fix determining beta value through configuration (Darko Poljak) * Core: Fix determining beta value through configuration (Darko Poljak)
* Core: Fix determining save_output_streams value through configuration (Darko Poljak)
4.8.0: 2018-02-14 4.8.0: 2018-02-14
* Core: Skip empty lines in parameter files (Darko Poljak) * Core: Skip empty lines in parameter files (Darko Poljak)