From 2dfbd89c5e3fa2f2cabbbe3471181c492e62412a Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 1 Mar 2018 20:00:54 +0100 Subject: [PATCH] Fix determining save_output_streams value through configuration --- cdist/configuration.py | 24 +++++++++++++++++++----- cdist/test/configuration/__init__.py | 2 +- docs/changelog | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cdist/configuration.py b/cdist/configuration.py index 674551b8..ea916107 100644 --- a/cdist/configuration.py +++ b/cdist/configuration.py @@ -78,6 +78,9 @@ class OptionBase: else: return newval + def should_override(self, currval, newval): + return True + class StringOption(OptionBase): def __init__(self, name): @@ -98,8 +101,12 @@ class StringOption(OptionBase): class BooleanOption(OptionBase): 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) + self.default_overrides = default_overrides + self.default_value = default_value def get_converter(self): def boolean_converter(val): @@ -113,6 +120,11 @@ class BooleanOption(OptionBase): def translate(self, 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): def __init__(self, name): @@ -286,7 +298,8 @@ class Configuration(metaclass=Singleton): 'parallel': JobsOption('parallel'), 'verbosity': VerbosityOption(), 'archiving': ArchivingOption(), - 'save_output_streams': BooleanOption('save_output_streams'), + 'save_output_streams': BooleanOption('save_output_streams', + default_overrides=False), }, } @@ -414,7 +427,7 @@ class Configuration(metaclass=Singleton): # False to override True. if (args[option] or (isinstance(option_object, BooleanOption) and - args[option] is not None)): + args[option] is not None)): d[dst_opt] = args[option] return d @@ -434,8 +447,9 @@ class Configuration(metaclass=Singleton): else: currval = None option_object = self.CONFIG_FILE_OPTIONS[section][option] - config[section][option] = option_object.update_value( - currval, newval, update_appends) + if option_object.should_override(currval, newval): + config[section][option] = option_object.update_value( + currval, newval, update_appends) def _update_defaults_for_unset(self, config): defaults = self.REQUIRED_DEFAULT_CONFIG_VALUES diff --git a/cdist/test/configuration/__init__.py b/cdist/test/configuration/__init__.py index 4ce3d29d..e34c30b9 100644 --- a/cdist/test/configuration/__init__.py +++ b/cdist/test/configuration/__init__.py @@ -1208,7 +1208,7 @@ class ConfigurationTestCase(test.CdistTestCase): expected_config_dict = { 'GLOBAL': { - 'save_output_streams': True, + 'save_output_streams': False, 'verbosity': 0, }, } diff --git a/docs/changelog b/docs/changelog index fadad32f..3c22ae35 100644 --- a/docs/changelog +++ b/docs/changelog @@ -11,6 +11,7 @@ next: * Core: Fix main and inventory parent argparse options (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 save_output_streams value through configuration (Darko Poljak) 4.8.0: 2018-02-14 * Core: Skip empty lines in parameter files (Darko Poljak)