2020-01-26 12:04:36 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-01-10 19:08:30 +00:00
|
|
|
let
|
2020-01-26 12:04:36 +00:00
|
|
|
backend =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
services.httpd = {
|
|
|
|
enable = true;
|
|
|
|
adminAddr = "foo@example.org";
|
|
|
|
virtualHosts.localhost.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
|
2010-01-11 15:58:15 +00:00
|
|
|
};
|
2020-01-26 12:04:36 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
in
|
|
|
|
{
|
2020-01-26 12:04:36 +00:00
|
|
|
name = "proxy";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ ];
|
2010-01-11 15:58:15 +00:00
|
|
|
};
|
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
nodes = {
|
2024-12-10 19:26:33 +00:00
|
|
|
proxy =
|
|
|
|
{ nodes, ... }:
|
|
|
|
{
|
2020-01-26 12:04:36 +00:00
|
|
|
services.httpd = {
|
|
|
|
enable = true;
|
|
|
|
adminAddr = "bar@example.org";
|
|
|
|
extraModules = [
|
|
|
|
"proxy_balancer"
|
|
|
|
"lbmethod_byrequests"
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
2020-01-26 12:04:36 +00:00
|
|
|
extraConfig = ''
|
|
|
|
ExtendedStatus on
|
2024-12-10 19:26:33 +00:00
|
|
|
'';
|
2020-01-26 12:04:36 +00:00
|
|
|
virtualHosts.localhost = {
|
|
|
|
extraConfig = ''
|
|
|
|
<Location /server-status>
|
|
|
|
Require all granted
|
|
|
|
SetHandler server-status
|
|
|
|
</Location>
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
<Proxy balancer://cluster>
|
|
|
|
Require all granted
|
|
|
|
BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
|
|
|
|
BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
|
2024-12-10 19:26:33 +00:00
|
|
|
</Proxy>
|
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
ProxyStatus full
|
|
|
|
ProxyPass /server-status !
|
|
|
|
ProxyPass / balancer://cluster/
|
|
|
|
ProxyPassReverse / balancer://cluster/
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# For testing; don't want to wait forever for dead backend servers.
|
|
|
|
ProxyTimeout 5
|
2024-12-10 19:26:33 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-01-26 12:04:36 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
backend1 = backend;
|
|
|
|
backend2 = backend;
|
|
|
|
|
|
|
|
client = { ... }: { };
|
|
|
|
};
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
testScript = ''
|
|
|
|
start_all()
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
proxy.wait_for_unit("httpd")
|
|
|
|
backend1.wait_for_unit("httpd")
|
|
|
|
backend2.wait_for_unit("httpd")
|
|
|
|
client.wait_for_unit("network.target")
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# With the back-ends up, the proxy should work.
|
|
|
|
client.succeed("curl --fail http://proxy/")
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
client.succeed("curl --fail http://proxy/server-status")
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# Block the first back-end.
|
|
|
|
backend1.block()
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# The proxy should still work.
|
|
|
|
client.succeed("curl --fail http://proxy/")
|
|
|
|
client.succeed("curl --fail http://proxy/")
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# Block the second back-end.
|
|
|
|
backend2.block()
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# Now the proxy should fail as well.
|
|
|
|
client.fail("curl --fail http://proxy/")
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2020-01-26 12:04:36 +00:00
|
|
|
# But if the second back-end comes back, the proxy should start
|
|
|
|
# working again.
|
|
|
|
backend2.unblock()
|
|
|
|
client.succeed("curl --fail http://proxy/")
|
|
|
|
'';
|
2014-04-14 12:02:44 +00:00
|
|
|
}
|
|
|
|
)
|