From 5b2b38254c2fb8402d41877529bcd7215d08fc34 Mon Sep 17 00:00:00 2001 From: Alexey Lyubimov Date: Wed, 6 Dec 2023 13:17:11 +0300 Subject: [PATCH] Initial commit --- README.md | 10 +++ functions | 92 ++++++++++++++++++++ msvsphereiso.uri | 5 ++ osinfo-detect-reference.result | 2 + osinfo-detect-test.sh | 153 +++++++++++++++++++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100644 README.md create mode 100644 functions create mode 100644 msvsphereiso.uri create mode 100644 osinfo-detect-reference.result create mode 100755 osinfo-detect-test.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bf3713 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +Тест osinfo-db на корректность распознавания ISO-образов MSVSphere утилитой osinfo-detect + +Исходные ISO файлы загружаются из списка msvsphereiso.uri + +При успешном завершении тест возвращает 0, при проблемах возвращается значение 1 и более. + +Работа теста сопровождается выводом информационных сообщений поятняющих суть действий. + +Для запуска теста необходимо проверить наличие корректных URL для загрузки ISO и CHECKSUM файлов и выполнить osinfo-detect-test.sh + diff --git a/functions b/functions new file mode 100644 index 0000000..fb41312 --- /dev/null +++ b/functions @@ -0,0 +1,92 @@ +exitmsg() +{ + echo "$1" + exit $2 +} + +cdcheck() +{ +case $1 in + 0) + echo "cd $2" + ;; + 1) + exitmsg "Error: cd $2, exiting..." 1 + ;; + *) + exitmsg "Error: cd $2 unknown error " $? + ;; +esac +} + +wgetcheck() +{ +case $1 in + 0) + echo "osinfo-detect-test.sh log: wget $2 No problems occurred." + ;; + 1) + exitmsg "Error: wget $2 Generic error code, exiting..." 1 + ;; + 2) + exitmsg "Error: wget $2 Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc..., exiting..." 2 + ;; + 3) + exitmsg "Error: wget $2 File I/O error, exiting..." 3 + ;; + 4) + exitmsg "Error: wget $2 Network failure, exiting..." 4 + ;; + 5) + exitmsg "Error: wget $2 SSL verification failure, exiting..." 5 + ;; + 6) + exitmsg "Error: wget $2 Username/password authentication failure, exiting..." 6 + ;; + 7) + exitmsg "Error: wget $2 Protocol errors, exiting..." 7 + ;; + 8) + exitmsg "Error: wget $2 Server issued an error response, exiting..." 8 + ;; + *) + exitmsg "Error: wget unknown error " $? + ;; +esac +} + +osinfodetectcheck() +{ +case $1 in + 0) + echo "Detecting completed successfully." + ;; + 1) + exitmsg "Error: Detecting comleted with error, exiting..." 1 + ;; + 253) + exitmsg "Error: Internal test error (Error parsing media: Failed to open file:) when osinfo detecting, exiting..." 2 + ;; + *) + exitmsg "Error: osinfo-detect unknown error " $? + ;; +esac +} + +diffcheck() +{ +case $1 in + 0) + echo "Test completed successfully." + ;; + 1) + exitmsg "Error: Test unsuccessful, exiting..." 1 + ;; + 2) + exitmsg "Error: There was a trouble when result check after osinfo detecting, exiting..." 2 + ;; + *) + exitmsg "Error: cd $2 unknown error " $? + ;; +esac +} diff --git a/msvsphereiso.uri b/msvsphereiso.uri new file mode 100644 index 0000000..aa48d23 --- /dev/null +++ b/msvsphereiso.uri @@ -0,0 +1,5 @@ +https://rsync.inferitos.ru/msvsphere/9.3/isos/x86_64/MSVSphere-9.3-x86_64-dvd.iso +https://rsync.inferitos.ru/msvsphere/9.3/isos/x86_64/MSVSphere-9.3-x86_64-netinstall.iso +https://rsync.inferitos.ru/msvsphere/9.3/isos/x86_64/MSVSphere-9.3-x86_64-minimal.iso +https://rsync.inferitos.ru/msvsphere/9.3/isos/x86_64/MSVSphere-9.3-x86_64-server.iso +https://rsync.inferitos.ru/msvsphere/9.3/isos/x86_64/MSVSphere-9.3-x86_64-arm.iso diff --git a/osinfo-detect-reference.result b/osinfo-detect-reference.result new file mode 100644 index 0000000..c230575 --- /dev/null +++ b/osinfo-detect-reference.result @@ -0,0 +1,2 @@ +Media is bootable. +Media is an installer for OS 'MSVSphere 9 (x86_64)' diff --git a/osinfo-detect-test.sh b/osinfo-detect-test.sh new file mode 100755 index 0000000..d93bd7b --- /dev/null +++ b/osinfo-detect-test.sh @@ -0,0 +1,153 @@ +#!/bin/bash + +#---------------------------------------------------------------------- +# Description: osinfo-detect-test.sh - Check msvsphere patches are working for osinfo-db +# Author: td25i +# 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