Handle case when metadata files are configured but not present and also

case where metadata file list is empty

This commit specifically fixes the code to handle the case where metadata files
are configured in the browbeat configuration file but are not present in the
metadata directory. Previoulsy since the combine_metadata method return boolean
value false in such cases and the index_result method treated result as a
dcitionary, traceback was seen. With this commit, combine_metadata stops
returning false and instead exits the run if an intended metadata file is
absent.

+ Changing how we return result so that the code doesn't err out even when
  metadata file list is empty in the confing file
+ Checking in browbeat.py too
Change-Id: I52712beaa2dec6209394a2f3ef605d5a9a13f5cb
This commit is contained in:
Sai Sindhur Malleni 2016-09-19 17:16:20 -04:00
parent 344931b1aa
commit 6c1215960d
2 changed files with 22 additions and 2 deletions

View File

@ -67,6 +67,15 @@ def _run_workload_provider(provider, config):
else:
_logger.error("Unknown workload provider: {}".format(provider))
def check_metadata(config, _logger):
_logger.debug("Checking if configured metadata files are present")
meta = config['elasticsearch']['metadata_files']
for _meta in meta:
if not os.path.isfile(_meta['file']):
_logger.error("Metadata file {} is not present".format(_meta['file']))
return False
return True
def main():
parser = argparse.ArgumentParser(
@ -119,6 +128,13 @@ def main():
time_stamp = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S")
_logger.info("Browbeat test suite kicked off")
_logger.info("Browbeat UUID: {}".format(browbeat_uuid))
if _config['elasticsearch']['enabled']:
_logger.info("Checking for Metadata")
metadata_exists = check_metadata(_config, _logger)
if not metadata_exists:
_logger.error("Elasticsearch has been enabled but"
" metadata files do not exist, exiting")
sys.exit(1)
_logger.info("Running workload(s): {}".format(','.join(_cli_args.workloads)))
for wkld_provider in _cli_args.workloads:
if wkld_provider in _config:

View File

@ -15,6 +15,7 @@ import logging
import json
import datetime
import uuid
import sys
browbeat_uuid = uuid.uuid4()
@ -72,8 +73,11 @@ class Elastic:
except (IOError, OSError):
self.logger.error(
"Error loading Metadata file : {}".format(_meta['file']))
return False
return result
self.logger.error("Please make sure the metadata file exists and"
" is valid JSON or run the playbook ansible/gather/site.yml"
" before running the Browbeat test Suite")
sys.exit(1)
return result
"""
"""