Commit 8718c6d0 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

bugfix function not found

parent cf2d1261
......@@ -17,6 +17,58 @@
workdir=/scratch/resif_datadump/test_restore
archivedir=/osug-dc/resif/validated_seismic_data
function test_random_file {
echo === Extracting one random file ===
target_line=$(tar tvf latest.tar | grep -e '[0-9]$' | shuf -n 1)
target_file=$(echo "$target_line"| awk '{print $NF}')
echo $target_file
tar -xf latest.tar $target_file
target_file_date=$(date +%s -d $(stat $target_file --print %z | awk '{print $1}'))
fname=$(echo $target_file | awk -F'/' '{print $NF}')
echo $fname
regex="([A-Z0-9]+)\.([A-Z]+)\.[A-Z0-9]*\.([A-Z0-9]{3}\.D)\.([12][0-9]{3})\.[0-3][0-9]{2}"
archive_file=""
if [[ $fname =~ $regex ]]; then
archive_file="$archivedir/${BASH_REMATCH[4]}/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]}/$fname";
if [[ ! -r $archive_file ]]; then
printf "\033[1;33mWARNING\033[0m $archive_file not preset\n"
exit 1
fi
fi
echo $archive_file
archive_file_date=$(date +%s -d $(stat $archive_file --print %z | awk '{print $1}'))
if [ $archive_file_date -gt $target_file_date ]; then
echo "File in archive is newer than remote file. Skipping md5 test"
else
echo === Checking md5 ===
dumped_md5=$(md5sum $target_file | awk '{print $1}')
data_md5=$(md5sum $archive_file | awk '{print $1}')
echo $dumped_md5 $target_file
echo $data_md5 $archive_file
if [[ $dumped_md5 == $data_md5 ]]; then
printf "\033[0;32mOK\033[0m $target_file md5 sum is correct\n"
else
printf "\033[0;31mError\033[0m Files $target_file and $archive_file mismatch\n"
exit 1
fi
fi
echo === Compare msi traces ===
dumped_msi=$(msi $target_file)
data_msi=$(msi $archive_file)
if [[ $(md5sum <<< $dumped_msi | awk '{print $1}') == $(md5sum <<< $data_msi | awk '{print $1}') ]]; then
printf "\033[0;32mOK\033[0m Traces match\n"
else
echo "Traces of remote file $target_file"
echo "$dumped_msi"
echo "Traces of local file $archive_file"
echo "$data_msi"
printf "\033[1;33mWARNING\033[0m Traces mismatch\n"
fi
}
if [[ $# -eq 0 ]]; then
# Pas de clé en paramètre, récupère un channel au hasard dans les métadonnées
line=$(wget -q -O - "http://ws.resif.fr/fdsnws/station/1/query?level=channel&format=text" | shuf -n 1)
......@@ -70,58 +122,7 @@ else
fi
nbtests=$(( $(tar -tf latest.tar | wc -l) / 10 ))
for i in $(seq nbtests); do
for i in $(seq $nbtests); do
test_random_file
done
function test_random_file {
echo === Extracting one random file ===
target_line=$(tar tvf latest.tar | grep -e '[0-9]$' | shuf -n 1)
target_file=$(echo "$target_line"| awk '{print $NF}')
echo $target_file
tar -xf latest.tar $target_file
target_file_date=$(date +%s -d $(stat $target_file --print %z | awk '{print $1}'))
fname=$(echo $target_file | awk -F'/' '{print $NF}')
echo $fname
regex="([A-Z0-9]+)\.([A-Z]+)\.[A-Z0-9]*\.([A-Z0-9]{3}\.D)\.([12][0-9]{3})\.[0-3][0-9]{2}"
archive_file=""
if [[ $fname =~ $regex ]]; then
archive_file="$archivedir/${BASH_REMATCH[4]}/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]}/$fname";
if [[ ! -r $archive_file ]]; then
printf "\033[1;33mWARNING\033[0m $archive_file not preset\n"
exit 1
fi
fi
echo $archive_file
archive_file_date=$(date +%s -d $(stat $archive_file --print %z | awk '{print $1}'))
if [ $archive_file_date -gt $target_file_date ]; then
echo "File in archive is newer than remote file. Skipping md5 test"
else
echo === Checking md5 ===
dumped_md5=$(md5sum $target_file | awk '{print $1}')
data_md5=$(md5sum $archive_file | awk '{print $1}')
echo $dumped_md5 $target_file
echo $data_md5 $archive_file
if [[ $dumped_md5 == $data_md5 ]]; then
printf "\033[0;32mOK\033[0m $target_file md5 sum is correct\n"
else
printf "\033[0;31mError\033[0m Files $target_file and $archive_file mismatch\n"
exit 1
fi
fi
echo === Compare msi traces ===
dumped_msi=$(msi $target_file)
data_msi=$(msi $archive_file)
if [[ $(md5sum <<< $dumped_msi | awk '{print $1}') == $(md5sum <<< $data_msi | awk '{print $1}') ]]; then
printf "\033[0;32mOK\033[0m Traces match\n"
else
echo "Traces of remote file $target_file"
echo "$dumped_msi"
echo "Traces of local file $archive_file"
echo "$data_msi"
printf "\033[1;33mWARNING\033[0m Traces mismatch\n"
fi
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment