]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
TESTS: add a python wrapper for sockpair@
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 11 Sep 2018 14:51:30 +0000 (16:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Sep 2018 05:20:26 +0000 (07:20 +0200)
This is a python wrapper which creates a socketpair and passes it as two
environment variable to haproxy.

It's the easiest way to test the sockpair protocol in haproxy.

tests/test-sockpair.py [new file with mode: 0644]

diff --git a/tests/test-sockpair.py b/tests/test-sockpair.py
new file mode 100644 (file)
index 0000000..922c6d0
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+"""
+Python wrapper example to test socketpair protocol
+./test-socketpair.py test.cfg
+
+use sockpair@${FD1} and sockpair@${FD2} in your configuration file
+
+"""
+
+import socket, os, sys
+
+s = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+os.set_inheritable(s[0].fileno(), 1)
+os.set_inheritable(s[1].fileno(), 1)
+
+FD1 = s[0].fileno()
+FD2 = s[1].fileno()
+
+print("FD1={} FD2={}".format(FD1, FD2))
+
+os.environ["FD1"] = str(FD1)
+os.environ["FD2"] = str(FD2)
+
+cmd = ["./haproxy",
+       "-f",
+       "{}".format(sys.argv[1])
+]
+os.execve(cmd[0], cmd, os.environ)