From f585e9ceb57d39284123c50a0f98999302a6f749 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara Date: Tue, 10 Aug 2021 13:11:41 -0500 Subject: [PATCH] Add gating tests Related: #1966688 --- gating.yaml | 6 ++ tests/haproxy.cfg.in | 16 +++++ tests/run_tests.sh | 142 +++++++++++++++++++++++++++++++++++++++++++ tests/tests.yml | 13 ++++ 4 files changed, 177 insertions(+) create mode 100644 gating.yaml create mode 100644 tests/haproxy.cfg.in create mode 100755 tests/run_tests.sh create mode 100644 tests/tests.yml diff --git a/gating.yaml b/gating.yaml new file mode 100644 index 0000000..648918d --- /dev/null +++ b/gating.yaml @@ -0,0 +1,6 @@ +--- !Policy +product_versions: + - rhel-9 +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional} diff --git a/tests/haproxy.cfg.in b/tests/haproxy.cfg.in new file mode 100644 index 0000000..d64c489 --- /dev/null +++ b/tests/haproxy.cfg.in @@ -0,0 +1,16 @@ +global + daemon + maxconn 1024 + user haproxy + group haproxy + +defaults + mode http + timeout connect 2s + timeout client 10s + timeout server 10s + +listen test + bind *:81 + server $VHOST1_NAME $VHOST1_ADDR:$VHOST1_PORT check + server $VHOST2_NAME $VHOST2_ADDR:$VHOST2_PORT check diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100755 index 0000000..025d150 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +export VHOST1_NAME="vhost1" +export VHOST1_ADDR="192.168.100.101" +export VHOST1_PORT="80" + +export VHOST2_NAME="vhost2" +export VHOST2_ADDR="192.168.100.102" +export VHOST2_PORT="80" + +mkdir -p /var/www/html/${VHOST1_NAME} +mkdir -p /var/www/html/${VHOST2_NAME} + +echo ${VHOST1_NAME} > /var/www/html/${VHOST1_NAME}/index.html +echo ${VHOST2_NAME} > /var/www/html/${VHOST2_NAME}/index.html + +restorecon -R /var/www/html + +cat >/etc/httpd/conf.d/vhost.conf < + DocumentRoot /var/www/html/${VHOST1_NAME} + + + DocumentRoot /var/www/html/${VHOST2_NAME} + +EOF + +echo -ne "[debug]: adding ${VHOST1_ADDR} ... " +ip addr add ${VHOST1_ADDR} dev lo +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: adding ${VHOST1_ADDR} ... " +ip addr add ${VHOST2_ADDR} dev lo +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: starting httpd service ... " +systemctl start httpd +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: checking httpd active ... " +systemctl -q is-active httpd +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +VHOST1_VARS='${VHOST1_NAME}:${VHOST1_ADDR}:${VHOST1_PORT}' +VHOST2_VARS='${VHOST2_NAME}:${VHOST2_ADDR}:${VHOST2_PORT}' + +echo -ne "[debug]: setting up config file .... " +envsubst "${VHOST1_VARS},${VHOST2_VARS}" < ./haproxy.cfg.in > /etc/haproxy/haproxy.cfg +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: configuring selinux policy ... " +setsebool haproxy_connect_any 1 +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: starting haproxy service ... " +systemctl start haproxy +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: checking haproxy active ... " +systemctl -q is-active haproxy +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: fetching URL via haproxy ... " +if [[ $( curl -s http://127.0.0.1:81 ) != ${VHOST1_NAME} ]] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: fetching URL via haproxy ... " +if [[ $( curl -s http://127.0.0.1:81 ) != ${VHOST2_NAME} ]] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: stopping haproxy service ... " +systemctl stop haproxy +if [ $? -ne 0 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +echo -ne "[debug]: checking haproxy inactive ... " +systemctl -q is-active haproxy +if [ $? -ne 3 ] ; then + echo "FAIL" + exit 1 +else + echo "OK" +fi + +systemctl stop httpd + +ip addr del ${VHOST1_ADDR}/32 dev lo +ip addr del ${VHOST2_ADDR}/32 dev lo + +exit 0 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..7ec8ad9 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,13 @@ +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - simple: + dir: . + run: ./run_tests.sh + required_packages: + - curl + - gettext + - httpd