summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 15:09:31 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 15:09:31 +0000
commit83d69f888f6c9bb89ae1e02e21b85422183efb41 (patch)
treef059d3bef980554e3e6acde1ba712d3ab89db78e
parent28b4e2b50b35816a086fba0474c58ae9e601265d (diff)
parent21e70e28b3015c1619dacfad8a2218b09e8109ec (diff)
Merge "Add snap package paths to default config dirs"4.6.0
-rw-r--r--oslo_config/cfg.py19
-rw-r--r--oslo_config/tests/test_cfg.py24
2 files changed, 41 insertions, 2 deletions
diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py
index 94d487e..b067c2d 100644
--- a/oslo_config/cfg.py
+++ b/oslo_config/cfg.py
@@ -613,16 +613,27 @@ def _get_config_dirs(project=None):
613 /etc/${project}/ 613 /etc/${project}/
614 /etc/ 614 /etc/
615 615
616 Otherwise, these directories:: 616 If a project is specified and installed from a snap package, following
617 directories are also returned:
618
619 ${SNAP}/etc/${project}
620 ${SNAP_COMMON}/etc/${project}
621
622 Otherwise, if project is not specified, these directories are returned:
617 623
618 ~/ 624 ~/
619 /etc/ 625 /etc/
620 """ 626 """
627 snap = os.environ.get('SNAP')
628 snap_c = os.environ.get('SNAP_COMMON')
629
621 cfg_dirs = [ 630 cfg_dirs = [
622 _fixpath(os.path.join('~', '.' + project)) if project else None, 631 _fixpath(os.path.join('~', '.' + project)) if project else None,
623 _fixpath('~'), 632 _fixpath('~'),
624 os.path.join('/etc', project) if project else None, 633 os.path.join('/etc', project) if project else None,
625 '/etc' 634 '/etc',
635 os.path.join(snap, "etc", project) if snap and project else None,
636 os.path.join(snap_c, "etc", project) if snap_c and project else None,
626 ] 637 ]
627 return [x for x in cfg_dirs if x] 638 return [x for x in cfg_dirs if x]
628 639
@@ -673,6 +684,8 @@ def find_config_files(project=None, prog=None, extension='.conf'):
673 ~/ 684 ~/
674 /etc/${project}/ 685 /etc/${project}/
675 /etc/ 686 /etc/
687 ${SNAP}/etc/${project}
688 ${SNAP_COMMON}/etc/${project}
676 689
677 We return an absolute path for (at most) one of each the default config 690 We return an absolute path for (at most) one of each the default config
678 files, for the topmost directory it exists in. 691 files, for the topmost directory it exists in.
@@ -703,6 +716,8 @@ def find_config_dirs(project=None, prog=None, extension='.conf.d'):
703 ~/ 716 ~/
704 /etc/${project}/ 717 /etc/${project}/
705 /etc/ 718 /etc/
719 ${SNAP}/etc/${project}
720 ${SNAP_COMMON}/etc/${project}
706 721
707 We return an absolute path for each of the two config dirs, 722 We return an absolute path for each of the two config dirs,
708 in the first place we find it (iff we find it). 723 in the first place we find it (iff we find it).
diff --git a/oslo_config/tests/test_cfg.py b/oslo_config/tests/test_cfg.py
index 5186342..26093e3 100644
--- a/oslo_config/tests/test_cfg.py
+++ b/oslo_config/tests/test_cfg.py
@@ -223,6 +223,18 @@ class FindConfigFilesTestCase(BaseTestCase):
223 223
224 self.assertEqual(cfg.find_config_files(project='blaa'), config_files) 224 self.assertEqual(cfg.find_config_files(project='blaa'), config_files)
225 225
226 def test_find_config_files_snap(self):
227 config_files = ['/snap/nova/current/etc/blaa/blaa.conf']
228 fake_env = {'SNAP': '/snap/nova/current/',
229 'SNAP_COMMON': '/var/snap/nova/common/'}
230
231 self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
232 self.useFixture(fixtures.MonkeyPatch('os.path.exists',
233 lambda p: p in config_files))
234 self.useFixture(fixtures.MonkeyPatch('os.environ', fake_env))
235
236 self.assertEqual(cfg.find_config_files(project='blaa'), config_files)
237
226 def test_find_config_files_with_extension(self): 238 def test_find_config_files_with_extension(self):
227 config_files = ['/etc/foo.json'] 239 config_files = ['/etc/foo.json']
228 240
@@ -248,6 +260,18 @@ class FindConfigDirsTestCase(BaseTestCase):
248 260
249 self.assertEqual(cfg.find_config_dirs(project='blaa'), config_dirs) 261 self.assertEqual(cfg.find_config_dirs(project='blaa'), config_dirs)
250 262
263 def test_find_config_dirs_snap(self):
264 config_dirs = ['/var/snap/nova/common/etc/blaa/blaa.conf.d']
265 fake_env = {'SNAP': '/snap/nova/current/',
266 'SNAP_COMMON': '/var/snap/nova/common/'}
267
268 self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
269 self.useFixture(fixtures.MonkeyPatch('os.path.exists',
270 lambda p: p in config_dirs))
271 self.useFixture(fixtures.MonkeyPatch('os.environ', fake_env))
272
273 self.assertEqual(cfg.find_config_dirs(project='blaa'), config_dirs)
274
251 def test_find_config_dirs_non_exists(self): 275 def test_find_config_dirs_non_exists(self):
252 self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo'])) 276 self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
253 self.assertEqual(cfg.find_config_dirs(project='blaa'), []) 277 self.assertEqual(cfg.find_config_dirs(project='blaa'), [])