Allow to configure an initial delay

Until now, all clients would start at the same time. This could greatly
affect the tested server.

This change allows to configure a time span in which a client will
randomly start with the execution. This should mitigate the effect.

Change-Id: I0a1ea7f21f82c96f4e20428eed0ce4590962530c
diff --git a/README.md b/README.md
index 34764f3..b9f62df 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,9 @@
 | `gerrit.user`                                   | Gerrit user used for tests                                                            | `admin`                 |
 | `gerrit.password`                               | Password of Gerrit user                                                               | `secret`                |
 | `testrun.duration`                              | Duration for which to run the tests                                                   | `null` (indefinitely)   |
+| `testrun.initialization.delay.enabled`          | Whether to delay execution of a test run                                              | `true`                  |
+| `testrun.initialization.delay.min`              | Minimum initial delay in seconds                                                      | `0`                     |
+| `testrun.initialization.delay.max`              | Maximum initial delay in seconds                                                      | `300`                   |
 | `testrun.initialization.createProjects.enabled` | Whether to create new projects during initialization                                  | `true`                  |
 | `testrun.initialization.createProjects.number`  | How many new projects to create during initialization                                 | `1`                     |
 | `testrun.initialization.knownProjects`          | List of projects that the simulated user knows of from the beginning                  | `nil`                   |
diff --git a/config.sample.yaml b/config.sample.yaml
index 8b53287..0f4626d 100644
--- a/config.sample.yaml
+++ b/config.sample.yaml
@@ -6,6 +6,10 @@
 testrun:
   duration: null
   initialization:
+    delay:
+      enabled: true
+      min: 0
+      max: 300
     createProjects:
       enabled: true
       number: 1
diff --git a/container/tools/config/parser.py b/container/tools/config/parser.py
index 96488dd..98ca550 100644
--- a/container/tools/config/parser.py
+++ b/container/tools/config/parser.py
@@ -23,6 +23,7 @@
     "testrun": {
         "duration": None,
         "initialization": {
+            "delay": {"enabled": True, "min": 0, "max": 300},
             "createProjects": {"enabled": True, "number": 1},
             "knownProjects": list(),
         },
diff --git a/container/tools/start_test.py b/container/tools/start_test.py
index 04c2542..374b7dd 100755
--- a/container/tools/start_test.py
+++ b/container/tools/start_test.py
@@ -31,6 +31,13 @@
 class LoadTestInstance:
     def __init__(self, test_config):
         self.config = test_config
+        self.log = logging.getLogger("ActionLogger")
+
+        if self.config["testrun"]["initialization"]["delay"]["enabled"]:
+            self._wait_random_seconds(
+                self.config["testrun"]["initialization"]["delay"]["min"],
+                self.config["testrun"]["initialization"]["delay"]["max"],
+            )
 
         self.url = self.config["gerrit"]["url"]
         self.user = self.config["gerrit"]["user"]
@@ -57,8 +64,6 @@
                 self.config["testrun"]["initialization"]["createProjects"]["number"]
             )
 
-        self.log = logging.getLogger("ActionLogger")
-
     def run(self):
         while True:
             if self.timeout and time.time() >= self.timeout:
@@ -92,9 +97,9 @@
                 ).execute()
             )
 
-    @staticmethod
-    def _wait_random_seconds(min_wait, max_wait):
+    def _wait_random_seconds(self, min_wait, max_wait):
         wait_duration = random.randint(min_wait, max_wait)
+        self.log.info("Waiting for %d seconds.", wait_duration)
         time.sleep(wait_duration)
 
     @staticmethod
diff --git a/kubernetes/load-tester/load-tester.configmap.yaml b/kubernetes/load-tester/load-tester.configmap.yaml
index 589a627..88f2eb9 100644
--- a/kubernetes/load-tester/load-tester.configmap.yaml
+++ b/kubernetes/load-tester/load-tester.configmap.yaml
@@ -9,6 +9,10 @@
     testrun:
       duration: null
       initialization:
+        delay:
+          enabled: true
+          min: 0
+          max: 300
         createProjects:
           enabled: true
           number: 1