summaryrefslogtreecommitdiff
path: root/site_scons/site_tools
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2022-01-19 16:32:33 -0600
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-24 22:12:26 +0000
commit021c3209622eb7e273e31424bdca2f70b964e1dc (patch)
tree943062f05a00a7444ee50e5a24c86ea4e8e4f33c /site_scons/site_tools
parentac8581ed35cb4d1dd20d4ac034bce6a2be868916 (diff)
downloadmongo-021c3209622eb7e273e31424bdca2f70b964e1dc.tar.gz
SERVER-62285 added processing of cache-dir push failures.
Diffstat (limited to 'site_scons/site_tools')
-rw-r--r--site_scons/site_tools/validate_cache_dir.py45
1 files changed, 22 insertions, 23 deletions
diff --git a/site_scons/site_tools/validate_cache_dir.py b/site_scons/site_tools/validate_cache_dir.py
index b1df5326eab..b5faee9b3e0 100644
--- a/site_scons/site_tools/validate_cache_dir.py
+++ b/site_scons/site_tools/validate_cache_dir.py
@@ -23,6 +23,7 @@
import datetime
import json
import os
+import sys
import pathlib
import shutil
import tempfile
@@ -93,8 +94,8 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
raise UnsupportedError(cls.__name__, "timestamp-newer")
src_file = cls.get_file_contents_path(src)
-
- if cls.get_bad_cachefile_path(src).exists():
+ # using os.path.exists here because: https://bugs.python.org/issue35306
+ if os.path.exists(str(cls.get_bad_cachefile_path(src))):
raise InvalidChecksum(cls.get_hash_path(src_file), dst, f"cachefile marked as bad checksum")
csig = None
@@ -129,10 +130,10 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
# dst is bsig/file from cachepath method, so
# we make sure to make the bsig dir first
dst = pathlib.Path(dst)
- os.makedirs(dst, exist_ok=True)
-
dst_file = dst / dst.name.split('.')[0]
+
try:
+ os.makedirs(dst, exist_ok=True)
super().copy_to_cache(env, src, dst_file)
except OSError as ex:
raise CacheTransferFailed(src, dst_file, f"failed to copy to cache: {ex}") from ex
@@ -198,33 +199,31 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
'cache_dir': str(pathlib.Path(cachefile).parent.parent),
})
+ # capture exception information
+ if sys.exc_info()[1]:
+ json_data.update({'error': self._format_exception_msg()})
+
self.json_log.write(json.dumps(json_data) + '\n')
def CacheDebug(self, fmt, target, cachefile):
- # The target cachefile will live in a directory with the special
- # extension for this cachedir class. Check if this cachefile is
- # in a directory like that and customize the debug logs.
- cksum_cachefile = str(pathlib.Path(cachefile).parent)
- if cksum_cachefile.endswith(self.get_ext()):
- super().CacheDebug(fmt, target, cksum_cachefile)
- else:
- super().CacheDebug(fmt, target, cachefile)
- def _log(self, msg, log_msg, json_info, realnode, cachefile):
- self.CacheDebug(log_msg + cache_debug_suffix, realnode, cachefile)
+ super().CacheDebug(fmt, target, cachefile)
+ # Capture exception information into the cache debug log
+ if sys.exc_info()[1] and self.debugFP:
+ self.debugFP.write(self._format_exception_msg())
+
+ def _format_exception_msg(self):
+ return ('An exception was detected while using the cache:\n' +
+ ' ' + "\n ".join("".join(traceback.format_exc()).split("\n"))) + '\n'
- # Write the exception and/or error info to the cache debug log file if in use.
- if self.debugFP:
- self.debugFP.write(msg + '\n')
+ def _log(self, log_msg, json_info, realnode, cachefile):
+ self.CacheDebug(log_msg + cache_debug_suffix, realnode, cachefile)
self.CacheDebugJson(json_info, realnode, cachefile)
def print_cache_issue(self, node, ex):
cksum_dir = pathlib.Path(self.cachepath(node)[1])
- msg = ('An issue was detected while validating the cache:\n' +
- ' ' + "\n ".join("".join(traceback.format_exc()).split("\n")))
-
- self._log(msg, str(ex), {'type': 'error', 'error': msg}, node, cksum_dir)
+ self._log(str(ex), {'type': 'error'}, node, cksum_dir)
def clean_bad_cachefile(self, node, cache_csig, computed_csig):
@@ -238,11 +237,11 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
cksum_dir.replace(rm_path)
except OSError as ex:
msg = f"Failed to rename {cksum_dir} to {rm_path}: {ex}"
- self._log(msg, msg, {'type': 'error', 'error': msg}, node, cksum_dir)
+ self._log(msg, {'type': 'error'}, node, cksum_dir)
return
msg = f"Removed bad cachefile {cksum_dir} found in cache."
- self._log(msg, msg, {
+ self._log(msg, {
'type': 'invalid_checksum',
'cache_csig': cache_csig,
'computed_csig': computed_csig