Externalize soak parameters to a json file
[testsuite/python-testing-utils.git] / loadtest / TestConfig.py
1 '''
2 Created on Apr 7, 2017
3
4 @author: jf9860
5 '''
6 import json
7
8 class TestConfig(object):
9     '''
10     The profile defines a cycle of tests. Each entry is defined as
11     [<seconds to wait>, [<list of ete tags to run after the wait]],
12     '''
13     profile =    [
14         [0, ["health"]],
15     ]
16
17     duration=10
18     cyclelength=60
19
20     def __init__(self, duration=None, cyclelength=None, json=None):
21         '''
22         Constructor
23         '''
24         if (json != None):
25             self.parseConfig(json)
26         if (duration != None):
27             self.duration = duration
28         if (cyclelength != None):
29             self.cyclelength = cyclelength
30         running_time = 0
31         for p in self.profile:
32             secs = p[0]
33             running_time = running_time + secs
34         if (running_time < self.cyclelength):
35             last = self.cyclelength - running_time
36             self.profile.append([last, []])
37
38     def parseConfig(self, fileName):
39         with open(fileName) as data_file:
40             config = json.load(data_file)
41         self.profile = config["profile"]
42         self.cyclelength = config["cyclelength"]
43         self.duration = config["duration"]
44
45
46     def to_string(self):
47         pstring = 'Cycle length is {} seconds'.format(self.cyclelength)
48         pstring = '{}\nDuration is {} seconds'.format(pstring, self.duration)
49         running_time = 0
50         for p in self.profile:
51             secs = p[0]
52             running_time = running_time + secs
53             for ete in p[1]:
54                 pstring = "{0}\n{1:08d} : {2:08d} : {3}".format(pstring, secs, running_time, ete)
55             if (len(p[1]) == 0):
56                 pstring = "{0}\n{1:08d} : {2:08d} : {3}".format(pstring, secs, running_time, "")
57         return pstring
58
59