python: run isort on everything
[babeltrace.git] / tests / data / plugins / src.ctf.lttng-live / lttng_live_server.py
index d0eb26d25c5a343b37a50574d223fab0a9a7c369..cd659f49d1b9ea641e378570b5495e5be6167adc 100644 (file)
@@ -3,17 +3,17 @@
 # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
 #
 
-import argparse
-import collections.abc
-import logging
 import os
-import os.path
 import re
+import sys
+import json
 import socket
 import struct
-import sys
+import logging
+import os.path
+import argparse
 import tempfile
-import json
+import collections.abc
 from collections import namedtuple
 
 
@@ -901,7 +901,6 @@ def _split_metadata_sections(metadata_file_path, raw_config_sections):
         # If the next section begins at the current line, create a
         # section with the metadata we gathered so far.
         if curr_line_number >= next_section_line_number:
-
             # Flushing the metadata of the current section.
             sections.append(
                 _LttngMetadataStreamSection(
@@ -1446,9 +1445,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 +1459,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 +1499,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 +1744,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 +1783,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.024356 seconds and 4 git commands to generate.