Skip to content
Snippets Groups Projects
Commit c5e1b99e authored by Pierre LALET's avatar Pierre LALET
Browse files

Python 3: tests fixes

parent 2060322f
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,13 @@
~ automaton netaccess linux needs_root
* This test retries on failure because it often fails
from __future__ import print_function
import os
import time
import signal
from scapy.modules.six.moves import range
def handler(signum, stack_frame):
raise Exception("Timer expired !")
......@@ -28,12 +31,12 @@ IPTABLE_RULE = "iptables -%c INPUT -s %s -p tcp --sport 80 -j DROP"
assert(os.system(IPTABLE_RULE % ('A', SECDEV_IP4)) == 0)
success = False
for i in xrange(10):
for i in range(10):
tmp = signal.alarm(5)
try:
r, w = os.pipe()
t = TCP_client(SECDEV_IP4, 80, external_fd={ "tcp": (r,w) })
tmp = os.write(w, "HEAD / HTTP/1.0\r\n\r\n")
tmp = os.write(w, b"HEAD / HTTP/1.0\r\n\r\n")
t.runbg()
time.sleep(0.5)
response = os.read(r, 4096)
......@@ -41,13 +44,13 @@ for i in xrange(10):
t.stop()
os.close(r)
os.close(w)
if response.startswith("HTTP/1.1 200 OK"):
if response.startswith(b"HTTP/1.1 200 OK"):
success = True
break
else:
time.sleep(0.5)
except Exception as e:
print e
print(e)
# Remove the iptables rule
assert(os.system(IPTABLE_RULE % ('D', SECDEV_IP4)) == 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment