tests: add `--port` option to lttng_live_server.py
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 30 Jun 2022 17:15:46 +0000 (13:15 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8215
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10836
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py

index d0eb26d25c5a343b37a50574d223fab0a9a7c369..8ef7e5fd91fb7dff2089c8ba38474406ee15f3a1 100644 (file)
@@ -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)
This page took 0.028186 seconds and 4 git commands to generate.