From 03acdd0e059db34101eb560b5cbc31687267883d Mon Sep 17 00:00:00 2001 From: "W. David Dagenhart" Date: Thu, 6 Jul 2023 17:44:50 +0200 Subject: [PATCH] Fix error code on file open error with test --- FWCore/Catalog/src/FileLocator.cc | 10 ++++++ 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 ++++++++++ 9 files changed, 108 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/FWCore/Catalog/src/FileLocator.cc b/FWCore/Catalog/src/FileLocator.cc index b22acebe754eb..80340ae1b8e9f 100644 --- a/FWCore/Catalog/src/FileLocator.cc +++ b/FWCore/Catalog/src/FileLocator.cc @@ -1,5 +1,6 @@ #include "FWCore/Catalog/interface/FileLocator.h" #include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Utilities/interface/Exception.h" #include #include @@ -295,6 +296,15 @@ namespace edm { m_prefix = found_protocol->second.get("prefix", kEmptyString); if (m_prefix == kEmptyString) { //get rules + if (found_protocol->second.find("rules") == found_protocol->second.not_found()) { + cms::Exception ex("FileCatalog"); + ex << "protocol must contain either a prefix or rules, " + << "neither found for protocol \"" << aCatalog.protocol << "\" for the storage site \"" + << aCatalog.storageSite << "\" and volume \"" << aCatalog.volume + << "\" in storage.json. Check site-local-config.xml and storage.json"; + ex.addContext("edm::FileLocator:init()"); + throw ex; + } const pt::ptree& rules = found_protocol->second.find("rules")->second; //loop over rules for (pt::ptree::value_type const& storageRule : rules) { 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) +)