Add --print-cachedir option
The option allows other programs to find the cache directory and files without having access to OS_CONFIG_FILES. Change-Id: Iad87efb65ea4db387e94160376c9eaf956fff413
This commit is contained in:
parent
61b6dfb604
commit
c2b1b3909c
@ -55,6 +55,9 @@ opts = [
|
||||
cfg.FloatOpt('polling-interval', short='i', default=300,
|
||||
help='When running continuously, pause this many seconds'
|
||||
' between collecting data.'),
|
||||
cfg.BoolOpt('print-cachedir',
|
||||
default=False,
|
||||
help='Print out the value of cachedir and exit immediately.'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
@ -161,6 +164,10 @@ def __main__(args=sys.argv, requests_impl_map=None):
|
||||
if not log.getLogger(None).logger.handlers:
|
||||
log.setup("os-collect-config")
|
||||
|
||||
if CONF.print_cachedir:
|
||||
print(CONF.cachedir)
|
||||
return
|
||||
|
||||
unknown_collectors = set(CONF.collectors) - set(DEFAULT_COLLECTORS)
|
||||
if unknown_collectors:
|
||||
raise exc.InvalidArguments(
|
||||
|
@ -156,6 +156,21 @@ class TestCollect(testtools.TestCase):
|
||||
self.assertIn('ec2', out_struct)
|
||||
self.assertIn('cfn', out_struct)
|
||||
|
||||
def test_main_print_cachedir(self):
|
||||
fake_cachedir = self.useFixture(fixtures.TempDir())
|
||||
fake_args = [
|
||||
'os-collect-config',
|
||||
'--cachedir', fake_cachedir.path,
|
||||
'--config-file', '/dev/null',
|
||||
'--print-cachedir',
|
||||
]
|
||||
output = self.useFixture(fixtures.StringStream('stdout'))
|
||||
self.useFixture(
|
||||
fixtures.MonkeyPatch('sys.stdout', output.stream))
|
||||
self._call_main(fake_args)
|
||||
cache_dir = output.getDetails()['stdout'].as_text().strip()
|
||||
self.assertEquals(fake_cachedir.path, cache_dir)
|
||||
|
||||
def test_main_invalid_collector(self):
|
||||
fake_args = ['os-collect-config', 'invalid']
|
||||
self.assertRaises(exc.InvalidArguments, self._call_main, fake_args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user