Disable config parser interpolation
This commit is contained in:
parent
b9a48c9316
commit
5aa8dac80a
4 changed files with 45 additions and 26 deletions
|
@ -382,7 +382,7 @@ class Configuration(metaclass=Singleton):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def _read_config_file(self, files):
|
def _read_config_file(self, files):
|
||||||
config_parser = configparser.ConfigParser()
|
config_parser = configparser.ConfigParser(interpolation=None)
|
||||||
config_parser.read(files)
|
config_parser.read(files)
|
||||||
d = dict()
|
d = dict()
|
||||||
for section in config_parser.sections():
|
for section in config_parser.sections():
|
||||||
|
|
|
@ -31,6 +31,11 @@ import logging
|
||||||
|
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
|
interpolation_config_file = op.join(fixtures, "interpolation-test.cfg")
|
||||||
|
|
||||||
|
|
||||||
|
def newConfigParser():
|
||||||
|
return configparser.ConfigParser(interpolation=None)
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationOptionsTestCase(test.CdistTestCase):
|
class ConfigurationOptionsTestCase(test.CdistTestCase):
|
||||||
|
@ -141,7 +146,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create test config file.
|
# Create test config file.
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -159,13 +164,13 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
'verbosity': 'INFO',
|
'verbosity': 'INFO',
|
||||||
'archiving': 'none',
|
'archiving': 'none',
|
||||||
}
|
}
|
||||||
config_custom = configparser.ConfigParser()
|
config_custom = newConfigParser()
|
||||||
config_custom['GLOBAL'] = {
|
config_custom['GLOBAL'] = {
|
||||||
'parallel': '4',
|
'parallel': '4',
|
||||||
'archiving': 'txz',
|
'archiving': 'txz',
|
||||||
}
|
}
|
||||||
|
|
||||||
config_custom2 = configparser.ConfigParser()
|
config_custom2 = newConfigParser()
|
||||||
config_custom2['GLOBAL'] = {
|
config_custom2['GLOBAL'] = {
|
||||||
'parallel': '16',
|
'parallel': '16',
|
||||||
'archiving': 'tbz2',
|
'archiving': 'tbz2',
|
||||||
|
@ -405,7 +410,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -463,7 +468,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -486,7 +491,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -544,7 +549,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -611,7 +616,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -634,7 +639,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -709,7 +714,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -732,7 +737,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -800,7 +805,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -823,7 +828,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -840,7 +845,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(local_config_file, 'w') as f:
|
with open(local_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'conf_dir': '/opt/conf/cdist',
|
'conf_dir': '/opt/conf/cdist',
|
||||||
'remote_copy': 'scpcustom',
|
'remote_copy': 'scpcustom',
|
||||||
|
@ -899,7 +904,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -922,7 +927,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -939,7 +944,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(local_config_file, 'w') as f:
|
with open(local_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'conf_dir': '/opt/conf/cdist',
|
'conf_dir': '/opt/conf/cdist',
|
||||||
'remote_copy': 'scpcustom',
|
'remote_copy': 'scpcustom',
|
||||||
|
@ -998,7 +1003,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
}
|
}
|
||||||
args = argparse.Namespace()
|
args = argparse.Namespace()
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'off',
|
'beta': 'off',
|
||||||
'local_shell': '/bin/sh',
|
'local_shell': '/bin/sh',
|
||||||
|
@ -1021,7 +1026,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(global_config_file, 'w') as f:
|
with open(global_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'beta': 'on',
|
'beta': 'on',
|
||||||
'local_shell': '/usr/bin/sh',
|
'local_shell': '/usr/bin/sh',
|
||||||
|
@ -1038,7 +1043,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
with open(local_config_file, 'w') as f:
|
with open(local_config_file, 'w') as f:
|
||||||
config.write(f)
|
config.write(f)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'conf_dir': '/opt/conf/cdist',
|
'conf_dir': '/opt/conf/cdist',
|
||||||
'remote_copy': 'scpcustom',
|
'remote_copy': 'scpcustom',
|
||||||
|
@ -1107,7 +1112,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(dargs, expected_args)
|
self.assertEqual(dargs, expected_args)
|
||||||
|
|
||||||
def test_configuration_empty_value_in_file(self):
|
def test_configuration_empty_value_in_file(self):
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'inventory_dir': '',
|
'inventory_dir': '',
|
||||||
'conf_dir': '',
|
'conf_dir': '',
|
||||||
|
@ -1169,7 +1174,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
config_files=())
|
config_files=())
|
||||||
|
|
||||||
def test_configuration_disable_saving_output_streams1(self):
|
def test_configuration_disable_saving_output_streams1(self):
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'save_output_streams': 'True',
|
'save_output_streams': 'True',
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1202,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(configuration.config, expected_config_dict)
|
self.assertEqual(configuration.config, expected_config_dict)
|
||||||
|
|
||||||
def test_configuration_disable_saving_output_streams2(self):
|
def test_configuration_disable_saving_output_streams2(self):
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'save_output_streams': 'False',
|
'save_output_streams': 'False',
|
||||||
}
|
}
|
||||||
|
@ -1225,7 +1230,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(configuration.config, expected_config_dict)
|
self.assertEqual(configuration.config, expected_config_dict)
|
||||||
|
|
||||||
def test_configuration_disable_saving_output_streams3(self):
|
def test_configuration_disable_saving_output_streams3(self):
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'save_output_streams': 'False',
|
'save_output_streams': 'False',
|
||||||
}
|
}
|
||||||
|
@ -1253,7 +1258,7 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(configuration.config, expected_config_dict)
|
self.assertEqual(configuration.config, expected_config_dict)
|
||||||
|
|
||||||
def test_configuration_disable_saving_output_streams4(self):
|
def test_configuration_disable_saving_output_streams4(self):
|
||||||
config = configparser.ConfigParser()
|
config = newConfigParser()
|
||||||
config['GLOBAL'] = {
|
config['GLOBAL'] = {
|
||||||
'save_output_streams': 'True',
|
'save_output_streams': 'True',
|
||||||
}
|
}
|
||||||
|
@ -1280,6 +1285,17 @@ class ConfigurationTestCase(test.CdistTestCase):
|
||||||
config_files=config_files)
|
config_files=config_files)
|
||||||
self.assertEqual(configuration.config, expected_config_dict)
|
self.assertEqual(configuration.config, expected_config_dict)
|
||||||
|
|
||||||
|
def test_read_config_file_with_interpolation(self):
|
||||||
|
try:
|
||||||
|
config = cc.Configuration(None, env={}, config_files=())
|
||||||
|
d = config._read_config_file(interpolation_config_file)
|
||||||
|
val = d['GLOBAL']['cache_path_pattern']
|
||||||
|
self.assertIsNotNone(val)
|
||||||
|
self.assertEqual(val, '%N')
|
||||||
|
except configparser.InterpolationSyntaxError as e:
|
||||||
|
self.fail("Exception should not have been raised: {}".format(
|
||||||
|
e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import unittest
|
import unittest
|
||||||
|
|
2
cdist/test/configuration/fixtures/interpolation-test.cfg
Normal file
2
cdist/test/configuration/fixtures/interpolation-test.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[GLOBAL]
|
||||||
|
cache_path_pattern = %N
|
|
@ -3,6 +3,7 @@ Changelog
|
||||||
|
|
||||||
next:
|
next:
|
||||||
* New type: __acl (Ander Punnar)
|
* New type: __acl (Ander Punnar)
|
||||||
|
* Core: Disable config parser interpolation (Darko Poljak)
|
||||||
|
|
||||||
4.9.1: 2018-05-30
|
4.9.1: 2018-05-30
|
||||||
* New type: __install_coreos (Ľubomír Kučera)
|
* New type: __install_coreos (Ľubomír Kučera)
|
||||||
|
|
Loading…
Reference in a new issue