INF-759: Реализовать поддержку тестирования серверного варианта в openQA

pull/2/head
Pavel Negrobov 1 year ago
parent 6748131de7
commit 67e27b043d

3
.gitignore vendored

@ -0,0 +1,3 @@
__pycache__/
.vagrant/
.idea/

@ -1,3 +1,4 @@
# QA
# QA - Тесты RPM-пакетов
См. описание [здесь](https://git.inferitos.ru/internal/documentation/wiki/%D0%A2%D0%B5%D1%81%D1%82%D1%8B-RPM-%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%BE%D0%B2)
Тесты MSVSphere ОС

@ -0,0 +1,125 @@
#!/bin/bash
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo -e "$@"
fi
}
return 1
}
assert_success() {
if [[ 0 -ne "$status" ]]; then
flunk "command failed with exit status ${status}\\noutput: ${output}"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [[ 0 -eq "$status" ]]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [[ "$1" != "$2" ]]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_different() {
if [[ "$1" == "$2" ]]; then
{
echo "expected: $1 != $2"
} | flunk
fi
}
assert_match() {
out="${2:-${output}}"
if [ ! $(echo "${out}" | grep -- "${1}") ]; then
{ echo "expected match: $1"
echo "actual: $out"
} | flunk
fi
}
assert_not_match() {
out="${2:-${output}}"
if [ $(echo "${out}" | grep -- "${1}") ]; then
{ echo "unexpected match: $1"
echo "source: $out"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}"
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1' in \n $output"
fi
}
refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then
flunk "output has $num_lines lines"
fi
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then
flunk "expected to not find line \`$line'"
fi
done
fi
}
assert_include() {
eval 'local values=("${'$1'[@]}")'
local element
for element in "${values[@]}"; do
[[ "$element" == "$2" ]] && return 0
done
flunk "failed: array ${values[*]} not include $2}"
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
assert_running() {
ps aux | grep $1 >> /dev/null
if [ $? -ne 0 ]; then
flunk "process with id $1 is not running"
fi
}
assert_not_running() {
if [ -d /proc/$1 ]; then
flunk "process with id $1 is running"
fi
}

@ -0,0 +1,34 @@
#!/bin/bash
set -uo pipefail
function check_test_status {
local exit_code=$?
if [ ${1} -ne 0 ]; then
echo "test [FAILED]: $2 Code: $1"
else
echo "test [PASSED]: $2"
fi
return ${exit_code}
}
function eq_is_success {
local exit_code=$?
local check=$1
if [[ ${exit_code} -ne ${2} ]]; then
let check+=1
fi
echo ${check}
return ${exit_code}
}
function not_eq_is_success {
local exit_code=$?
local check=$1
if [[ ${exit_code} -eq ${2} ]]; then
let check+=1
fi
echo ${check}
return ${exit_code}
}

@ -0,0 +1,11 @@
#!/bin/bash -x
source ../../library/sh_lib.sh
check=0
/bin/systemctl status --no-pager mariadb | /bin/grep -E 'running;|enabled;'
check=$(eq_is_success ${check} 0)
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,6 @@
#!/bin/bash
systemctl enable mariadb
systemctl restart mariadb
exit 0

@ -0,0 +1,11 @@
#!/bin/bash -x
source ../../library/sh_lib.sh
check=0
/bin/systemctl status --no-pager postgresql | /bin/grep -E 'running;|enabled;'
check=$(eq_is_success ${check} 0)
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,14 @@
#!/bin/bash
source ../../library/sh_lib.sh
check=0
postgresql-setup --initdb
check=$(eq_is_success ${check} 0)
systemctl enable postgresql
systemctl restart postgresql
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,7 @@
#!/bin/bash
echo "Подготовка окружения для тестирования пакета ${TEST_PACKAGE_NAME}"
dnf -y install man man-pages util-linux
exit 0

@ -0,0 +1,27 @@
#!/bin/bash -x
echo "Тест наличия bugzilla ссылок"
source ../../library/sh_lib.sh
check=0
test_gcc_v(){
echo "INFO: Testing bugzilla URL in gcc -v"
gcc -v 2>&1 | grep "\-\-with\-bugurl=https://bugs.msvsphere.ru/"
check=$(eq_is_success ${check} 0)
}
test_gcc_man_page(){
echo "INFO: Testing bugzilla URL in man gcc"
/bin/man -P /bin/cat gcc | /bin/grep https://bugs.msvsphere.ru/
check=$(eq_is_success ${check} 0)
}
############
# Run tests
test_gcc_v
test_gcc_man_page
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,16 @@
#!/bin/bash -x
echo "Тест компилятора"
source ../../library/sh_lib.sh
check=0
gcc -o simple_test files/simple_test.c
check=$(eq_is_success ${check} 0)
./simple_test | grep -E '^Hello, world!$'
check=$(eq_is_success ${check} 0)
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,10 @@
// simple-test.c
#include <stdio.h>
int main ( void )
{
printf ("Hello, world!");
return 0;
} // main

@ -0,0 +1 @@
../p_grub2-efi-x64/001-prepare_environment.sh

@ -0,0 +1 @@
../p_grub2-efi-x64/01-files-check.sh

@ -0,0 +1 @@
../p_grub2-efi-x64/02-pesigcheck.sh

@ -0,0 +1,8 @@
#!/bin/bash
echo "Подготовка окружения для тестирования пакета ${TEST_PACKAGE_NAME}"
# Установка вспомогательных пакетов
dnf install -y sphere-sb-certs pesign
exit 0

@ -0,0 +1,26 @@
#!/bin/bash -x
echo "Тест наличия файлов пакета ${TEST_PACKAGE_NAME}"
source ../../library/sh_lib.sh
if [[ "${TEST_PACKAGE_NAME}" != "grub2-efi-x64" ]] && [[ "${TEST_PACKAGE_NAME}" != "grub2-efi-x64-cdboot" ]]; then
echo "ERROR: Неверное имя пакета - '${TEST_PACKAGE_NAME}'. Этот тест предназначен для пакетов grub2-efi-x64 и grub2-efi-x64-cdboot"
exit 1
fi
if [[ "${TEST_PACKAGE_NAME}" == "grub2-efi-x64" ]]; then
_FILE1='/boot/efi/EFI/msvsphere/grubx64.efi'
else
_FILE1='/boot/efi/EFI/msvsphere/gcdx64.efi'
fi
check=0
if [[ ! -f "${_FILE1}" ]]; then
echo "ERROR: File ${_FILE1} absent!"
let check+=1
fi
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,24 @@
#!/bin/bash -x
echo "Тест pesigcheck файлов пакета ${TEST_PACKAGE_NAME}"
source ../../library/sh_lib.sh
if [[ "${TEST_PACKAGE_NAME}" != "grub2-efi-x64" ]] && [[ "${TEST_PACKAGE_NAME}" != "grub2-efi-x64-cdboot" ]]; then
echo "ERROR: Неверное имя пакета - '${TEST_PACKAGE_NAME}'. Этот тест предназначен для пакетов grub2-efi-x64 и grub2-efi-x64-cdboot"
exit 1
fi
if [[ "${TEST_PACKAGE_NAME}" == "grub2-efi-x64" ]]; then
_FILE1='/boot/efi/EFI/msvsphere/grubx64.efi'
else
_FILE1='/boot/efi/EFI/msvsphere/gcdx64.efi'
fi
check=0
/bin/pesigcheck -n 0 -c /etc/pki/sb-certs/secureboot-grub2-x86_64.cer -i "${_FILE1}" | /bin/grep "\"${_FILE1}\" is valid."
check=$(eq_is_success ${check} 0)
check_test_status ${check} "$0"
exit ${check}

@ -0,0 +1,5 @@
#!/bin/bash
echo "Подготовка окружения для тестирования пакета ${TEST_PACKAGE_NAME}"
exit 0

@ -0,0 +1,15 @@
#!/usr/bin/bats
load ../../library/assertions;
PACKAGE=httpd-core
setup() {
if [[ -z $(/bin/rpm -qa | /bin/grep ${PACKAGE}) ]]; then
skip "${PACKAGE} is not installed, tests skipped"
fi
}
@test "dummy-test" {
skip "Skipped, this test only demo"
}

@ -0,0 +1,5 @@
#!/bin/bash
echo "Подготовка окружения для тестирования пакета ${TEST_PACKAGE_NAME}"
exit 0

@ -0,0 +1,16 @@
#!/usr/bin/bats
load ../../library/assertions;
PACKAGE=httpd
setup() {
if [[ -z $(/bin/rpm -qa | /bin/grep ${PACKAGE}) ]]; then
skip "${PACKAGE} is not installed, tests skipped"
fi
}
@test "is httpd service present" {
/bin/systemctl status ${PACKAGE} | /bin/grep -E 'running;|disabled;'
assert_success;
}

@ -0,0 +1,13 @@
#!/bin/bash -x
# Test apache group present
source ../../library/sh_lib.sh
check=0
cat /etc/group | grep apache
check=$(eq_is_success ${check} 0)
check_test_status ${check} "$0"
exit ${check}
Loading…
Cancel
Save