From 6c1215960d6a1219bb3d5a6aefdb9c4461cd453f Mon Sep 17 00:00:00 2001 From: Sai Sindhur Malleni Date: Mon, 19 Sep 2016 17:16:20 -0400 Subject: [PATCH] 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 --- browbeat.py | 16 ++++++++++++++++ lib/Elastic.py | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/browbeat.py b/browbeat.py index eef05d440..bbb22badc 100755 --- a/browbeat.py +++ b/browbeat.py @@ -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: diff --git a/lib/Elastic.py b/lib/Elastic.py index 3fe220430..f32861201 100644 --- a/lib/Elastic.py +++ b/lib/Elastic.py @@ -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 """ """