From 8a4356b22b9e3a26da2343b7d8ea87def84fdd17 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 4 Jul 2024 16:11:47 +0100 Subject: [PATCH 1/2] Remove profile after ZIP creation --- framework/python/src/test_orc/test_orchestrator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index c78830bd8..bc45ac533 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -272,7 +272,8 @@ def zip_results(self, timestamp) # Define where to save the zip file - zip_location = os.path.join('/tmp/testrun',timestamp) + zip_location = os.path.join("/tmp/testrun", + timestamp) # Delete ZIP if it already exists if os.path.exists(zip_location + ".zip"): @@ -290,9 +291,6 @@ def zip_results(self, with open(os.path.join(src_path, "profile.pdf"), "wb") as f: f.write(profile.to_pdf(device).getvalue()) - with open(os.path.join(src_path, "profile.html"), "w") as fp: - fp.write(profile.to_html(device)) - # Create ZIP archive shutil.make_archive(zip_location, "zip", src_path) @@ -302,6 +300,10 @@ def zip_results(self, if os.path.exists(zip_file) else'creation failed'}''') + # Remove the profile now that it has been included + os.remove(os.path.join(src_path, "profile.pdf")) + os.remove(os.path.join(src_path, "profile.json")) + return zip_file except Exception as error: # pylint: disable=W0703 From fdaee21d433c3afead6beef20b2507a641c0067d Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Mon, 8 Jul 2024 12:08:55 -0600 Subject: [PATCH 2/2] Create /tmp dir for results Copy test results and profile to results dir Zip results dir and cleanup --- .../python/src/test_orc/test_orchestrator.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index bc45ac533..403034c72 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -271,28 +271,40 @@ def zip_results(self, device.device_folder), timestamp) + # Define temp directory to store files before zipping + results_dir = os.path.join(f'/tmp/testrun/{time.time()}') + # Define where to save the zip file zip_location = os.path.join("/tmp/testrun", timestamp) + # Delete zip_temp if it already exists + if os.path.exists(results_dir): + os.remove(results_dir) + # Delete ZIP if it already exists if os.path.exists(zip_location + ".zip"): os.remove(zip_location + ".zip") + shutil.copytree(src_path,results_dir) + # Include profile if specified if profile is not None: LOGGER.debug( f"Copying profile {profile.name} to results directory") shutil.copy(profile.get_file_path(), os.path.join( - src_path, + results_dir, "profile.json")) - with open(os.path.join(src_path, "profile.pdf"), "wb") as f: + with open(os.path.join(results_dir, "profile.pdf"), "wb") as f: f.write(profile.to_pdf(device).getvalue()) # Create ZIP archive - shutil.make_archive(zip_location, "zip", src_path) + shutil.make_archive(zip_location, "zip", results_dir) + + # Delete the temp results directory + shutil.rmtree(results_dir) # Check that the ZIP was successfully created zip_file = zip_location + ".zip" @@ -300,9 +312,6 @@ def zip_results(self, if os.path.exists(zip_file) else'creation failed'}''') - # Remove the profile now that it has been included - os.remove(os.path.join(src_path, "profile.pdf")) - os.remove(os.path.join(src_path, "profile.json")) return zip_file