From: Simon Marchi Date: Mon, 18 Sep 2023 18:47:44 +0000 (-0400) Subject: tests: make lttng_live_server.py write temp port filename in same directory X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=a0a92e790c59dbe2483a54a1b7cb62fa0ed57bd8 tests: make lttng_live_server.py write temp port filename in same directory When running lttng_live_server.py with `--port-filename yoyoyo`, I get: Traceback (most recent call last): File "lttng_live_server.py", line 1982, in LttngLiveServer(port, port_filename, sessions, max_query_data_response_size) File "lttng_live_server.py", line 1716, in __init__ self._write_port_to_file(port_filename) File "lttng_live_server.py", line 1839, in _write_port_to_file os.replace(tmp_port_file.name, port_filename) OSError: [Errno 18] Invalid cross-device link: '/tmp/tmpe70085jz' -> 'yoyoyo' Fix this by placing the temporary file in the same directory as its final location. Change-Id: Ibe6fee5dc99860ab3cd4464a2f490e05c65df1eb Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10901 Tested-by: jenkins Reviewed-by: 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 5d844029..2177afa5 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 @@ -1783,7 +1783,9 @@ class LttngLiveServer: def _write_port_to_file(self, port_filename: str): # Write the port number to a temporary file. - with tempfile.NamedTemporaryFile(mode="w", delete=False) as tmp_port_file: + with tempfile.NamedTemporaryFile( + mode="w", delete=False, dir=os.path.dirname(port_filename) + ) as tmp_port_file: print(self._server_port, end="", file=tmp_port_file) # Rename temporary file to real file