mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-26 06:32:13 +00:00
TESTS: add a python wrapper for sockpair@
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.
This commit is contained in:
parent
2fe7dd0b2e
commit
7755f9f2be
28
tests/test-sockpair.py
Normal file
28
tests/test-sockpair.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user