Utility function for relayd spawning
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 15 Nov 2017 18:49:37 +0000 (13:49 -0500)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 15 Nov 2017 18:49:37 +0000 (13:49 -0500)
Spawn a relayd under a runtime with random free ports.

Synchronization is based on log which is less than ideal.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
lttng_ivc/utils/utils.py

index 755304137aed849242c7a6a2b8434850faaeb396..6a5608c908c36a8fea3f61d4817edfca0d3a24af 100644 (file)
@@ -56,6 +56,45 @@ def sessiond_spawn(runtime):
     return sessiond
 
 
+def relayd_spawn(runtime, url="localhost"):
+    """
+    Return a tuple (relayd_uuid, ctrl_port, data_port, live_port)
+    """
+    ports = find_multiple_free_port(3)
+    data_port = ports.pop()
+    ctrl_port = ports.pop()
+    live_port = ports.pop()
+
+    base_cmd = "lttng-relayd -vvv"
+    data_string = "-D tcp://{}:{}".format(url, data_port)
+    ctrl_string = "-C tcp://{}:{}".format(url, ctrl_port)
+    live_string = "-L tcp://{}:{}".format(url, live_port)
+
+    cmd = " ".join([base_cmd, data_string, ctrl_string, live_string])
+    relayd = runtime.spawn_subprocess(cmd)
+
+    # Synchronization based on verbosity since no -S is available for
+    # lttng-relayd yet.
+    log_path = runtime.get_subprocess_stderr_path(relayd)
+
+    # TODO: Move to settings.
+    ready_cue = "Listener accepting live viewers connections"
+    # TODO: Move to settings.
+    timeout = 60
+    ready = False
+    for i in range(timeout):
+        if file_contains(log_path, ready_cue):
+            ready = True
+            break
+        time.sleep(1)
+
+    if not ready:
+        # Cleanup is performed by runtime
+        raise Exception("Relayd readyness timeout expired")
+
+    return (relayd, ctrl_port, data_port, live_port)
+
+
 def find_free_port():
     # There is no guarantee that the port will be free at runtime but should be
     # good enough
@@ -64,6 +103,20 @@ def find_free_port():
         return s.getsockname()[1]
 
 
+def find_multiple_free_port(number):
+    """
+    Return a list of supposedly free port
+    """
+    assert(number >= 0)
+    ports = []
+    while(len(ports) != number):
+        port = find_free_port()
+        if port in ports:
+            continue
+        ports.append(port)
+    return ports
+
+
 def file_contains(file_path, list_of_string):
     with open(file_path, 'r') as f:
         for line in f:
This page took 0.024648 seconds and 5 git commands to generate.