Handle case where benchmark list is empty

Currently if the key benchmarks is present in the configuration file but the
list of benchmarks/scenarios is empty, a None type object is returned and
len(benchmarks) fails. This patch handles this case by  short-circuiting
the if statement with a check for None.

Change-Id: I7be614e05a93dbd605c0c5b0452b6ca0920f1790
Closes-Bug: #1605389
This commit is contained in:
Sai Sindhur Malleni 2016-07-21 17:08:07 -04:00
parent 381e0204e4
commit e52a87c261
3 changed files with 3 additions and 4 deletions

View File

@ -158,7 +158,7 @@ class PerfKit(WorkloadBase):
time_stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
self.logger.debug("Time Stamp (Prefix): {}".format(time_stamp))
benchmarks = self.config.get('perfkit')['benchmarks']
if len(benchmarks) > 0:
if (benchmarks is not None and len(benchmarks) > 0):
for benchmark in benchmarks:
if benchmark['enabled']:
self.logger.info("Benchmark: {}".format(benchmark['name']))

View File

@ -179,7 +179,7 @@ class Rally(WorkloadBase):
dir_ts = es_ts.strftime("%Y%m%d-%H%M%S")
self.logger.debug("Time Stamp (Prefix): {}".format(dir_ts))
benchmarks = self.config.get('rally')['benchmarks']
if len(benchmarks) > 0:
if (benchmarks is not None and len(benchmarks) > 0):
for benchmark in benchmarks:
if benchmark['enabled']:
self.logger.info("Benchmark: {}".format(benchmark['name']))

View File

@ -397,8 +397,7 @@ class Shaker(WorkloadBase):
scenarios = self.config.get('shaker')['scenarios']
venv = self.config['shaker']['venv']
self.shaker_checks()
scen_length = len(scenarios)
if scen_length > 0:
if (scenarios is not None and len(scenarios) > 0):
for scenario in scenarios:
if scenario['enabled']:
self.update_scenarios()