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 @@ ...@@ -12,10 +12,13 @@
~ automaton netaccess linux needs_root ~ automaton netaccess linux needs_root
* This test retries on failure because it often fails * This test retries on failure because it often fails
from __future__ import print_function
import os import os
import time import time
import signal import signal
from scapy.modules.six.moves import range
def handler(signum, stack_frame): def handler(signum, stack_frame):
raise Exception("Timer expired !") raise Exception("Timer expired !")
...@@ -28,12 +31,12 @@ IPTABLE_RULE = "iptables -%c INPUT -s %s -p tcp --sport 80 -j DROP" ...@@ -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) assert(os.system(IPTABLE_RULE % ('A', SECDEV_IP4)) == 0)
success = False success = False
for i in xrange(10): for i in range(10):
tmp = signal.alarm(5) tmp = signal.alarm(5)
try: try:
r, w = os.pipe() r, w = os.pipe()
t = TCP_client(SECDEV_IP4, 80, external_fd={ "tcp": (r,w) }) 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() t.runbg()
time.sleep(0.5) time.sleep(0.5)
response = os.read(r, 4096) response = os.read(r, 4096)
...@@ -41,13 +44,13 @@ for i in xrange(10): ...@@ -41,13 +44,13 @@ for i in xrange(10):
t.stop() t.stop()
os.close(r) os.close(r)
os.close(w) os.close(w)
if response.startswith("HTTP/1.1 200 OK"): if response.startswith(b"HTTP/1.1 200 OK"):
success = True success = True
break break
else: else:
time.sleep(0.5) time.sleep(0.5)
except Exception as e: except Exception as e:
print e print(e)
# Remove the iptables rule # Remove the iptables rule
assert(os.system(IPTABLE_RULE % ('D', SECDEV_IP4)) == 0) 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