1
0
mirror of https://github.com/graygnuorg/pound.git synced 2026-10-25 10:19:36 +03:00

Test A-based dynamic backends

* tests/poundharness.pl (cleanup): Stop nameserver if necessary.
Install $SIG{__DIE__}.
* tests/dyn_a.at: New test.
* tests/srv.at: rename to tests/dyn_srv.at
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
This commit is contained in:
Sergey Poznyakoff
2024-09-30 09:58:23 +03:00
parent d4977ade46
commit 6b339a980e
5 changed files with 166 additions and 24 deletions

View File

@@ -72,6 +72,8 @@ TESTSUITE_AT = \
chunked2.at\
config.at\
disable.at\
dyn_a.at\
dyn_srv.at\
echo.at\
err503.at\
errfile.at\
@@ -124,7 +126,6 @@ TESTSUITE_AT = \
sessparm.at\
sessurl.at\
set.at\
srv.at\
stringmatch.at\
template.at\
url.at\

137
tests/dyn_a.at Normal file
View File

@@ -0,0 +1,137 @@
# This file is part of pound testsuite. -*- autotest -*-
# Copyright (C) 2024 Sergey Poznyakoff
#
# Pound is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Pound is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pound. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([A record])
AT_KEYWORDS([a_rr])
AT_CHECK([PT_PREREQ_DYNAMIC_BACKENDS
PT_PREREQ_FAKEDNS])
m4_pushdef([HARNESS_OPTIONS],[--fakedns=$LIBFAKEDNS])
PT_CHECK([Control "pound.ctl"
ListenHTTP
Service
Balancer iwrr
Backend
Resolve all
Address "be.pound.example.org"
Family inet
End
End
End
],
[[zonefile
$ORIGIN example.org.
@ IN SOA mname rname 1 2h 1h 2w 1h
$ORIGIN pound.example.org.
be 5 A 127.0.0.1
end
sleep 3
control
backends 1 0
[{
"type":"matrix",
"family":2,
"resolve_mode":"all",
"hostname":"be.pound.example.org",
"weight":0
},
{
"type":"backend",
"parent":0,
"weight":0,
"priority":5,
"address":"127.0.0.1:80"
}]
end
end
zonefile
$ORIGIN example.org.
@ IN SOA mname rname 1 2h 1h 2w 1h
$ORIGIN pound.example.org.
be 5 A 127.0.0.2
end
sleep 10
control
backends 1 0
[{
"type":"matrix",
"family":2,
"resolve_mode":"all",
"hostname":"be.pound.example.org",
"weight":0
},
{
"type":"backend",
"parent":0,
"weight":0,
"priority":5,
"address":"127.0.0.2:80"
}]
end
end
zonefile
$ORIGIN example.org.
@ IN SOA mname rname 1 2h 1h 2w 1h
$ORIGIN pound.example.org.
be 5 A 127.0.0.1
be 5 A 127.0.0.2
be 5 A 127.0.0.3
end
sleep 10
control
backends 1 0
[{
"type":"matrix",
"family":2,
"resolve_mode":"all",
"hostname":"be.pound.example.org",
"weight":0
},
{
"type":"backend",
"parent":0,
"weight":0,
"priority":5,
"address":"127.0.0.1:80"
},
{
"type":"backend",
"parent":0,
"weight":0,
"priority":5,
"address":"127.0.0.2:80"
},
{
"type":"backend",
"parent":0,
"weight":0,
"priority":5,
"address":"127.0.0.3:80"
}]
end
end
]])
m4_popdef([HARNESS_OPTIONS])
AT_CLEANUP

View File

@@ -13,8 +13,8 @@
#
# You should have received a copy of the GNU General Public License
# along with pound. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([SRV])
AT_KEYWORDS([srv])
AT_SETUP([SRV record])
AT_KEYWORDS([srv_rr])
AT_CHECK([PT_PREREQ_DYNAMIC_BACKENDS
PT_PREREQ_FAKEDNS])

View File

@@ -49,6 +49,23 @@ use constant {
EX_EXEC => 127
};
my $nameserver;
my $zonefile = 'fakedns.zone';
sub dns_reply_handler {
my $sb = stat($zonefile) or die "can't stat $zonefile: $!";
$nameserver->ReadZoneFile($zonefile);
$nameserver->{ReplyHandler} = \&dns_reply_handler;
return $nameserver->ReplyHandler(@_);
}
sub write_zone_file {
my $text = join("\n", @_);
open(my $fh, '>', $zonefile) or die "can't open $zonefile: $!";
print $fh $text;
close $fh;
}
## Early checks
## ------------
@@ -73,6 +90,9 @@ sub cleanup {
}
kill 'HUP', $pound_pid;
}
if ($nameserver) {
$nameserver->stop_server();
}
}
## Signal handling and program cleanup
@@ -80,7 +100,7 @@ sub cleanup {
my %status_codes;
$SIG{QUIT} = $SIG{HUP} = $SIG{TERM} = $SIG{INT} = \&cleanup;
$SIG{QUIT} = $SIG{HUP} = $SIG{TERM} = $SIG{INT} = $SIG{__DIE__} = \&cleanup;
sub handle_pound_status {
if (WIFEXITED($?)) {
@@ -119,24 +139,6 @@ sub sigchild {
exit(EX_ERROR);
};
$SIG{CHLD} = \&sigchild;
my $nameserver;
my $zonefile = 'fakedns.zone';
sub dns_reply_handler {
my $sb = stat($zonefile) or die "can't stat $zonefile: $!";
$nameserver->ReadZoneFile($zonefile);
$nameserver->{ReplyHandler} = \&dns_reply_handler;
return $nameserver->ReplyHandler(@_);
}
sub write_zone_file {
my $text = join("\n", @_);
open(my $fh, '>', $zonefile) or die "can't open $zonefile: $!";
print $fh $text;
close $fh;
}
## Start the program
## -----------------
@@ -228,6 +230,7 @@ $ps->parse;
# Terminate
if ($nameserver) {
$nameserver->stop_server();
$nameserver = undef;
}
if ($statistics) {
@@ -1726,7 +1729,7 @@ sub backends {
} elsif ($a->{priority} != $b->{priority}) {
$a->{priority} <=> $b->{priority}
} else {
$a->{address} cmp $b->{address}
($a->{address}//'') cmp ($b->{address}//'')
}
} @{$res->{backends}}];
}

View File

@@ -152,4 +152,5 @@ m4_include([disable.at])
m4_include([sessctl.at])
AT_BANNER([Dynamic backends])
m4_include([srv.at])
m4_include([dyn_a.at])
m4_include([dyn_srv.at])