Merge "Add snap package paths to default config dirs"
This commit is contained in:
commit
83d69f888f
|
@ -613,16 +613,27 @@ def _get_config_dirs(project=None):
|
|||
/etc/${project}/
|
||||
/etc/
|
||||
|
||||
Otherwise, these directories::
|
||||
If a project is specified and installed from a snap package, following
|
||||
directories are also returned:
|
||||
|
||||
${SNAP}/etc/${project}
|
||||
${SNAP_COMMON}/etc/${project}
|
||||
|
||||
Otherwise, if project is not specified, these directories are returned:
|
||||
|
||||
~/
|
||||
/etc/
|
||||
"""
|
||||
snap = os.environ.get('SNAP')
|
||||
snap_c = os.environ.get('SNAP_COMMON')
|
||||
|
||||
cfg_dirs = [
|
||||
_fixpath(os.path.join('~', '.' + project)) if project else None,
|
||||
_fixpath('~'),
|
||||
os.path.join('/etc', project) if project else None,
|
||||
'/etc'
|
||||
'/etc',
|
||||
os.path.join(snap, "etc", project) if snap and project else None,
|
||||
os.path.join(snap_c, "etc", project) if snap_c and project else None,
|
||||
]
|
||||
return [x for x in cfg_dirs if x]
|
||||
|
||||
|
@ -673,6 +684,8 @@ def find_config_files(project=None, prog=None, extension='.conf'):
|
|||
~/
|
||||
/etc/${project}/
|
||||
/etc/
|
||||
${SNAP}/etc/${project}
|
||||
${SNAP_COMMON}/etc/${project}
|
||||
|
||||
We return an absolute path for (at most) one of each the default config
|
||||
files, for the topmost directory it exists in.
|
||||
|
@ -703,6 +716,8 @@ def find_config_dirs(project=None, prog=None, extension='.conf.d'):
|
|||
~/
|
||||
/etc/${project}/
|
||||
/etc/
|
||||
${SNAP}/etc/${project}
|
||||
${SNAP_COMMON}/etc/${project}
|
||||
|
||||
We return an absolute path for each of the two config dirs,
|
||||
in the first place we find it (iff we find it).
|
||||
|
|
|
@ -223,6 +223,18 @@ class FindConfigFilesTestCase(BaseTestCase):
|
|||
|
||||
self.assertEqual(cfg.find_config_files(project='blaa'), config_files)
|
||||
|
||||
def test_find_config_files_snap(self):
|
||||
config_files = ['/snap/nova/current/etc/blaa/blaa.conf']
|
||||
fake_env = {'SNAP': '/snap/nova/current/',
|
||||
'SNAP_COMMON': '/var/snap/nova/common/'}
|
||||
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
|
||||
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
|
||||
lambda p: p in config_files))
|
||||
self.useFixture(fixtures.MonkeyPatch('os.environ', fake_env))
|
||||
|
||||
self.assertEqual(cfg.find_config_files(project='blaa'), config_files)
|
||||
|
||||
def test_find_config_files_with_extension(self):
|
||||
config_files = ['/etc/foo.json']
|
||||
|
||||
|
@ -248,6 +260,18 @@ class FindConfigDirsTestCase(BaseTestCase):
|
|||
|
||||
self.assertEqual(cfg.find_config_dirs(project='blaa'), config_dirs)
|
||||
|
||||
def test_find_config_dirs_snap(self):
|
||||
config_dirs = ['/var/snap/nova/common/etc/blaa/blaa.conf.d']
|
||||
fake_env = {'SNAP': '/snap/nova/current/',
|
||||
'SNAP_COMMON': '/var/snap/nova/common/'}
|
||||
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
|
||||
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
|
||||
lambda p: p in config_dirs))
|
||||
self.useFixture(fixtures.MonkeyPatch('os.environ', fake_env))
|
||||
|
||||
self.assertEqual(cfg.find_config_dirs(project='blaa'), config_dirs)
|
||||
|
||||
def test_find_config_dirs_non_exists(self):
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
|
||||
self.assertEqual(cfg.find_config_dirs(project='blaa'), [])
|
||||
|
|
Loading…
Reference in New Issue