1import ./make-test.nix ({ pkgs, ...} :
2
3let
4
5 backend =
6 { config, pkgs, ... }:
7
8 { services.httpd.enable = true;
9 services.httpd.adminAddr = "foo@example.org";
10 services.httpd.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
11 networking.firewall.allowedTCPPorts = [ 80 ];
12 };
13
14in
15
16{
17 name = "proxy";
18 meta = with pkgs.stdenv.lib.maintainers; {
19 maintainers = [ eelco chaoflow ];
20 };
21
22 nodes =
23 { proxy =
24 { config, pkgs, nodes, ... }:
25
26 { services.httpd.enable = true;
27 services.httpd.adminAddr = "bar@example.org";
28 services.httpd.extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
29
30 services.httpd.extraConfig =
31 ''
32 ExtendedStatus on
33
34 <Location /server-status>
35 Require all granted
36 SetHandler server-status
37 </Location>
38
39 <Proxy balancer://cluster>
40 Require all granted
41 BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
42 BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
43 </Proxy>
44
45 ProxyStatus full
46 ProxyPass /server-status !
47 ProxyPass / balancer://cluster/
48 ProxyPassReverse / balancer://cluster/
49
50 # For testing; don't want to wait forever for dead backend servers.
51 ProxyTimeout 5
52 '';
53
54 networking.firewall.allowedTCPPorts = [ 80 ];
55 };
56
57 backend1 = backend;
58 backend2 = backend;
59
60 client = { config, pkgs, ... }: { };
61 };
62
63 testScript =
64 ''
65 startAll;
66
67 $proxy->waitForUnit("httpd");
68 $backend1->waitForUnit("httpd");
69 $backend2->waitForUnit("httpd");
70 $client->waitForUnit("network.target");
71
72 # With the back-ends up, the proxy should work.
73 $client->succeed("curl --fail http://proxy/");
74
75 $client->succeed("curl --fail http://proxy/server-status");
76
77 # Block the first back-end.
78 $backend1->block;
79
80 # The proxy should still work.
81 $client->succeed("curl --fail http://proxy/");
82
83 $client->succeed("curl --fail http://proxy/");
84
85 # Block the second back-end.
86 $backend2->block;
87
88 # Now the proxy should fail as well.
89 $client->fail("curl --fail http://proxy/");
90
91 # But if the second back-end comes back, the proxy should start
92 # working again.
93 $backend2->unblock;
94 $client->succeed("curl --fail http://proxy/");
95 '';
96})