cfg: Read configuration from .d files and multiple locations

- Read configuration files from three different locations.
/usr/share/freedombox/freedombox.config, /etc/plinth/plinth.config and
/etc/freedombox/freedombox.conf. Later listed has higher priority.

- Provide backward compatibility for /etc/plinth/plinth.config files. With lower
priority than /etc/freedombox but higher priority than /usr/share/.

- Read sorted files from config.d directories with the same suffix as original
configuration file. Parse them by priority. This allows administrator/programs
to drop in configuration bits without worry about editing files.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2020-06-28 21:01:40 -04:00
1 parent 823735729b
commit aaa306aef5
5 files changed
+46 -7

No files matched your search

@@ -0,0 +1,2 @@
[Misc]
box_name = FreedomBox01
@@ -0,0 +1,2 @@
[Misc]
box_name = FreedomBox02
@@ -0,0 +1,2 @@
[Misc]
box_name = FreedomBox03
+18 -3
View File
@@ -45,15 +45,30 @@ def test_read_default_config_file():
compare_configurations(parser)
@patch('plinth.cfg.get_config_path')
def test_read_primary_config_file(get_config_path):
@patch('plinth.cfg.get_config_paths')
def test_read_primary_config_file(get_config_paths):
"""Verify that the primary config file is used by default."""
config_path = CONFIG_FILE_WITH_MISSING_OPTIONS
get_config_path.return_value = config_path
get_config_paths.return_value = [config_path]
cfg.read()
assert cfg.config_files[-1] == config_path
@patch('plinth.cfg.get_config_paths')
def test_read_dot_d_config_files(get_config_paths):
"""Verify that the configuration is read from .d directories."""
root_dir = pathlib.Path(__file__).resolve().parent
config_path = root_dir / 'data' / 'configs' / 'freedombox.config'
config_path_d = config_path.with_suffix(config_path.suffix + '.d')
get_config_paths.return_value = [str(config_path)]
cfg.read()
assert cfg.config_files[-3] == str(config_path)
assert cfg.config_files[-2] == str(config_path_d / '01_first.config')
assert cfg.config_files[-1] == str(config_path_d / '02_second.config')
assert cfg.box_name == 'FreedomBox02'
def test_read_develop_config_file():
"""Verify that the correct develop config file is used."""
test_dir = os.path.dirname(os.path.realpath(__file__))