From 2dac53acebf05c7edcb9445e454995298f51a0a8 Mon Sep 17 00:00:00 2001 From: Jerry Flood Date: Fri, 2 Jun 2017 16:43:02 -0400 Subject: Externalize soak parameters to a json file Issue: TEST-38 Change-Id: I90ae5ebaf7cdfed770dfe99c9ae600bb425abadf Signed-off-by: Jerry Flood --- loadtest/TestConfig.py | 30 +++++++++++++++++++----------- loadtest/TestController.py | 2 +- loadtest/TestMain.py | 4 +++- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'loadtest') diff --git a/loadtest/TestConfig.py b/loadtest/TestConfig.py index c22e875..b9b8112 100644 --- a/loadtest/TestConfig.py +++ b/loadtest/TestConfig.py @@ -3,6 +3,8 @@ Created on Apr 7, 2017 @author: jf9860 ''' +import json + class TestConfig(object): ''' The profile defines a cycle of tests. Each entry is defined as @@ -10,31 +12,37 @@ class TestConfig(object): ''' profile = [ [0, ["health"]], - [5, ["instantiate", "distribute"]], - [300, ["distribute"]], - [300, ["distribute"]], - [300, ["distribute"]], - [300, ["distribute"]], - [300, ["distribute"]], ] duration=10 cyclelength=60 - def __init__(self, duration=10, cyclelength=1800, json=None): + def __init__(self, duration=None, cyclelength=None, json=None): ''' Constructor ''' - self.duration = duration - self.cyclelength = cyclelength + if (json != None): + self.parseConfig(json) + if (duration != None): + self.duration = duration + if (cyclelength != None): + self.cyclelength = cyclelength running_time = 0 for p in self.profile: secs = p[0] running_time = running_time + secs - if (running_time < cyclelength): - last = cyclelength - running_time + if (running_time < self.cyclelength): + last = self.cyclelength - running_time self.profile.append([last, []]) + def parseConfig(self, fileName): + with open(fileName) as data_file: + config = json.load(data_file) + self.profile = config["profile"] + self.cyclelength = config["cyclelength"] + self.duration = config["duration"] + + def to_string(self): pstring = 'Cycle length is {} seconds'.format(self.cyclelength) pstring = '{}\nDuration is {} seconds'.format(pstring, self.duration) diff --git a/loadtest/TestController.py b/loadtest/TestController.py index 751b13a..3ba0083 100644 --- a/loadtest/TestController.py +++ b/loadtest/TestController.py @@ -23,7 +23,7 @@ class TestController(object): ''' Constructor ''' - self.config = TestConfig(duration=options.duration) + self.config = TestConfig(duration=options.duration, cyclelength=options.cyclelength, json=options.profile) logging.info(self.config.to_string()) def execute(self): diff --git a/loadtest/TestMain.py b/loadtest/TestMain.py index a9b57db..81c635f 100644 --- a/loadtest/TestMain.py +++ b/loadtest/TestMain.py @@ -54,7 +54,9 @@ def main(argv=None): parser = OptionParser(version=program_version_string, epilog=program_longdesc, description=program_license) parser.add_option("-d", "--duration", dest="duration", help="duration of soak test in seconds [default: %default]", type=int) parser.add_option("-l", "--logfile", dest="logfile", help="Full path soak log file name") - parser.set_defaults(duration="60", logfile="") + parser.add_option("-c", "--cyclelength", dest="cyclelength", help="Length of a single cycle through the config.\nMust be longer than a single iteration", type=int) + parser.add_option("-p", "--profile", dest="profile", help="Filename of json profile file") + parser.set_defaults(logfile="") (opts, args) = parser.parse_args(argv) if (opts.logfile != ""): -- cgit 1.2.3-korg