summaryrefslogtreecommitdiff
path: root/zuul
diff options
context:
space:
mode:
authorIan Wienand <iwienand@redhat.com>2022-07-21 14:41:39 +1000
committerIan Wienand <iwienand@redhat.com>2022-08-09 17:04:46 +1000
commitdf3f9dcd30a13232447b3be67c7845c51cb527a0 (patch)
treee2f834ca9d0c0f4330309b64a1587db25ca09805 /zuul
parentc1b2fa55988b3f22b392086fe003bde2444ebbdc (diff)
downloadzuul-df3f9dcd30a13232447b3be67c7845c51cb527a0.tar.gz
zuul-stream: automatically remove streaming files
When using protocol version 1, send a finalise message when streaming is complete so that the zuul_console daemon can delete the temporary file. We test this by inspecting the Ansible console output, which logs a message with the UUID of the streaming job. We dump the temporary files on the remote side and make sure a console file for that job isn't present. Change-Id: I823156dc2bcae91bd6d9770bd1520aa55ad875b4
Diffstat (limited to 'zuul')
-rw-r--r--zuul/ansible/base/callback/zuul_stream.py10
-rwxr-xr-xzuul/ansible/base/library/zuul_console.py22
2 files changed, 26 insertions, 6 deletions
diff --git a/zuul/ansible/base/callback/zuul_stream.py b/zuul/ansible/base/callback/zuul_stream.py
index d33b4dda0..f31983ed6 100644
--- a/zuul/ansible/base/callback/zuul_stream.py
+++ b/zuul/ansible/base/callback/zuul_stream.py
@@ -211,6 +211,16 @@ class CallbackModule(default.CallbackModule):
done = self._log_streamline(
host, line.decode("utf-8", "backslashreplace"))
if done:
+ if self._zuul_console_version > 0:
+ try:
+ # reestablish connection and tell console to
+ # clean up
+ s = self._read_log_connect(host, ip, port)
+ s.send(f'f:{log_id}\n'.encode('utf-8'))
+ s.close()
+ except Exception:
+ # Don't worry if this fails
+ pass
return
else:
more = s.recv(4096)
diff --git a/zuul/ansible/base/library/zuul_console.py b/zuul/ansible/base/library/zuul_console.py
index bd23d5f49..f8e4e1e6a 100755
--- a/zuul/ansible/base/library/zuul_console.py
+++ b/zuul/ansible/base/library/zuul_console.py
@@ -174,11 +174,17 @@ class Server(object):
except UnicodeDecodeError:
pass
+ def _clean_uuid(self, log_uuid):
+ # use path split to make use the input isn't trying to be clever
+ # and construct some path like /tmp/console-/../../something
+ return os.path.split(log_uuid)[-1]
+
def handleOneConnection(self, conn):
# V1 protocol
# -----------
# v:<ver> get version number, <ver> is remote version
# s:<uuid> send logs for <uuid>
+ # f:<uuid> finalise/cleanup <uuid>
while True:
command = self.get_command(conn)
if command.startswith('v:'):
@@ -187,8 +193,16 @@ class Server(object):
# for now.
conn.send(f'{ZUUL_CONSOLE_PROTO_VERSION}\n'.encode('utf-8'))
continue
+ elif command.startswith('f:'):
+ log_uuid = self._clean_uuid(command[2:])
+ try:
+ os.unlink(self.path.format(log_uuid=log_uuid))
+ except Exception:
+ # something might have cleaned /tmp
+ pass
+ continue
elif command.startswith('s:'):
- log_uuid = command[2:]
+ log_uuid = self._clean_uuid(command[2:])
break
else:
# NOTE(ianw): 2022-07-21 In releases < 6.3.0 the streaming
@@ -196,13 +210,9 @@ class Server(object):
# default assume that is what is coming in here. We can
# remove this fallback when we decide it is no longer
# necessary.
- log_uuid = command
+ log_uuid = self._clean_uuid(command)
break
- # use path split to make use the input isn't trying to be clever
- # and construct some path like /tmp/console-/../../something
- log_uuid = os.path.split(log_uuid)[-1]
-
# FIXME: this won't notice disconnects until it tries to send
console = None
try: