Handle missing local collector directory

We currently explode if local collector is enabled with the data
directory missing. Changing this to a warning allows us to have this
turned on by default without greatly inconveniencing users.

Change-Id: I36364ba1a0706a5a2c820eadd526f2ba424ac665
This commit is contained in:
Gregory Haynes 2014-10-28 12:47:44 -07:00
parent 0f83ecbc2f
commit d05f57b092
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))