From 55d8b358b69f244f3a774de0ae7561feee40d36b Mon Sep 17 00:00:00 2001 From: fbarreir Date: Mon, 4 Nov 2024 12:11:04 +0100 Subject: [PATCH 1/4] Fixing the log upload --- pandaserver/userinterface/Client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pandaserver/userinterface/Client.py b/pandaserver/userinterface/Client.py index 812bb13f..005fe2cf 100755 --- a/pandaserver/userinterface/Client.py +++ b/pandaserver/userinterface/Client.py @@ -142,7 +142,15 @@ def post_files(self, url, data): files = {} try: - files = {key: open(value, "rb") for key, value in data.items()} + for key, value in data.items(): + if type(data[key]) == str: + # we got a file to upload without specifying the destination name + files[key] = open(data[key], "rb") + else: + # we got a file to upload which specifies the destination name + files[key] = (data[key][0], open(data[key][1], "rb")) + + file = {key: open(value, "rb") for key, value in data.items()} print(f"cert: {cert}, verify: {verify}") response = requests.post(url, headers=headers, files=files, timeout=600, cert=cert, verify=verify) response.raise_for_status() @@ -921,7 +929,7 @@ def uploadLog(logStr, logFileName): gfh.close() # execute url = f"{baseURLSSL}/uploadLog" - data = {"file": f"{fh.name};filename={logFileName}"} + data = {"file": (logFileName, fh.name)} retVal = http_client.post_files(url, data) os.unlink(fh.name) return retVal From 77a3aa9f1a7d891b4b4b06af9ec584178a0aae86 Mon Sep 17 00:00:00 2001 From: fbarreir Date: Mon, 4 Nov 2024 12:46:38 +0100 Subject: [PATCH 2/4] Fixing the log upload --- pandaserver/userinterface/Client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandaserver/userinterface/Client.py b/pandaserver/userinterface/Client.py index 005fe2cf..82205277 100755 --- a/pandaserver/userinterface/Client.py +++ b/pandaserver/userinterface/Client.py @@ -149,8 +149,6 @@ def post_files(self, url, data): else: # we got a file to upload which specifies the destination name files[key] = (data[key][0], open(data[key][1], "rb")) - - file = {key: open(value, "rb") for key, value in data.items()} print(f"cert: {cert}, verify: {verify}") response = requests.post(url, headers=headers, files=files, timeout=600, cert=cert, verify=verify) response.raise_for_status() @@ -159,7 +157,11 @@ def post_files(self, url, data): return 255, str(e) finally: for file in files.values(): - file.close() + if type(file) == tuple: + file_handler = file[1] + else: + file_handler = file + file_handler.close() """ From 07c9abdec704cd5ede00ab676c7a5860b87cc6aa Mon Sep 17 00:00:00 2001 From: fbarreir Date: Mon, 4 Nov 2024 12:55:42 +0100 Subject: [PATCH 3/4] Fixing the log upload --- pandaserver/userinterface/Client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandaserver/userinterface/Client.py b/pandaserver/userinterface/Client.py index 82205277..12e06b1c 100755 --- a/pandaserver/userinterface/Client.py +++ b/pandaserver/userinterface/Client.py @@ -931,7 +931,8 @@ def uploadLog(logStr, logFileName): gfh.close() # execute url = f"{baseURLSSL}/uploadLog" - data = {"file": (logFileName, fh.name)} + # sometimes the logFileName comes as an integer (e.g. a JEDI task ID) and it needs to be converted to a string + data = {"file": (str(logFileName), fh.name)} retVal = http_client.post_files(url, data) os.unlink(fh.name) return retVal From ea997a68a436762151deb0f39ad1bfd98eff677a Mon Sep 17 00:00:00 2001 From: fbarreir Date: Mon, 4 Nov 2024 13:02:21 +0100 Subject: [PATCH 4/4] Fixing the log upload --- pandaserver/userinterface/Client.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandaserver/userinterface/Client.py b/pandaserver/userinterface/Client.py index 12e06b1c..03f1cfc2 100755 --- a/pandaserver/userinterface/Client.py +++ b/pandaserver/userinterface/Client.py @@ -9,6 +9,7 @@ import socket import sys import tempfile +from cgi import logfile import requests from pandacommon.pandautils.net_utils import replace_hostname_in_url_randomly @@ -931,11 +932,12 @@ def uploadLog(logStr, logFileName): gfh.close() # execute url = f"{baseURLSSL}/uploadLog" - # sometimes the logFileName comes as an integer (e.g. a JEDI task ID) and it needs to be converted to a string - data = {"file": (str(logFileName), fh.name)} - retVal = http_client.post_files(url, data) + # sometimes the destination file name (=logFileName) comes as an integer (e.g. a JEDI task ID) and it needs to be converted to a string + logFileName = str(logFileName) + data = {"file": (logFileName, fh.name)} + return_value = http_client.post_files(url, data) os.unlink(fh.name) - return retVal + return return_value def changeTaskPriority(jediTaskID, newPriority):