MINOR: reg-tests: add a way to add service dependency

I was looking at writing a simple first test for prometheus but I
realised there is no proper way to exclude it if haproxy was not built
with prometheus plugin.

Today we have `REQUIRE_OPTIONS` in reg-tests which is based on `Feature
list` from `haproxy -vv`. Those options are coming from the Makefile
itself.

A plugin is build this way:
  EXTRA_OBJS="contrib/prometheus-exporter/service-prometheus.o"

It does register service actions through `service_keywords_register`.
Those are listed through `list_services` in `haproxy -vv`.
To facilitate parsing, I slightly changed the output to a single line
and integrate it in regtests shell script so that we can now specify a
dependency while writing a reg-test for prometheus, e.g:

  #REQUIRE_SERVICE=prometheus-exporter
  #REQUIRE_SERVICES=prometheus-exporter,foo

There might be other ways to handle this, but that's the cleanest I
found; I understand people might be concerned by this output change in
`haproxy -vv` which goes from:

  Available services :
          foo
          bar

to:

  Available services : foo bar

Signed-off-by: William Dauchy <wdauchy@gmail.com>
This commit is contained in:
William Dauchy 2021-01-09 17:26:20 +01:00 committed by Willy Tarreau
parent 5417e898ff
commit aabde71332
2 changed files with 27 additions and 6 deletions

View File

@ -56,9 +56,11 @@ _help()
# Below option is required to complete this test successfully
#REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
#REQUIRE_OPTIONS=ZLIB|SLZ,OPENSSL,LUA
#REQUIRE_SERVICE=prometheus-exporter
#REQUIRE_SERVICES=prometheus-exporter,foo
# To define a range of versions that a test can run with:
#REQUIRE_VERSION=0.0
#REQUIRE_VERSION_BELOW=99.9
@ -133,6 +135,7 @@ _findtests() {
require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i" | sed -e 's/,/ /g')"
require_services="$(sed -ne 's/^#REQUIRE_SERVICES=//p' "$i" | sed -e 's/,/ /g')"
exclude_targets="$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i" | sed -e 's/,/ /g')"
require_binaries="$(sed -ne 's/^#REQUIRE_BINARIES=//p' "$i" | sed -e 's/,/ /g')"
if [ $any_test -ne 1 ] ; then
@ -151,6 +154,11 @@ _findtests() {
require_options="$require_options $requiredoption"
fi
requiredservice="$(sed -ne 's/^#REQUIRE_SERVICE=//p' "$i" | sed -e 's/,.*//')"
if [ -n "$requiredservice" ]; then
require_services="$require_services $requiredservice"
fi
excludedtarget="$(sed -ne 's/^#EXCLUDE_TARGET=//p' "$i" | sed -e 's/,.*//')"
if [ -n "$excludedtarget" ]; then
exclude_targets="$exclude_targets $excludedtarget"
@ -192,6 +200,20 @@ _findtests() {
fi
done
for requiredservice in $require_services; do
alternatives=$(echo "$requiredservice" | sed -e 's/|/ /g')
found=
for alt in $alternatives; do
if echo "$SERVICES" | grep -qw "\+$alt"; then
found=1;
fi
done
if [ -z $found ]; then
echo " Skip $i because haproxy is not compiled with the required service $requiredservice"
skiptest=1
fi
done
for requiredbin in $require_binaries; do
if ! command -v $requiredbin >/dev/null 2>&1
then
@ -322,8 +344,8 @@ if [ $preparefailed ]; then
exit 1
fi
{ read HAPROXY_VERSION; read TARGET; read FEATURES; } << EOF
$($HAPROXY_PROGRAM $HAPROXY_ARGS -vv |grep 'HA-Proxy version\|TARGET.*=\|^Feature' | sed 's/.* [:=] //')
{ read HAPROXY_VERSION; read TARGET; read FEATURES; read SERVICES; } << EOF
$($HAPROXY_PROGRAM $HAPROXY_ARGS -vv | grep 'HA-Proxy version\|TARGET.*=\|^Feature\|^Available services' | sed 's/.* [:=] //')
EOF
HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
@ -342,6 +364,7 @@ fi
echo "Target : $TARGET"
echo "Options : $FEATURES"
echo "Services : $SERVICES"
echo "########################## Gathering tests to run ##########################"
# if htx is enable, but HAProxy version is lower to 1.9, disable it

View File

@ -2791,10 +2791,8 @@ void list_services(FILE *out)
fprintf(out, "Available services :");
list_for_each_entry(kw_list, &service_keywords, list) {
for (i = 0; kw_list->kw[i].kw != NULL; i++) {
if (!found)
fputc('\n', out);
found = 1;
fprintf(out, "\t%s\n", kw_list->kw[i].kw);
fprintf(out, " %s", kw_list->kw[i].kw);
}
}
if (!found)