Accepting request 329353 from home:pgajdos:apache2

- version 20150904
- new macros: %apache_test_module_curl, %apache_test_module_dir

OBS-URL: https://build.opensuse.org/request/show/329353
OBS-URL: https://build.opensuse.org/package/show/Apache/apache-rpm-macros?expand=0&rev=16
This commit is contained in:
Petr Gajdos 2015-09-06 11:35:52 +00:00 committed by Git OBS Bridge
parent be264cdbf3
commit f79d3984ea
3 changed files with 59 additions and 16 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Sat Sep 5 07:22:53 UTC 2015 - pgajdos@suse.com
- version 20150904
- new macros: %apache_test_module_curl, %apache_test_module_dir
-------------------------------------------------------------------
Thu Sep 3 08:36:35 UTC 2015 - pgajdos@suse.com

View File

@ -43,7 +43,7 @@
%endif
%define macros_file macros.apache
Name: apache-rpm-macros
Version: 20150903
Version: 20150904
Release: 0
Summary: Apache RPM Macros
License: Apache-2.0

View File

@ -1,3 +1,12 @@
%__test_dir /tmp/%{name}-test
%__test_mpm prefork
%__test_user abuild
%__test_group abuild
%__test_port 60080
# world writeable dir for testing purposes (logs, document root, ..)
%apache_test_module_dir %{__test_dir}
#
# macro: apache_test_module_start_apache -- start apache with specified modules loaded
#
@ -9,9 +18,11 @@
# %{apache_libexecdir}
# [example value: asn:dbd]
# include_list: colon separated list of names of apache configuration files
# to be included (path relative to current dir)
# search path %{buildroot}%{apache_sysconfdir} tree
# to be included; can be either existing path or just name
# of the configuration file,which will be searched under:
# %{buildroot}%{apache_sysconfdir} tree
# $PWD tree
# %{apache_test_module_dir}
# [example value: mod_asn.conf]
# document_root: document root of the test server,
# [default value: $PWD/test/htdocs]
@ -19,11 +30,11 @@
#
%apache_test_module_start_apache(m:,i:,r:) \
# constants \
TEST_DIR='test' \
TEST_MPM='prefork' \
TEST_USER='abuild' \
TEST_GROUP='abuild' \
TEST_PORT='60080' \
TEST_DIR='%{__test_dir}' \
TEST_MPM='%{__test_mpm}' \
TEST_USER='%{__test_user}' \
TEST_GROUP='%{__test_group}' \
TEST_PORT='%{__test_port}' \
# arguments \
# modules to load, from BUILD tree or system \
MODULES=$(echo %{-m:%{-m*}} | tr ':' ' ') \
@ -36,7 +47,7 @@
# document root of the test server \
DOCUMENT_ROOT="%{-r:%{-r*}}" \
if [ -z "$DOCUMENT_ROOT" ]; then \
DOCUMENT_ROOT=$PWD/$TEST_DIR/htdocs \
DOCUMENT_ROOT=$TEST_DIR/htdocs \
fi \
# helpers \
APACHE_BRANCH=$(echo %{apache_branch} | tr -d '.') \
@ -46,19 +57,19 @@
echo \
echo "modules to load: $MODULES" \
echo "configs to include: $CONFIGS" \
# create test \
# create test dir \
mkdir -p $TEST_DIR \
# create document root if not exist \
mkdir -p $DOCUMENT_ROOT \
# create test/httpd-test.conf \
TEST_CONF_FILE="$TEST_DIR/httpd-test.conf" \
TEST_CONF_FILE="$TEST_DIR/httpd.conf" \
SYSTEM_MODULE_PATH="%{apache_libexecdir}-$TEST_MPM" \
echo "ServerName test" > $TEST_CONF_FILE \
echo "User $TEST_USER" >> $TEST_CONF_FILE \
echo "Group $TEST_GROUP" >> $TEST_CONF_FILE \
echo "Listen $TEST_PORT" >> $TEST_CONF_FILE \
echo "PidFile $PWD/$TEST_DIR/pid" >> $TEST_CONF_FILE \
echo "ErrorLog $PWD/$TEST_DIR/error_log" >> $TEST_CONF_FILE \
echo "PidFile $TEST_DIR/pid" >> $TEST_CONF_FILE \
echo "ErrorLog $TEST_DIR/error_log" >> $TEST_CONF_FILE \
echo "LoadModule dir_module $SYSTEM_MODULE_PATH/mod_dir.so" >> $TEST_CONF_FILE \
echo "LoadModule auth_basic_module $SYSTEM_MODULE_PATH/mod_auth_basic.so" >> $TEST_CONF_FILE \
if [ $APACHE_BRANCH -ge 24 ]; then \
@ -75,7 +86,14 @@
echo "LoadModule ${m}_module $module_path" >> $TEST_CONF_FILE \
done \
for c in $(echo $CONFIGS | tr ':' ' '); do \
include_path=$(find %{buildroot}%{apache_sysconfdir} $PWD -name "$c" 2>/dev/null | tail -n 1) \
if [ -f $c ]; then \
if [[ ! "$c" = /* ]]; then \
c="$PWD/$c" \
fi \
include_path="$c" \
else \
include_path=$(find %{buildroot}%{apache_sysconfdir} %{apache_test_module_dir} $PWD -name "$c" 2>/dev/null | tail -n 1) \
fi \
if [ -z "$include_path" ]; then \
echo "ERROR: Config file $c not found." \
exit 1 \
@ -97,7 +115,7 @@
# run apache \
CMD=$(ls %{_sbindir}/httpd*-$TEST_MPM | head -n 1) \
echo -n "Starting Apache ... " \
$CMD -f $PWD/$TEST_CONF_FILE -k start \
$CMD -f $TEST_CONF_FILE -k start \
# wait to be sure apache finished start \
sleep 2 \
if [ ! -f $TEST_DIR/pid ]; then \
@ -115,6 +133,7 @@
# usage: apache_test_module_stop_apache
#
%apache_test_module_stop_apache() \
TEST_DIR='%{__test_dir}' \
# stop apache \
echo "Stopping Apache ..." \
kill -TERM `cat $TEST_DIR/pid` \
@ -122,6 +141,24 @@
echo "-----------------------------------------------------------" \
%nil
#
# macro: apache_test_module_curl -- outputs curl on particular document relative to
# document root of test instance
#
# usage: apache_test_module_curl -d document_to_curl -o output_of_curl
# example: apache_test_module_curl -d foo/test.html -o test.html
# apache_test_module_curl -d foo/ -o output.txt
#
%apache_test_module_curl(d:,o:) \
TEST_DOCUMENT="%{-d:%{-d*}}" \
TEST_OUTPUT="%{-o:%{-o*}}" \
if [ -z "$TEST_OUTPUT" ]; then \
echo "Missing argument -o to apache_test_module_curl." \
exit 1 \
fi \
curl -s "http://localhost:%{__test_port}/$TEST_DOCUMENT" --create-dirs -o "$TEST_OUTPUT" \
%nil
#
# macro: apache_test_module_load -- tests that module(s) can be loaded
#