Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-15 23:40:28

0001 #!/bin/env bash
0002 # Simple test to use one of the files generated by TestDQMServicesDemo test
0003 # to upload it to the dev DQMGUI, making sure that the ROOT file format generated
0004 # is compatible. See cmssw issue #43590.
0005 # Requires curl and jq to be installed. Also requires either a Grid key and certificate,
0006 # or a proxy to be available.
0007 set -x
0008 set -e
0009 
0010 force=0
0011 
0012 function usage() {
0013     echo "Usage: $0 [--help] [--force]"
0014 }
0015 
0016 # Parse args, if any.
0017 while [[ "$#" -gt 0 ]]; do
0018     case $1 in
0019     --force)
0020         force=1
0021         shift
0022         ;;
0023     --help)
0024         usage
0025         exit 0
0026         ;;
0027     *)
0028         echo "Unknown parameter passed: $1"
0029         usage
0030         exit 1
0031         ;;
0032     esac
0033 done
0034 
0035 # Don't run the test unless it's run by the bot for PRs or IBs.
0036 # The user may force it by adding --force
0037 if [ -z "$CMSBOT_CI_TESTS" ] && [ "$force" -ne 1 ]; then
0038     echo "Non-automated test environment, skipping test."
0039     exit 0
0040 fi
0041 
0042 DEV_DQMGUI_URL="https://cmsweb.cern.ch/dqm/dev"
0043 # Create a unique fake "Era", so that different executions of this test
0044 # produce differently named files. This is required, because this test might pass
0045 # if it's checking a file that was successfully uploaded during a previous
0046 # instance of the same test.
0047 UNIQUE_ERA_ID=$(date -u +%Y%m%d%H%M%S%N)
0048 OLD_FILENAME=DQM_V0001_R000000001__Harvesting__DQMTests__DQMIO.root
0049 NEW_FILENAME=${OLD_FILENAME/DQMTests/DQMTests${UNIQUE_ERA_ID}}
0050 
0051 # Make sure the required file exists. We expect to find it in the current directory.
0052 if [ ! -f $OLD_FILENAME ]; then
0053     echo "Unable to find required file ${OLD_FILENAME}!"
0054     exit 1
0055 fi
0056 
0057 # Prepare curl args
0058 curl_args=""
0059 if [ -n "$X509_CERT_DIR" ]; then
0060     curl_args="${curl_args} --capath ${X509_CERT_DIR}/"
0061 else
0062     curl_args="${curl_args} -k"
0063 fi
0064 if [ -n "$X509_USER_PROXY" ]; then
0065     curl_args="${curl_args} --key ${X509_USER_PROXY} --cert ${X509_USER_PROXY}"
0066 elif [ -n "$X509_USER_KEY" ] && [ -n "$X509_USER_CERT" ]; then
0067     curl_args="${curl_args} --key ${X509_USER_KEY} --cert ${X509_USER_CERT}"
0068 elif [ -f $HOME/.globus/usercert.pem ] && [ -f $HOME/.globus/userkey.pem ]; then
0069     curl_args="${curl_args} --key $HOME/.globus/userkey.pem --cert $HOME/.globus/usercert.pem"
0070 else
0071     echo "Unable to find proxy or key/cert env vars, cannot continue"
0072     exit 1
0073 fi
0074 
0075 # Make a copy with a filename that conforms to the naming convention required by DQMGUI.
0076 rm -f "$NEW_FILENAME"
0077 cp $OLD_FILENAME "$NEW_FILENAME"
0078 
0079 # Upload the file to the DQMGUI
0080 visDQMUpload.py "$DEV_DQMGUI_URL" "$NEW_FILENAME"
0081 
0082 # Wait for a bit for the file to be imported into the DQMGUI's index.
0083 # The currently used file is very small and expected to be ingested quickly,
0084 # but better safe than sorry.
0085 SECONDS_TO_WAIT=600
0086 # Reset shell's internal SECONDS var.
0087 SECONDS=0
0088 
0089 while true; do
0090     # Wait for the dataset to appear in the /json/samples endpoint. It might take a while.
0091     if curl -sL $curl_args "${DEV_DQMGUI_URL}/data/json/samples?match=DQMTests${UNIQUE_ERA_ID}" | jq .samples[0].items[0].dataset | grep -q "$UNIQUE_ERA_ID"; then
0092         exit 0
0093     fi
0094 
0095     sleep 10
0096     # Timeout after SECONDS_TO_WAIT have passed.
0097     if [ $SECONDS -ge $SECONDS_TO_WAIT ]; then
0098         exit 1
0099     fi
0100 done
0101 exit 1