diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index c78830bd8..403034c72 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -271,30 +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) + 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()) - 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) + 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" @@ -302,6 +312,7 @@ def zip_results(self, if os.path.exists(zip_file) else'creation failed'}''') + return zip_file except Exception as error: # pylint: disable=W0703