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 http-request use-service prometheus-exporter if { path /metrics }
20 use_backend http_server
21 '';
22 };
23 services.httpd = {
24 enable = true;
25 virtualHosts.localhost = {
26 documentRoot = pkgs.writeTextDir "index.txt" "We are all good!";
27 adminAddr = "notme@yourhost.local";
28 listen = [{
29 ip = "::1";
30 port = 8000;
31 }];
32 };
33 };
34 };
35 };
36 testScript = ''
37 start_all()
38 machine.wait_for_unit("multi-user.target")
39 machine.wait_for_unit("haproxy.service")
40 machine.wait_for_unit("httpd.service")
41 assert "We are all good!" in machine.succeed("curl -fk http://localhost:80/index.txt")
42 assert "haproxy_process_pool_allocated_bytes" in machine.succeed(
43 "curl -fk http://localhost:80/metrics"
44 )
45
46 with subtest("reload"):
47 machine.succeed("systemctl reload haproxy")
48 # wait some time to ensure the following request hits the reloaded haproxy
49 machine.sleep(5)
50 assert "We are all good!" in machine.succeed(
51 "curl -fk http://localhost:80/index.txt"
52 )
53 '';
54})