Merge "Handle missing local collector directory"

This commit is contained in:
Jenkins 2014-10-29 16:13:22 +00:00 committed by Gerrit Code Review
commit 72bd2854f6
2 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,11 @@ class Collector(object):
raise exc.LocalMetadataNotAvailable
final_content = []
for local_path in cfg.CONF.local.path:
try:
os.stat(local_path)
except OSError:
logger.warning("%s not found. Skipping", local_path)
continue
if _dest_looks_insecure(local_path):
raise exc.LocalMetadataNotAvailable
for data_file in os.listdir(local_path):

View File

@ -140,3 +140,11 @@ class TestLocal(testtools.TestCase):
badjson.write('{')
self.assertRaises(exc.LocalMetadataNotAvailable, self._call_collect)
self.assertIn('is not valid JSON', self.log.output)
def test_collect_local_path_nonexist(self):
cfg.CONF.set_override(name='path',
override=['/this/doesnt/exist'],
group='local')
local_md = self._call_collect()
self.assertThat(local_md, matchers.IsInstance(list))
self.assertEqual(0, len(local_md))