You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
osinfo-db-tests/osinfo-detect-test.sh

154 lines
3.8 KiB

11 months ago
#!/bin/bash
#----------------------------------------------------------------------
# Description: osinfo-detect-test.sh - Check msvsphere patches are working for osinfo-db
# Author: td25i <a.lyubimov@softline.com>
# Created at: Mon Dec 4 10:53:18 MSK 2023
# Computer: ii7
# System: Linux 5.14.0-362.8.1.el9_3.x86_64 on x86_64
#
# Copyright (c) 2023 Softline All rights reserved.
#
#----------------------------------------------------------------------
# Configure section:
# v0.1
dnf -y in curl util-linux gawk which libosinfo coreutils diffutils
# TODO check exit stats
FUNCTIONS_FILE=./functions
DOWNLOAD_LIST_FILENAME=msvsphereiso.uri
TEST_REFERENCE_RESULT_FILE=osinfo-detect-reference.result
TEST_OBTAINED_RESULT_FILE=osinfo-detect-obtained.result
echo "Getting meminfo..."
MEMFREEKB=`grep MemFree /proc/meminfo | sed 's/ kB//g' | sed 's/ //g' | cut -f 2 -d :`
echo "Getting free space in /var/tmp ..."
DISTFREEKB=`df --output=avail /var/tmp | tail -n 1`
echo "Calculating sum sizes of ISO files..."
MEMFREEREQBYTES=$(curl -s https://rsync.inferitos.ru/msvsphere/9/isos/x86_64/ grep href\=\"MSVSphere | rev | cut -f 1 -d \ | awk '{s+=$1}END{print s}')
MEMFREEREQKB=`echo "scale=0; $MEMFREEREQBYTES/1024" | bc`
echo "Need $MEMFREEREQKB kB."
echo "Checking free space for download ISO images..."
echo "Choosing a location to place files.."
if [[ $MEMFREEKB -lt $MEMFREEREQKB ]]
then
echo "With less RAM $MEMFREEKB kB, use /var/tmp"
WORK_DIR=`mktemp -d --suffix=.osinfo-db-tests -p /var/tmp`
else
echo "RAM is enough $MEMFREEKB kB, use /tmp"
WORK_DIR=`mktemp -d --suffix=.osinfo-db-tests`
fi
declare -a REF_TESTING_RESULTS=()
declare -a TESTING_RESULTS=()
cleantempdata()
{
rm -rv $1
}
# TODO
cp $DOWNLOAD_LIST_FILENAME $TEST_REFERENCE_RESULT_FILE $WORK_DIR/
if [[ -f $FUNCTIONS_FILE ]]
then
. $FUNCTIONS_FILE
else
echo "Error: file $FUNCTIONS_FILE not found, exiting..."
exit 1
fi
which basename || exitmsg "Error: basename not found, exiting..." $?
which sha256sum || exitmsg "Error: sha256sum not found, exiting..." $?
cd $WORK_DIR
cdcheck $? $REF_GIT_DIR
wgetdownload()
{
while read LINE; do
wget -c $LINE
wgetcheck $? $LINE
wget -c $LINE.CHECKSUM
wgetcheck $? $LINE.CHECKSUM
done < $1
}
if [[ -f $DOWNLOAD_LIST_FILENAME ]]
then
wgetdownload $DOWNLOAD_LIST_FILENAME
else
#cleantempdata $WORK_DIR
exitmsg "Error: file $DOWNLOAD_LIST_FILENAME not found, exiting..." 1
fi
if [[ ! -f $TEST_REFERENCE_RESULT_FILE ]]
then
cleantempdata $WORK_DIR
exitmsg "Error: file $TEST_REFERENCE_RESULT_FILE not found, exiting..." 1
fi
while read LINE; do
ITEM=`basename $LINE`
REF_TESTING_RESULTS+=("$ITEM")
done < $WORK_DIR/$DOWNLOAD_LIST_FILENAME
integrityverify()
{
while read LINE; do
ITEM=`basename $LINE`
sha256sum -c --ignore-missing $ITEM.CHECKSUM
if [[ ! $? == 0 ]]
then
cleantempdata $WORK_DIR
exitmsg "osinfo-detect-test.sh log: sha256sum failed for $ITEM, exiting..." $?
fi
echo "Verifying sha256sum of $ITEM successully completed."
done < $WORK_DIR/$DOWNLOAD_LIST_FILENAME
}
integrityverify
osinfodetect()
{
while read LINE; do
ITEM=`basename $LINE`
osinfo-detect $ITEM | tee $TEST_OBTAINED_RESULT_FILE
if [[ $? == 0 ]]
then
echo "Detecting of $ITEM completed without errors, starting comparing detected result with right value..."
diff -qsa $TEST_REFERENCE_RESULT_FILE $TEST_OBTAINED_RESULT_FILE
if [[ ! $? == 0 ]]
then
cleantempdata $WORK_DIR
exitmsg "Error: Testing osinfo-detect failed for $ITEM, exiting..." 1
else
echo "Testing osinfo-detect with "$ITEM" are successful."
TESTING_RESULTS+=("$ITEM")
fi
else
cleantempdata $WORK_DIR
exitmsg "osinfo-detect-test.sh log: osinfo-detect failed for $ITEM, exiting..." $?
fi
done < $WORK_DIR/$DOWNLOAD_LIST_FILENAME
}
osinfodetect
for I in "${REF_TESTING_RESULTS[@]}"
do
echo "Referenced item $I"
done
for I in "${TESTING_RESULTS[@]}"
do
echo "Tested item $I"
done
cleantempdata $WORK_DIR