From dd35b401a712b18207928955dfb776c9b9356528 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 5 Jul 2022 13:37:30 +1000 Subject: [PATCH] gitea: test loadbalancer to gitea This explicitly tests connection through the load-balancer to the gitea backend to ensure correct operation. Additionally, it adds a check of the haproxy output to make sure the back-ends are active (that's the srv_op_state field, c.f. [1]) [1] http://docs.haproxy.org/2.6/management.html#9.3-show%20servers%20state Change-Id: Ia896134d6a9b6951acebfbf8b0b32a7ef8b87777 --- testinfra/test_gitea_lb.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testinfra/test_gitea_lb.py b/testinfra/test_gitea_lb.py index 81e8695a42..18d7c2d2cb 100644 --- a/testinfra/test_gitea_lb.py +++ b/testinfra/test_gitea_lb.py @@ -29,3 +29,15 @@ def test_haproxy_statsd_running(host): out = json.loads(cmd.stdout) assert out[0]["State"]["Status"] == "running" assert out[0]["RestartCount"] == 0 + +def test_haproxy_gitea_connection(host): + cmd = host.run('curl --resolve opendev.org:443:127.0.0.1 ' + 'https://opendev.org') + assert 'OpenDev: Free Software Needs Free Tools' in cmd.stdout + +def test_haproxy_stats(host): + cmd = host.run('echo "show servers state" | socat /var/haproxy/run/stats stdio | ' + 'tail +3 | awk \'{print $2,$4,$6}\'') + + assert 'balance_git_http gitea99.opendev.org 2' in cmd.stdout + assert 'balance_git_https gitea99.opendev.org 2' in cmd.stdout