X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lttng_ivc%2Futils%2Futils.py;h=d7592c637869f93fd074546de3ce97b0b1186b4f;hb=efdd48dbd95ae57db1b0f2dfe5af429feee2b06d;hp=755304137aed849242c7a6a2b8434850faaeb396;hpb=206ef7445a69afa543ccfa8e13983483aa966623;p=deliverable%2Flttng-ivc.git diff --git a/lttng_ivc/utils/utils.py b/lttng_ivc/utils/utils.py index 7553041..d7592c6 100644 --- a/lttng_ivc/utils/utils.py +++ b/lttng_ivc/utils/utils.py @@ -1,3 +1,23 @@ +# Copyright (c) 2017 Jonathan Rajotte-Julien +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + import signal import hashlib import os @@ -47,15 +67,56 @@ def __dummy_sigusr1_handler(): pass -def sessiond_spawn(runtime): +def sessiond_spawn(runtime, opt_args=""): agent_port = find_free_port() previous_handler = signal.signal(signal.SIGUSR1, __dummy_sigusr1_handler) - sessiond = runtime.spawn_subprocess("lttng-sessiond -vvv -S --agent-tcp-port {}".format(agent_port)) + cmd = "lttng-sessiond -vvv --verbose-consumer -S --agent-tcp-port {}".format(agent_port) + cmd = " ".join([cmd, opt_args]) + sessiond = runtime.spawn_subprocess(cmd) signal.sigtimedwait({signal.SIGUSR1}, 60) previous_handler = signal.signal(signal.SIGUSR1, previous_handler) 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 +125,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: