[e2e] improve output dir handling (#21906)

Try to clear the result dir before running the e2e.py script, to avoid failures where the directory already exists, or a file cannot be overwritten due to permission issue.
This commit is contained in:
mwtian 2022-01-26 23:56:08 -08:00 committed by GitHub
parent bdf9fa337d
commit 634f897cb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2125,16 +2125,22 @@ def run_test_config(
f"{out_dir}") f"{out_dir}")
try: try:
shutil.rmtree(out_dir, ignore_errors=True) shutil.rmtree(out_dir)
except Exception:
logger.exception(
f"Ran into error when clearing the destination dir: {out_dir}")
try:
# Use distutils.dir_util.copy_tree() instead of shutil.cptree(), # Use distutils.dir_util.copy_tree() instead of shutil.cptree(),
# which allows existing output directory. # which allows existing output directory.
from distutils.dir_util import copy_tree from distutils.dir_util import copy_tree
copy_tree(temp_dir, out_dir) copy_tree(temp_dir, out_dir)
logger.info(f"Dir contents: {os.listdir(out_dir)}") except Exception:
except Exception as e:
logger.exception( logger.exception(
"Ran into error when copying results dir to persistent " "Ran into error when copying results dir to persistent "
f"location: {str(e)}") f"location: {out_dir}")
logger.info(f"Dir contents: {os.listdir(out_dir)}")
return result return result