Belle II Software  release-08-01-10
test_caf.py
1 
8 import json
9 import subprocess
10 
11 import basf2
12 import b2test_utils
13 import validation_gt as vgt
14 
15 
16 calibration_path = b2test_utils.require_file('calibration', 'validation')
17 
19 
20  # Prepare the configuration dictionary for CAF and dump it into a JSON file.
21  config = {
22  "caf_script": "caf_klm_channel_status.py",
23  "database_chain": [globaltag for globaltag in reversed(vgt.get_validation_globaltags())],
24  "requested_iov": [0, 0, -1, -1]
25  }
26  with open("config.json", "w") as config_json:
27  json.dump(config, config_json)
28 
29  # Prepare the input files for the calibration and dump them into a JSON file.
30  input_files = {
31  "raw_physics": [
32  [f"{calibration_path}/cdst_e0008_r3121_hadronSkim/", [8, 3121]],
33  [f"{calibration_path}/cdst_e0010_r5095_hadronSkim/", [10, 5095]]
34  ],
35  "raw_cosmic": [
36  [f"{calibration_path}/cdst_e0008_r3121_cosmicSkim/", [8, 3121]],
37  [f"{calibration_path}/cdst_e0010_r5095_cosmicSkim/", [10, 5095]]
38  ],
39  "raw_beam": []
40  }
41  with open("input_files.json", "w") as input_files_json:
42  json.dump(input_files, input_files_json)
43 
44  # Now simply run the calibration locally (on our CI/CD servers we can not test different backends).
45  try:
46  subprocess.check_call(['b2caf-prompt-run', 'Local', 'config.json', 'input_files.json', '--heartbeat', '20'])
47  except subprocess.CalledProcessError as e:
48  # In case of failure, prints all the BELLE2 environment variables...
50  # ... and the submit.sh...
51  sub_name = basf2.find_file('calibration_results/KLMChannelStatus/0/collector_output/raw/0/submit.sh', '', True)
52  if sub_name:
53  with open(sub_name) as sub_file:
54  basf2.B2ERROR('Calibration failed, here is the submit.sh of the first collector job.')
55  print(sub_file.read())
56  # ... and the stdout...
57  out_name = basf2.find_file('calibration_results/KLMChannelStatus/0/collector_output/raw/0/stdout', '', True)
58  if out_name:
59  with open(out_name) as out_file:
60  basf2.B2ERROR('Calibration failed, here is the stdout of the first collector job.')
61  print(out_file.read())
62  # ... and the stderr.
63  err_name = basf2.find_file('calibration_results/KLMChannelStatus/0/collector_output/raw/0/stderr', '', True)
64  if err_name:
65  with open(err_name) as err_file:
66  basf2.B2ERROR('Calibration failed, here is the stderr of the first collector job.')
67  print(err_file.read())
68  basf2.B2FATAL(
69  f'The test failed because an exception was raised ({e}). Please re-run the build if this failure happened on bamboo.')
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:189
def print_belle2_environment()
Definition: __init__.py:368