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 Thu Sep 3 08:36:35 UTC 2015 - pgajdos@suse.com

View File

@ -43,7 +43,7 @@
%endif %endif
%define macros_file macros.apache %define macros_file macros.apache
Name: apache-rpm-macros Name: apache-rpm-macros
Version: 20150903 Version: 20150904
Release: 0 Release: 0
Summary: Apache RPM Macros Summary: Apache RPM Macros
License: Apache-2.0 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 # macro: apache_test_module_start_apache -- start apache with specified modules loaded
# #
@ -9,9 +18,11 @@
# %{apache_libexecdir} # %{apache_libexecdir}
# [example value: asn:dbd] # [example value: asn:dbd]
# include_list: colon separated list of names of apache configuration files # include_list: colon separated list of names of apache configuration files
# to be included (path relative to current dir) # to be included; can be either existing path or just name
# search path %{buildroot}%{apache_sysconfdir} tree # of the configuration file,which will be searched under:
# $PWD tree # %{buildroot}%{apache_sysconfdir} tree
# $PWD tree
# %{apache_test_module_dir}
# [example value: mod_asn.conf] # [example value: mod_asn.conf]
# document_root: document root of the test server, # document_root: document root of the test server,
# [default value: $PWD/test/htdocs] # [default value: $PWD/test/htdocs]
@ -19,11 +30,11 @@
# #
%apache_test_module_start_apache(m:,i:,r:) \ %apache_test_module_start_apache(m:,i:,r:) \
# constants \ # constants \
TEST_DIR='test' \ TEST_DIR='%{__test_dir}' \
TEST_MPM='prefork' \ TEST_MPM='%{__test_mpm}' \
TEST_USER='abuild' \ TEST_USER='%{__test_user}' \
TEST_GROUP='abuild' \ TEST_GROUP='%{__test_group}' \
TEST_PORT='60080' \ TEST_PORT='%{__test_port}' \
# arguments \ # arguments \
# modules to load, from BUILD tree or system \ # modules to load, from BUILD tree or system \
MODULES=$(echo %{-m:%{-m*}} | tr ':' ' ') \ MODULES=$(echo %{-m:%{-m*}} | tr ':' ' ') \
@ -36,7 +47,7 @@
# document root of the test server \ # document root of the test server \
DOCUMENT_ROOT="%{-r:%{-r*}}" \ DOCUMENT_ROOT="%{-r:%{-r*}}" \
if [ -z "$DOCUMENT_ROOT" ]; then \ if [ -z "$DOCUMENT_ROOT" ]; then \
DOCUMENT_ROOT=$PWD/$TEST_DIR/htdocs \ DOCUMENT_ROOT=$TEST_DIR/htdocs \
fi \ fi \
# helpers \ # helpers \
APACHE_BRANCH=$(echo %{apache_branch} | tr -d '.') \ APACHE_BRANCH=$(echo %{apache_branch} | tr -d '.') \
@ -46,19 +57,19 @@
echo \ echo \
echo "modules to load: $MODULES" \ echo "modules to load: $MODULES" \
echo "configs to include: $CONFIGS" \ echo "configs to include: $CONFIGS" \
# create test \ # create test dir \
mkdir -p $TEST_DIR \ mkdir -p $TEST_DIR \
# create document root if not exist \ # create document root if not exist \
mkdir -p $DOCUMENT_ROOT \ mkdir -p $DOCUMENT_ROOT \
# create test/httpd-test.conf \ # 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" \ SYSTEM_MODULE_PATH="%{apache_libexecdir}-$TEST_MPM" \
echo "ServerName test" > $TEST_CONF_FILE \ echo "ServerName test" > $TEST_CONF_FILE \
echo "User $TEST_USER" >> $TEST_CONF_FILE \ echo "User $TEST_USER" >> $TEST_CONF_FILE \
echo "Group $TEST_GROUP" >> $TEST_CONF_FILE \ echo "Group $TEST_GROUP" >> $TEST_CONF_FILE \
echo "Listen $TEST_PORT" >> $TEST_CONF_FILE \ echo "Listen $TEST_PORT" >> $TEST_CONF_FILE \
echo "PidFile $PWD/$TEST_DIR/pid" >> $TEST_CONF_FILE \ echo "PidFile $TEST_DIR/pid" >> $TEST_CONF_FILE \
echo "ErrorLog $PWD/$TEST_DIR/error_log" >> $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 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 \ echo "LoadModule auth_basic_module $SYSTEM_MODULE_PATH/mod_auth_basic.so" >> $TEST_CONF_FILE \
if [ $APACHE_BRANCH -ge 24 ]; then \ if [ $APACHE_BRANCH -ge 24 ]; then \
@ -75,7 +86,14 @@
echo "LoadModule ${m}_module $module_path" >> $TEST_CONF_FILE \ echo "LoadModule ${m}_module $module_path" >> $TEST_CONF_FILE \
done \ done \
for c in $(echo $CONFIGS | tr ':' ' '); do \ 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 \ if [ -z "$include_path" ]; then \
echo "ERROR: Config file $c not found." \ echo "ERROR: Config file $c not found." \
exit 1 \ exit 1 \
@ -97,7 +115,7 @@
# run apache \ # run apache \
CMD=$(ls %{_sbindir}/httpd*-$TEST_MPM | head -n 1) \ CMD=$(ls %{_sbindir}/httpd*-$TEST_MPM | head -n 1) \
echo -n "Starting Apache ... " \ 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 \ # wait to be sure apache finished start \
sleep 2 \ sleep 2 \
if [ ! -f $TEST_DIR/pid ]; then \ if [ ! -f $TEST_DIR/pid ]; then \
@ -115,6 +133,7 @@
# usage: apache_test_module_stop_apache # usage: apache_test_module_stop_apache
# #
%apache_test_module_stop_apache() \ %apache_test_module_stop_apache() \
TEST_DIR='%{__test_dir}' \
# stop apache \ # stop apache \
echo "Stopping Apache ..." \ echo "Stopping Apache ..." \
kill -TERM `cat $TEST_DIR/pid` \ kill -TERM `cat $TEST_DIR/pid` \
@ -122,6 +141,24 @@
echo "-----------------------------------------------------------" \ echo "-----------------------------------------------------------" \
%nil %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 # macro: apache_test_module_load -- tests that module(s) can be loaded
# #