CE-cms-basic 8.78 KB
Newer Older
1
#!/bin/bash
Andrea Sciaba's avatar
Andrea Sciaba committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# CE-cms-basic
#
# This test does the following things:
# - looks for the software area
# - sources the CMS environment and checks for errors
# - checks that CMS_PATH is defined
# - checks that the Site Local Config (SLC) exists
# - checks that the SLC defines: TFC, local stageout, sitename and Frontier
# - checks that the TFC exists
#
# String exit codes:
# SW_DIR_UNDEF: location of CMS software directory undefined
# SW_DIR_NOT_READABLE: CMS software directory not existent or unreadable
# NO_SETUP_SCRIPT: could not source cmsset_default.sh
# CMS_PATH_UNDEF: CMS_PATH is undefined
# NO_JOBCONFIG_DIR: ${CMS_PATH}/SITECONF/local/JobConfig does not exist
# NO_SITELOCALCONFIG:
#   ${CMS_PATH}/SITECONF/local/JobConfig/site-local-config.xml does not exist
# NO_TFC: TFC information missing
# NO_LOCALSTAGEOUT: LocalStageOut information missing
# NO_SITENAME: Site name not found
# NO_FRONTIER_CONFIG: FroNtier information missing
Andrea Sciaba's avatar
Andrea Sciaba committed
25
# LOCAL_SITE_CONF_GIT_ERROR: site-local-config.xml different from GIT version
Andrea Sciaba's avatar
Andrea Sciaba committed
26
#   since more than 72 hours
Andrea Sciaba's avatar
Andrea Sciaba committed
27
# LOCAL_SITE_CONF_GIT_WARNING: site-local-config.xml different from GIT version
Andrea Sciaba's avatar
Andrea Sciaba committed
28
#   since less than 72 hours
Andrea Sciaba's avatar
Andrea Sciaba committed
29
30
31
# GIT_NO_ACCESS: cannot access GIT
# TFC_GIT_ERROR: TFC different from GIT version since more than 72 hours
# TFC_GIT_WARNING: TFC different from GIT version since less than 72 hours
Stefano Belforte's avatar
Stefano Belforte committed
32

33
info=0
34
note=0
35
36
37
warning=0
error=0

Andrea Sciaba's avatar
Andrea Sciaba committed
38
cp $SAME_SENSOR_HOME/tests/fetch-from-web-gitlab .
39

Andrea Sciaba's avatar
Andrea Sciaba committed
40
# Find software area
Andrea Sciaba's avatar
Andrea Sciaba committed
41
if [ -n "$OSG_GRID" ] ; then
42
    [ -f $OSG_GRID/setup.sh ] && source $OSG_GRID/setup.sh
Andrea Sciaba's avatar
Andrea Sciaba committed
43
44
    if [ -d $OSG_APP/cmssoft/cms ] ; then
	SW_DIR=$OSG_APP/cmssoft/cms
