2015-07-12 11:09:40 +01:00
|
|
|
import ./make-test.nix ({ pkgs, ...} :
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
backend =
|
2010-01-11 15:58:15 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
2014-04-11 16:15:56 +01:00
|
|
|
{ services.httpd.enable = true;
|
2010-01-11 15:58:15 +00:00
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
2015-08-28 12:27:51 +01:00
|
|
|
services.httpd.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
|
2014-04-11 16:15:56 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
2010-01-11 15:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2014-06-28 15:04:49 +01:00
|
|
|
name = "proxy";
|
2015-07-12 11:09:40 +01:00
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ eelco chaoflow ];
|
|
|
|
};
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
nodes =
|
|
|
|
{ proxy =
|
|
|
|
{ config, pkgs, nodes, ... }:
|
|
|
|
|
2014-04-11 16:15:56 +01:00
|
|
|
{ services.httpd.enable = true;
|
2010-01-11 15:58:15 +00:00
|
|
|
services.httpd.adminAddr = "bar@example.org";
|
2014-11-06 13:27:02 +00:00
|
|
|
services.httpd.extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
services.httpd.extraConfig =
|
|
|
|
''
|
|
|
|
ExtendedStatus on
|
|
|
|
|
|
|
|
<Location /server-status>
|
2014-11-06 13:27:02 +00:00
|
|
|
Require all granted
|
2010-01-11 15:58:15 +00:00
|
|
|
SetHandler server-status
|
|
|
|
</Location>
|
|
|
|
|
|
|
|
<Proxy balancer://cluster>
|
2014-11-06 13:27:02 +00:00
|
|
|
Require all granted
|
2010-01-11 15:58:15 +00:00
|
|
|
BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
|
|
|
|
BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
|
|
|
|
</Proxy>
|
|
|
|
|
|
|
|
ProxyStatus full
|
|
|
|
ProxyPass /server-status !
|
|
|
|
ProxyPass / balancer://cluster/
|
|
|
|
ProxyPassReverse / balancer://cluster/
|
|
|
|
|
|
|
|
# For testing; don't want to wait forever for dead backend servers.
|
|
|
|
ProxyTimeout 5
|
|
|
|
'';
|
2014-04-11 16:15:56 +01:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
2010-01-11 15:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
backend1 = backend;
|
|
|
|
backend2 = backend;
|
|
|
|
|
|
|
|
client = { config, pkgs, ... }: { };
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
2012-10-24 17:22:53 +01:00
|
|
|
$proxy->waitForUnit("httpd");
|
|
|
|
$backend1->waitForUnit("httpd");
|
|
|
|
$backend2->waitForUnit("httpd");
|
2015-08-31 17:34:22 +01:00
|
|
|
$client->waitForUnit("network.target");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
# With the back-ends up, the proxy should work.
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->succeed("curl --fail http://proxy/server-status");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
# Block the first back-end.
|
|
|
|
$backend1->block;
|
|
|
|
|
|
|
|
# The proxy should still work.
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
# Block the second back-end.
|
|
|
|
$backend2->block;
|
|
|
|
|
|
|
|
# Now the proxy should fail as well.
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->fail("curl --fail http://proxy/");
|
2010-01-11 15:58:15 +00:00
|
|
|
|
|
|
|
# But if the second back-end comes back, the proxy should start
|
|
|
|
# working again.
|
|
|
|
$backend2->unblock;
|
2012-10-24 17:22:53 +01:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 15:58:15 +00:00
|
|
|
'';
|
2014-04-14 13:02:44 +01:00
|
|
|
})
|