at 15.09-beta 2.6 kB view raw
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}/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 71 # With the back-ends up, the proxy should work. 72 $client->succeed("curl --fail http://proxy/"); 73 74 $client->succeed("curl --fail http://proxy/server-status"); 75 76 # Block the first back-end. 77 $backend1->block; 78 79 # The proxy should still work. 80 $client->succeed("curl --fail http://proxy/"); 81 82 $client->succeed("curl --fail http://proxy/"); 83 84 # Block the second back-end. 85 $backend2->block; 86 87 # Now the proxy should fail as well. 88 $client->fail("curl --fail http://proxy/"); 89 90 # But if the second back-end comes back, the proxy should start 91 # working again. 92 $backend2->unblock; 93 $client->succeed("curl --fail http://proxy/"); 94 ''; 95})