Andrea Sciaba's avatar
Andrea Sciaba committed
45
    elif [ -d $CVMFS/cms.cern.ch ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
46
	SW_DIR=$CVMFS/cms.cern.ch
Andrea Sciaba's avatar
Andrea Sciaba committed
47
    elif [ -d /cvmfs/cms.cern.ch ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
48
	SW_DIR=/cvmfs/cms.cern.ch
Andrea Sciaba's avatar
Andrea Sciaba committed
49
    else
Andrea Sciaba's avatar
Andrea Sciaba committed
50
51
52
	echo "ERROR: Cannot find CMS software in OSG node"
	echo "summary: SW_DIR_UNDEF"
	exit $SAME_ERROR
Andrea Sciaba's avatar
Andrea Sciaba committed
53
    fi
54
55
elif [ -n "$VO_CMS_SW_DIR" ] ; then
    SW_DIR=$VO_CMS_SW_DIR
Andrea Sciaba's avatar
Andrea Sciaba committed
56
else
57
    SW_DIR=/cvmfs/cms.cern.ch
Andrea Sciaba's avatar
Andrea Sciaba committed
58
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
59
60
if [ ! -d $SW_DIR ] ; then
    echo "SwArea: $SW_DIR"
Andrea Sciaba's avatar
Andrea Sciaba committed
61
    echo "ERROR: software directory non existent or non readable"
Andrea Sciaba's avatar
Andrea Sciaba committed
62
    echo "summary: SW_DIR_NOT_READABLE"
63
64
65
    exit $SAME_ERROR
fi

Andrea Sciaba's avatar
Andrea Sciaba committed
66
67
68
69
# Source CMS environment
echo
echo "Printing CMS site local config information..."
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
70
echo Hostname: `hostname`
Andrea Sciaba's avatar
Andrea Sciaba committed
71
tmpfile=`mktemp /tmp/tmp.XXXXXXXXXX`
72
echo "SCRAM_ARCH: $SCRAM_ARCH"
Andrea Sciaba's avatar
Andrea Sciaba committed
73
source $SW_DIR/cmsset_default.sh > $tmpfile 2>&1
Stefano Belforte's avatar
Stefano Belforte committed
74
result=$?
75
echo "SCRAM_ARCH: $SCRAM_ARCH"
Andrea Sciaba's avatar
Andrea Sciaba committed
76
77
78
if [ $result != 0 ] ; then
    cat $tmpfile
    rm -f $tmpfile
Andrea Sciaba's avatar
Andrea Sciaba committed
79
    echo "ERROR: CMS software initialisation script cmsset_default.sh failed"
Andrea Sciaba's avatar
Andrea Sciaba committed
80
    echo "summary: NO_SETUP_SCRIPT"
Stefano Belforte's avatar
Stefano Belforte committed
81
82
    exit $SAME_ERROR
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
83
rm -f $tmpfile
Stefano Belforte's avatar
Stefano Belforte committed
84

Andrea Sciaba's avatar
Andrea Sciaba committed
85
if [ -z "$CMS_PATH" ]; then
Andrea Sciaba's avatar
Andrea Sciaba committed
86
    echo "ERROR: CMS_PATH not defined"
Andrea Sciaba's avatar
Andrea Sciaba committed
87
    echo "summary: CMS_PATH_UNDEF"
Stefano Belforte's avatar
Stefano Belforte committed
88
89
    exit $SAME_ERROR
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
90
echo "CMS_PATH: $CMS_PATH"
Stefano Belforte's avatar
Stefano Belforte committed
91
92

if [ ! -d $CMS_PATH ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
93
    echo "ERROR: CMS_PATH directory $CMS_PATH not existing"
Andrea Sciaba's avatar
Andrea Sciaba committed
94
    echo "summary: NO_CMS_PATH"
Stefano Belforte's avatar
Stefano Belforte committed
95
96
97
    exit $SAME_ERROR
fi

Andrea Sciaba's avatar
Andrea Sciaba committed
98
if [ ! -d ${CMS_PATH}/SITECONF/local/JobConfig ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
99
    echo "ERROR: JobConfig directory $CMS_PATH/SITECONF/local/JobConfig not existing"
Andrea Sciaba's avatar
Andrea Sciaba committed
100
    echo "summary: NO_JOBCONFIG_DIR"
Stefano Belforte's avatar
Stefano Belforte committed
101
102
    exit $SAME_ERROR
fi
103

Stefano Belforte's avatar
Stefano Belforte committed
104
ConfigFile=${CMS_PATH}/SITECONF/local/JobConfig/site-local-config.xml
Andrea Sciaba's avatar
Andrea Sciaba committed
105
echo "SiteLocalConfig: $ConfigFile"
Stefano Belforte's avatar
Stefano Belforte committed
106
107

if [ ! -f $ConfigFile ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
108
    echo "ERROR: Local Configuration file site-local-config.xml not existing"
Andrea Sciaba's avatar
Andrea Sciaba committed
109
    echo "summary: NO_SITELOCALCONFIG"
Stefano Belforte's avatar
Stefano Belforte committed
110
111
    exit $SAME_ERROR
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
112

Andrea Sciaba's avatar
Andrea Sciaba committed
113
TFCPath=`sed -nr '/trivialcatalog_file/s/.*:(.+)\?.*$/\1/p' $ConfigFile | uniq`
Stefano Belforte's avatar
Stefano Belforte committed
114
115
status=$?
if [ $status != 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
116
    echo "ERROR: TrivialFileCatalog string missing"
117
118
    errorSummary="summary: NO_TFC"
    error=1
Andrea Sciaba's avatar
Andrea Sciaba committed
119
120
else
    echo "TFCPath: $TFCPath"
Stefano Belforte's avatar
Stefano Belforte committed
121
122
123
124
125
fi

grep -q "local-stage-out" $ConfigFile
status=$?
if [ $status != 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
126
    echo "<p>ERROR: LocalStageOut string missing</p>"
127
128
    errorSummary="summary: NO_LOCALSTAGEOUT"
    error=1
Stefano Belforte's avatar
Stefano Belforte committed
129
130
fi

Andrea Sciaba's avatar
Andrea Sciaba committed
131
SiteName=`sed -nr '/<site name/s/^.*\"(.*)\".*$/\1/p' $ConfigFile`
132
133
status=$?
if [ $status != 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
134
135
    echo "ERROR: site name string missing"
    errorSummary="summary: NO_SITENAME"
136
    error=1
Andrea Sciaba's avatar
Andrea Sciaba committed
137
138
139
140
141
142
143
144
145
else
    echo "SiteName: $SiteName"
fi

subSiteName=""
subSiteName=`grep "subsite name" $ConfigFile | cut -d'"' -f2`
if [ -n "$subSiteName" ] ; then
    echo "SubSiteName: $subSiteName"
    subSiteName=_$subSiteName
146
147
fi

Stefano Belforte's avatar
Stefano Belforte committed
148
149
150
grep -q "frontier-connect" $ConfigFile
status=$?
if [ $status != 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
151
    echo "ERROR: Frontier Configuration string missing"
152
153
    errorSummary="summary: NO_FRONTIER_CONFIG"
    error=1
Stefano Belforte's avatar
Stefano Belforte committed
154
155
fi

156
if [ $error == 1 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
157
    echo "ERROR: invalid local configuration file $ConfigFile"
158
    echo $errorSummary
Andrea Sciaba's avatar
Andrea Sciaba committed
159
    exit $SAME_ERROR
Stefano Belforte's avatar
Stefano Belforte committed
160
fi
161

162
163
let seconds=`date +%s`-`stat -c%Y $ConfigFile`
let localConfigFileAgeInHours=$seconds/3600
Andrea Sciaba's avatar
Andrea Sciaba committed
164
echo "SiteLocalConfigAge: ${localConfigFileAgeInHours} hours"
165
166

asCvs=1
167
cvsUrl="https://gitlab.cern.ch/SITECONF/${SiteName}/raw/master/JobConfig/site-local-config${subSiteName}.xml"
168
ConfigFileFromCVS=`mktemp /tmp/site-local-config-from-CVS.xml.XXX`
Andrea Sciaba's avatar
Andrea Sciaba committed
169
echo "GITCopy: $cvsUrl"
Andrea Sciaba's avatar
Andrea Sciaba committed
170
./fetch-from-web-gitlab \"$cvsUrl\" $ConfigFileFromCVS
171
rc=$?
Andrea Sciaba's avatar
Andrea Sciaba committed
172
if [ $rc == 0 ] ; then
173
  diff -q -w -B $ConfigFile $ConfigFileFromCVS
174
175
  if [ $? == 1 ] ; then asCvs=0; fi
  if [ $asCvs == 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
176
    noConfigDump=1
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    cvsMarkupUrl="https://gitlab.cern.ch/SITECONF/${SiteName}/blob/master/JobConfig/site-local-config${subSiteName}.xml"
    ConfigFileMarkup=`mktemp /tmp/site-local-config-from-CVS-Markup.xml.XXX`
    ./fetch-from-web-gitlab \"$cvsMarkupUrl\" $ConfigFileMarkup
    cvsFileDate=`/bin/awk '{i=index($0,"datetime=");if(i>0){s=substr($0,i+10,4) "-" substr($0,i+15,2) "-" substr($0,i+18,2) " " substr($0,i+21,2) ":" substr($0,i+24,2) ":" substr($0,i+27,2) "Z";print s}}' $ConfigFileMarkup`
    let seconds=`date +%s`-`date +%s -d "$cvsFileDate"`
    let cvsFileAgeInHours=$seconds/3600
    echo "GITConfigFileAge: ${cvsFileAgeInHours} hours"
    if [ $localConfigFileAgeInHours -gt 120 ] && [ $cvsFileAgeInHours -gt 120 ] ; then
      error=1
      echo "ERROR: local site configuration file differ from GIT"
      errorSummary="summary: LOCAL_SITE_CONF_GIT_ERROR"
    else
      warning=1
      echo "WARNING: local site configuration file differ from GIT"
      errorSummary="summary: LOCAL_SITE_CONF_GIT_WARNING"
    fi
193
194
    diffList=`mktemp /tmp/diflist.XXXX`
    diff $ConfigFile $ConfigFileFromCVS > $diffList
Andrea Sciaba's avatar
Andrea Sciaba committed
195
    cat $diffList | sed 's/</\&lt;/g' | sed 's/>/\&gt;/g'
196
    rm -f $diffList
197
  else
Andrea Sciaba's avatar
Andrea Sciaba committed
198
    echo "Site Local Config GIT check: OK"
199
  fi
200
  rm -f $ConfigFileFromCVS
201
else
Andrea Sciaba's avatar
Andrea Sciaba committed
202
  echo "WARNING: failed to access GIT repository via Gitlab"
Andrea Sciaba's avatar
Andrea Sciaba committed
203
  errorSummary="summary: GIT_NO_ACCESS"
204
  note=1
205
fi
206

Andrea Sciaba's avatar
Andrea Sciaba committed
207
let seconds=`date +%s`-`stat -c%Y $TFCPath`
208
let localTFCfileAgeInHours=$seconds/3600
Andrea Sciaba's avatar
Andrea Sciaba committed
209
echo "LocalTFCAge: ${localTFCfileAgeInHours} hours"
210

211
asCvs=1
Andrea Sciaba's avatar
Andrea Sciaba committed
212
TFCfileName=`echo $TFCPath | awk -F'/' '{print $NF}'`
213
cvsUrl="https://gitlab.cern.ch/SITECONF/${SiteName}/raw/master/PhEDEx/${TFCfileName}"
214
TfcFileFromCVS=`mktemp /tmp/storage-from-CVS.xml.XXXX`
Andrea Sciaba's avatar
Andrea Sciaba committed
215
echo "TFCGITCopy: $cvsUrl"
Andrea Sciaba's avatar
Andrea Sciaba committed
216
./fetch-from-web-gitlab \"$cvsUrl\" $TfcFileFromCVS
217
rc=$?
218

Andrea Sciaba's avatar
Andrea Sciaba committed
219
220
if [ $rc == 0 ] ; then
  diff -q -w -B $TFCPath $TfcFileFromCVS
221
222
  if [ $? == 1 ] ; then asCvs=0; fi
  if [ $asCvs == 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
223
    noTFCDump=1
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    cvsMarkupUrl="https://gitlab.cern.ch/SITECONF/${SiteName}/blob/master/PhEDEx/${TFCfileName}"
    TfcFileMarkup=`mktemp /tmp/TFC-from-CVS-Markup.xml.XXX`
    echo "Fetch GIT Markup copy of TFC from $cvsMarkupUrl"
    ./fetch-from-web-gitlab \"$cvsMarkupUrl\" $TfcFileMarkup
    cvsFileDate=`/bin/awk '{i=index($0,"datetime=");if(i>0){s=substr($0,i+10,4) "-" substr($0,i+15,2) "-" substr($0,i+18,2) " " substr($0,i+21,2) ":" substr($0,i+24,2) ":" substr($0,i+27,2) "Z";print s}}' $TfcFileMarkup`
    let seconds=`date +%s`-`date +%s -d "$cvsFileDate"`
    let cvsFileAgeInHours=$seconds/3600
    echo "GITTFCAge: ${cvsFileAgeInHours} hours"
    if [ $localTFCfileAgeInHours -gt 120 ] && [ $cvsFileAgeInHours -gt 120 ] ; then
      error=1
      echo "ERROR: local Trivial Catalog File file differ from GIT"
      errorSummary="summary: TFC_GIT_ERROR"
    else
      warning=1
      echo "WARNING: local Trivial Catalog File file differ from GIT"
      errorSummary="summary: TFC_GIT_WARNING"
    fi
241
    diffList=`mktemp /tmp/diflist.XXXX`
Andrea Sciaba's avatar
Andrea Sciaba committed
242
243
    diff $TFCPath $TfcFileFromCVS > $diffList
    cat $diffList | sed 's/</\&lt;/g' | sed 's/>/\&gt;/g'
244
    rm -f $diffList
245
  else
Andrea Sciaba's avatar
Andrea Sciaba committed
246
    echo "TFC GIT check: OK"
247
  fi
248
  rm -f $TfcFileFromCVS
249
else
Andrea Sciaba's avatar
Andrea Sciaba committed
250
  echo "WARNING: failed to access GIT repository via Gitlab"
Andrea Sciaba's avatar
Andrea Sciaba committed
251
  errorSummary="summary: GIT_NO_ACCESS"
252
  note=1
253
fi
254

Andrea Sciaba's avatar
Andrea Sciaba committed
255
if [ -n "$noConfigDump" ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
256
257
echo "Site Local Config dump:"
cat $ConfigFile
Andrea Sciaba's avatar
Andrea Sciaba committed
258
fi
259

Andrea Sciaba's avatar
Andrea Sciaba committed
260
if [ -n "$noTFCDump" ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
261
262
echo "TFC dump:"
cat $TFCPath
Andrea Sciaba's avatar
Andrea Sciaba committed
263
fi
264

265
266
if [ $error == 1 ]
then
Andrea Sciaba's avatar
Andrea Sciaba committed
267
    echo $errorSummary
268
269
270
271
272
  exit $SAME_ERROR
fi

if [ $warning == 1 ]
then
Andrea Sciaba's avatar
Andrea Sciaba committed
273
  echo $errorSummary
274
  exit $SAME_WARNING
275
fi
Stefano Belforte's avatar
Stefano Belforte committed
276

277
278
if [ $note == 1 ]
then
Andrea Sciaba's avatar
Andrea Sciaba committed
279
  echo $errorSummary
Andrea Sciaba's avatar
Andrea Sciaba committed
280
  exit $SAME_WARNING
281
282
fi

283
284
if [ $info == 1 ]
then
Andrea Sciaba's avatar
Andrea Sciaba committed
285
  echo "summary: OK"
Andrea Sciaba's avatar
Andrea Sciaba committed
286
  exit $SAME_OK
287
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
288
289
echo
echo "All checks OK"
Andrea Sciaba's avatar
Andrea Sciaba committed
290
echo "summary: OK"
Stefano Belforte's avatar
Stefano Belforte committed
291
exit $SAME_OK