Externalize soak parameters to a json file
[testsuite/python-testing-utils.git] / loadtest / TestConfig.py
index c22e875..b9b8112 100644 (file)
@@ -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)