tests - integrated LinuxTest

This commit is contained in:
florian 2022-07-18 22:00:14 +02:00
parent eca010231c
commit f47ab0adc5
5 changed files with 63 additions and 18 deletions

View File

@ -381,6 +381,14 @@ jobs:
# run: ./tests/main.py "kubernetes"
- name: Generate Linux packages and build test images
run: ./tests/linux.sh ${{ env.BUILD_MODE }}
- name: Run Linux Ubuntu tests
run: ./tests/main.py "linux" "ubuntu"
- name: Run Linux Debian tests
run: ./tests/main.py "linux" "debian"
- name: Run Linux CentOS tests
run: ./tests/main.py "linux" "centos"
- name: Run Linux Fedora tests
run: ./tests/main.py "linux" "fedora"
- name: Temp stop tests
run: exit 1
- name: Run autoconf tests

View File

@ -0,0 +1,17 @@
#!/bin/bash
if [ $(id -u) -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
wget https://github.com/authelia/authelia/releases/download/v4.36.2/authelia-v4.36.2-linux-amd64.tar.gz -O /tmp/authelia.tar.gz
cd /tmp/
tar -xvzf authelia.tar.gz
mv authelia-linux-amd64 /usr/bin/authelia
mv authelia.service /etc/systemd/system
mkdir /etc/authelia
cp ./authelia/* /etc/authelia
sed -i "s@/config/@/etc/authelia/@g" /etc/authelia/configuration.yml
systemctl daemon-reload
systemctl start authelia

View File

@ -22,7 +22,7 @@ class LinuxTest(Test) :
raise(Exceptions("unknown distro " + distro))
self.__distro = distro
def init() :
def init(distro) :
try :
if not Test.init() :
return False
@ -34,14 +34,14 @@ class LinuxTest(Test) :
rmdir("/tmp/linux")
mkdir("/tmp/linux")
chmod("/tmp/linux", 0o0777)
cmd = "docker run -v /tmp/bw-data/letsencrypt:/etc/letsencrypt -v /tmp/bw-data/cache:/opt/bunkerweb/cache -v /tmp/bw-data/configs:/opt/bunkerweb/configs -v /tmp/bw-data/www:/opt/bunkerweb/www -v /tmp/linux/variables.env:/opt/bunkerweb/variables.env -p 80:80 -p 443:443 --rm --name linux-" + self.__distro + " -d --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro bw-" + self.__distro
cmd = "docker run -v /tmp/bw-data/letsencrypt:/etc/letsencrypt -v /tmp/bw-data/cache:/opt/bunkerweb/cache -v /tmp/bw-data/configs:/opt/bunkerweb/configs -v /tmp/bw-data/www:/opt/bunkerweb/www -v /tmp/linux/variables.env:/opt/bunkerweb/variables.env -p 80:80 -p 443:443 --rm --name linux-" + self.__distro + " -d --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro bw-" + distro
proc = run(cmd, shell=True)
if proc.returncode != 0 :
raise(Exception("docker run failed (linux stack)"))
cmd = "docker exec linux-" + self.__distro + " "
if self.__distro in ["ubuntu", "debian"] :
cmd = "docker exec linux-" + distro + " "
if distro in ["ubuntu", "debian"] :
cmd += " apt install -y /opt/*.deb"
elif self.__distro in ["centos", "fedora"] :
elif distro in ["centos", "fedora"] :
cmd += " dnf install -y /opt/*.rpm"
proc = run(cmd, shell=True)
if proc.returncode != 0 :
@ -54,12 +54,12 @@ class LinuxTest(Test) :
return False
return True
def end() :
def end(distro) :
ret = True
try :
if not Test.end() :
return False
proc = run("docker kill linux-" + self.__distro, shell=True)
proc = run("docker kill linux-" + distro, shell=True)
if proc.returncode != 0 :
ret = False
except :
@ -78,14 +78,17 @@ class LinuxTest(Test) :
Test.replace_in_files(test, "example.com", getenv("ROOT_DOMAIN"))
setup = test + "/setup-linux.sh"
if isfile(setup) :
proc = run("sudo ./setup-linux.sh", cwd=test, shell=True)
proc = run("docker cp /tmp/" + self._name + " linux-" + self.__distro + ":/opt/tests", cwd=test, shell=True)
if proc.returncode != 0 :
raise(Exception("setup-linux failed"))
raise(Exception("docker cp failed (linux stack)"))
proc = self.__docker_exec("/opt/tests/" + self._name + "/setup-linux.sh")
if proc.returncode != 0 :
raise(Exception("docker exec setup failed (linux stack)"))
if isdir(example_data) :
for cp_dir in listdir(example_data) :
if isdir(join(example_data, cp_dir)) :
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
proc = run("systemctl restart bunkerweb", shell=True)
proc = self.__docker_exec("systemctl restart bunkerweb")
if proc.returncode != 0 :
raise(Exception("docker exec systemctl restart failed (linux stack)"))
except :
@ -102,8 +105,8 @@ class LinuxTest(Test) :
# return False
# return True
# def _debug_fail(self) :
# cmd = "cat /var/log/nginx/access.log ;"
# proc = run("docker-compose logs", shell=True, cwd=autoconf)
# test = "/tmp/tests/" + self._name
# proc = run("docker-compose -f autoconf.yml logs", shell=True, cwd=test)
def _debug_fail(self) :
self.__docker_exec("cat /var/log/nginx/access.log ; cat /var/log/nginx/error.log ; journalctl -u bunkerweb --no-pager")
def __docker_exec(self, cmd_linux) :
return run("docker exec linux-" + self.__distro + " /bin/bash -c \"" + cmd_linux + "\"", shell=True)

View File

@ -24,8 +24,6 @@ function build_image() {
do_and_check_cmd docker build -t "bw-${linux}" -f "./tests/Dockerfile-${linux}" .
}
echo "Linux tests"
if [ ! -d /opt/packages ] ; then
do_and_check_cmd sudo mkdir -p /opt/packages/{dev,prod}/{ubuntu,debian,fedora,centos}
do_and_check_cmd sudo chmod -R 777 /opt/packages/
@ -37,18 +35,26 @@ fi
do_and_check_cmd mkdir /tmp/packages
# Generate packages
echo "Building ubuntu package ..."
gen_package "$1" "ubuntu"
echo "Building debian package ..."
gen_package "$1" "debian"
echo "Building centos package ..."
gen_package "$1" "centos"
echo "Building fedora package ..."
gen_package "$1" "fedora"
# Copy packages in the Docker context
do_and_check_cmd cp -r "/opt/packages/$1" ./packages
# Build test images
echo "Building ubuntu test image ..."
build_image "ubuntu"
echo "Building debian test image ..."
build_image "debian"
echo "Building centos test image ..."
build_image "centos"
echo "Building fedora test image ..."
build_image "fedora"
exit 0

View File

@ -14,6 +14,7 @@ from DockerTest import DockerTest
from AutoconfTest import AutoconfTest
from SwarmTest import SwarmTest
from KubernetesTest import KubernetesTest
from LinuxTest import LinuxTest
from logger import log
if len(argv) != 2 :
@ -40,6 +41,10 @@ elif test_type == "swarm" :
elif test_type == "kubernetes" :
ret = KubernetesTest.init()
end_fun = KubernetesTest.end
elif test_type == "linux" :
distro = argv[2]
ret = LinuxTest.init(distro)
end_fun = LinuxTest.end
if not ret :
log("TESTS", "", "Test.init() failed")
exit(1)
@ -61,6 +66,8 @@ for example in glob("./examples/*") :
test_obj = SwarmTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "kubernetes" :
test_obj = KubernetesTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "linux" :
test_obj = LinuxTest(tests["name"], tests["timeout"], tests["tests"], distro)
if not test_obj.run_tests() :
log("TESTS", "", "Tests failed for " + tests["name"])
end_fun()
@ -70,7 +77,11 @@ for example in glob("./examples/*") :
end_fun()
exit(1)
if not end_fun() :
if test_type == "linux" :
ret = end_fun(distro)
else :
ret = end_fun()
if not ret :
log("TESTS", "", "Test.end() failed")
exit(1)