From: Simon Marchi Date: Thu, 30 Jun 2022 17:15:46 +0000 (-0400) Subject: tests: add `--port` option to lttng_live_server.py X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=e51141d3d71aaa0b5260aa6aa85941a0706db0b2 tests: add `--port` option to lttng_live_server.py This is useful when testing manually, to force using a specific port. When not specified, we still use an OS-assigned port, so it doesn't change the behavior when used by the testsuite. Change-Id: Ic530bf13ddfa37fa1095c1e52a6c78f284e2c312 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8215 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/10836 Tested-by: jenkins CI-Build: Philippe Proulx --- diff --git a/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py b/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py index d0eb26d2..8ef7e5fd 100644 --- a/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py +++ b/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py @@ -1446,9 +1446,10 @@ class _LttngLiveViewerSession: # An LTTng live TCP server. # -# On creation, it binds to `localhost` with an OS-assigned TCP port. It writes -# the decimal TCP port number to a temporary port file. It renames the -# temporary port file to `port_filename`. +# On creation, it binds to `localhost` on the TCP port `port` if not `None`, or +# on an OS-assigned TCP port otherwise. It writes the decimal TCP port number +# to a temporary port file. It renames the temporary port file to +# `port_filename`. # # `tracing_session_descriptors` is a list of tracing session descriptors # (`LttngTracingSessionDescriptor`) to serve. @@ -1459,7 +1460,11 @@ class _LttngLiveViewerSession: # returns. class LttngLiveServer: def __init__( - self, port_filename, tracing_session_descriptors, max_query_data_response_size + self, + port, + port_filename, + tracing_session_descriptors, + max_query_data_response_size, ): logging.info("Server configuration:") @@ -1495,7 +1500,7 @@ class LttngLiveServer: self._codec = _LttngLiveViewerProtocolCodec() # Port 0: OS assigns an unused port - serv_addr = ("localhost", 0) + serv_addr = ("localhost", port if port is not None else 0) self._sock.bind(serv_addr) self._write_port_to_file(port_filename) @@ -1740,6 +1745,11 @@ if __name__ == "__main__": loglevel_namespace, remaining_args = parser.parse_known_args() logging.getLogger().setLevel(_loglevel_parser(loglevel_namespace.log_level)) + parser.add_argument( + "--port", + help="The port to bind to. If missing, use an OS-assigned port..", + type=int, + ) parser.add_argument( "--port-filename", help="The final port file. This file is present when the server is ready to receive connection.", @@ -1774,7 +1784,9 @@ if __name__ == "__main__": args.sessions_filename, args.trace_path_prefix, ) - LttngLiveServer(args.port_filename, sessions, args.max_query_data_response_size) + LttngLiveServer( + args.port, args.port_filename, sessions, args.max_query_data_response_size + ) except UnexpectedInput as exc: logging.error(str(exc)) print(exc, file=sys.stderr)