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