nixpkgs/nixos/tests/proxy.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.4 KiB
Nix
Raw Normal View History

2020-01-26 12:04:36 +00:00
import ./make-test-python.nix ({ pkgs, ...} :
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";
};
2020-01-26 12:04:36 +00:00
networking.firewall.allowedTCPPorts = [ 80 ];
};
in {
2014-06-28 15:04:49 +01:00
name = "proxy";
meta = with pkgs.lib.maintainers; {
maintainers = [ eelco ];
};
2020-01-26 12:04:36 +00:00
nodes = {
proxy = { nodes, ... }: {
services.httpd = {
enable = true;
adminAddr = "bar@example.org";
extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
extraConfig = ''
ExtendedStatus on
'';
virtualHosts.localhost = {
extraConfig = ''
<Location /server-status>
Require all granted
SetHandler server-status
</Location>
<Proxy balancer://cluster>
Require all granted
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
'';
};
2020-01-26 12:04:36 +00:00
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
2020-01-26 12:04:36 +00:00
backend1 = backend;
backend2 = backend;
client = { ... }: { };
};
2020-01-26 12:04:36 +00:00
testScript = ''
start_all()
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")
2020-01-26 12:04:36 +00:00
# With the back-ends up, the proxy should work.
client.succeed("curl --fail http://proxy/")
2020-01-26 12:04:36 +00:00
client.succeed("curl --fail http://proxy/server-status")
2020-01-26 12:04:36 +00:00
# Block the first back-end.
backend1.block()
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/")
2020-01-26 12:04:36 +00:00
# Block the second back-end.
backend2.block()
2020-01-26 12:04:36 +00:00
# Now the proxy should fail as well.
client.fail("curl --fail http://proxy/")
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/")
'';
})