From e1a3683a5ce9a8fc20f10c5d08c25cacd96954de Mon Sep 17 00:00:00 2001 From: "W. David Dagenhart" Date: Wed, 26 Jul 2023 17:50:26 +0200 Subject: [PATCH] Fix error code on file open error with test, 13_2_X backport --- IOPool/Input/src/RootInputFileSequence.cc | 5 +-- IOPool/Input/test/BuildFile.xml | 1 + .../noFallbackFile/local/storage.json | 10 ++++++ .../noFallbackFile/site-local-config.xml | 7 ++++ .../useFallbackFile/local/storage.json | 18 ++++++++++ .../useFallbackFile/site-local-config.xml | 8 +++++ .../Input/test/testFileOpenErrorExitCode.sh | 34 +++++++++++++++++++ .../test/test_fileOpenErrorExitCode_cfg.py | 17 ++++++++++ 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 IOPool/Input/test/sitelocalconfig/noFallbackFile/local/storage.json create mode 100644 IOPool/Input/test/sitelocalconfig/noFallbackFile/site-local-config.xml create mode 100644 IOPool/Input/test/sitelocalconfig/useFallbackFile/local/storage.json create mode 100644 IOPool/Input/test/sitelocalconfig/useFallbackFile/site-local-config.xml create mode 100755 IOPool/Input/test/testFileOpenErrorExitCode.sh create mode 100644 IOPool/Input/test/test_fileOpenErrorExitCode_cfg.py diff --git a/IOPool/Input/src/RootInputFileSequence.cc b/IOPool/Input/src/RootInputFileSequence.cc index fffe66091b18e..e2c4f71b5fc62 100644 --- a/IOPool/Input/src/RootInputFileSequence.cc +++ b/IOPool/Input/src/RootInputFileSequence.cc @@ -252,14 +252,15 @@ namespace edm { } for (std::vector::const_iterator it = fNames.begin(); it != fNames.end(); ++it) { try { + usedFallback_ = (it != fNames.begin()); std::unique_ptr name(gSystem->ExpandPathName(it->c_str())); filePtr = std::make_shared(name.get(), " Initiating request to open file ", inputType); - usedFallback_ = (it != fNames.begin()); break; } catch (cms::Exception const& e) { if (!skipBadFiles && std::next(it) == fNames.end()) { InputFile::reportSkippedFile((*it), logicalFileName()); - Exception ex(errors::FileOpenError, "", e); + errors::ErrorCodes errorCode = usedFallback_ ? errors::FallbackFileOpenError : errors::FileOpenError; + Exception ex(errorCode, "", e); ex.addContext("Calling RootInputFileSequence::initTheFile()"); std::ostringstream out; out << "Input file " << (*it) << " could not be opened."; diff --git a/IOPool/Input/test/BuildFile.xml b/IOPool/Input/test/BuildFile.xml index 04ff2c262a6ef..d1a545d67d8ce 100644 --- a/IOPool/Input/test/BuildFile.xml +++ b/IOPool/Input/test/BuildFile.xml @@ -9,4 +9,5 @@ + diff --git a/IOPool/Input/test/sitelocalconfig/noFallbackFile/local/storage.json b/IOPool/Input/test/sitelocalconfig/noFallbackFile/local/storage.json new file mode 100644 index 0000000000000..dad76a157c5b6 --- /dev/null +++ b/IOPool/Input/test/sitelocalconfig/noFallbackFile/local/storage.json @@ -0,0 +1,10 @@ +[ + { "site": "DUMMY", + "volume": "DummyVolume", + "protocols": [ + { "protocol": "protocolThatDoesNotExist", + "prefix": "abc" + } + ] + } +] diff --git a/IOPool/Input/test/sitelocalconfig/noFallbackFile/site-local-config.xml b/IOPool/Input/test/sitelocalconfig/noFallbackFile/site-local-config.xml new file mode 100644 index 0000000000000..4cd0590b4c036 --- /dev/null +++ b/IOPool/Input/test/sitelocalconfig/noFallbackFile/site-local-config.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/IOPool/Input/test/sitelocalconfig/useFallbackFile/local/storage.json b/IOPool/Input/test/sitelocalconfig/useFallbackFile/local/storage.json new file mode 100644 index 0000000000000..cc6950aacb008 --- /dev/null +++ b/IOPool/Input/test/sitelocalconfig/useFallbackFile/local/storage.json @@ -0,0 +1,18 @@ +[ + { "site": "DUMMY", + "volume": "DummyVolume1", + "protocols": [ + { "protocol": "protocolThatDoesNotExist1", + "prefix": "abc" + } + ] + }, + { "site": "DUMMY", + "volume": "DummyVolume2", + "protocols": [ + { "protocol": "protocolThatDoesNotExist2", + "prefix": "abc" + } + ] + } +] diff --git a/IOPool/Input/test/sitelocalconfig/useFallbackFile/site-local-config.xml b/IOPool/Input/test/sitelocalconfig/useFallbackFile/site-local-config.xml new file mode 100644 index 0000000000000..538412e075877 --- /dev/null +++ b/IOPool/Input/test/sitelocalconfig/useFallbackFile/site-local-config.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/IOPool/Input/test/testFileOpenErrorExitCode.sh b/IOPool/Input/test/testFileOpenErrorExitCode.sh new file mode 100755 index 0000000000000..9ce527d37dd5d --- /dev/null +++ b/IOPool/Input/test/testFileOpenErrorExitCode.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Pass in name and status +function die { echo $1: status $2 ; exit $2; } + +mkdir -p SITECONF +mkdir -p SITECONF/local +mkdir -p SITECONF/local/JobConfig + +export SITECONFIG_PATH=${PWD}/SITECONF/local +LOCAL_TEST_DIR=${SCRAM_TEST_PATH} + +cp ${LOCAL_TEST_DIR}/sitelocalconfig/noFallbackFile/site-local-config.xml ${SITECONFIG_PATH}/JobConfig/ +cp ${LOCAL_TEST_DIR}/sitelocalconfig/noFallbackFile/local/storage.json ${SITECONFIG_PATH}/ +F1=${LOCAL_TEST_DIR}/test_fileOpenErrorExitCode_cfg.py +cmsRun -j NoFallbackFile_jobreport.xml $F1 -- --input FileThatDoesNotExist.root && die "$F1 should have failed but didn't, exit code was 0" 1 + +CMSRUN_EXIT_CODE=$(edmFjrDump --exitCode NoFallbackFile_jobreport.xml) +echo "Exit code after first run of test_fileOpenErrorExitCode_cfg.py is ${CMSRUN_EXIT_CODE}" +if [ "x${CMSRUN_EXIT_CODE}" != "x8020" ]; then + echo "Unexpected cmsRun exit code after FileOpenError, exit code from jobReport ${CMSRUN_EXIT_CODE} which is different from the expected 8020" + exit 1 +fi + +cp ${LOCAL_TEST_DIR}/sitelocalconfig/useFallbackFile/site-local-config.xml ${SITECONFIG_PATH}/JobConfig/ +cp ${LOCAL_TEST_DIR}/sitelocalconfig/useFallbackFile/local/storage.json ${SITECONFIG_PATH}/ +cmsRun -j UseFallbackFile_jobreport.xml $F1 -- --input FileThatDoesNotExist.root && die "$F1 should have failed after file fallback but didn\'t, exit code was 0" 1 + +CMSRUN_EXIT_CODE=$(edmFjrDump --exitCode UseFallbackFile_jobreport.xml) +echo "Exit code after second run of test_fileOpenErrorExitCode_cfg.py is ${CMSRUN_EXIT_CODE}" +if [ "x${CMSRUN_EXIT_CODE}" != "x8028" ]; then + echo "Unexpected cmsRun exit code after FallbackFileOpenError, exit code from jobReport ${CMSRUN_EXIT_CODE} which is different from the expected 8028" + exit 1 +fi diff --git a/IOPool/Input/test/test_fileOpenErrorExitCode_cfg.py b/IOPool/Input/test/test_fileOpenErrorExitCode_cfg.py new file mode 100644 index 0000000000000..320f8cd84893e --- /dev/null +++ b/IOPool/Input/test/test_fileOpenErrorExitCode_cfg.py @@ -0,0 +1,17 @@ +import FWCore.ParameterSet.Config as cms +import argparse +import sys + +parser = argparse.ArgumentParser(prog=sys.argv[0], description="Test FileOpenErrorExitCode") +parser.add_argument("--input", type=str, default=[], nargs="*", help="Optional list of input files") + +argv = sys.argv[:] +if '--' in argv: + argv.remove("--") +args, unknown = parser.parse_known_args(argv) + +process = cms.Process("TEST") + +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring("/store/"+x for x in args.input) +)