at 22.05-pre 1.6 kB view raw
1import ./make-test-python.nix ({ pkgs, ...}: { 2 name = "haproxy"; 3 nodes = { 4 machine = { ... }: { 5 imports = [ ../modules/profiles/minimal.nix ]; 6 services.haproxy = { 7 enable = true; 8 config = '' 9 defaults 10 timeout connect 10s 11 12 backend http_server 13 mode http 14 server httpd [::1]:8000 15 16 frontend http 17 bind *:80 18 mode http 19 option http-use-htx 20 http-request use-service prometheus-exporter if { path /metrics } 21 use_backend http_server 22 ''; 23 }; 24 services.httpd = { 25 enable = true; 26 virtualHosts.localhost = { 27 documentRoot = pkgs.writeTextDir "index.txt" "We are all good!"; 28 adminAddr = "notme@yourhost.local"; 29 listen = [{ 30 ip = "::1"; 31 port = 8000; 32 }]; 33 }; 34 }; 35 }; 36 }; 37 testScript = '' 38 start_all() 39 machine.wait_for_unit("multi-user.target") 40 machine.wait_for_unit("haproxy.service") 41 machine.wait_for_unit("httpd.service") 42 assert "We are all good!" in machine.succeed("curl -fk http://localhost:80/index.txt") 43 assert "haproxy_process_pool_allocated_bytes" in machine.succeed( 44 "curl -fk http://localhost:80/metrics" 45 ) 46 47 with subtest("reload"): 48 machine.succeed("systemctl reload haproxy") 49 # wait some time to ensure the following request hits the reloaded haproxy 50 machine.sleep(5) 51 assert "We are all good!" in machine.succeed( 52 "curl -fk http://localhost:80/index.txt" 53 ) 54 ''; 55})