summaryrefslogtreecommitdiffstats
path: root/xlate-test.py
diff options
context:
space:
mode:
authorPablo M. Bermudo Garay <pablombg@gmail.com>2017-04-19 01:19:08 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2017-04-25 10:55:27 +0200
commit3f92b25932a8b9e2a897c49859a7c244c4c7ff37 (patch)
tree7d55b0674d7d4947e722cd7175f4e9b291f36b23 /xlate-test.py
parentd89dc47ab3875f6fe6679cebceccd2000bf81b8e (diff)
tests: xlate: remove python 3.5 dependency
This commit replaces subprocess.run (introduced in python 3.5) with subprocess.Popen (supported since the first version of python 3). Furthermore, the output has been improved when ip[6]tables-translate exits with non-zero return code. Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'xlate-test.py')
-rwxr-xr-xxlate-test.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/xlate-test.py b/xlate-test.py
index 006289f3..37760e96 100755
--- a/xlate-test.py
+++ b/xlate-test.py
@@ -4,8 +4,8 @@
import os
import sys
import shlex
-import subprocess
import argparse
+from subprocess import Popen, PIPE
keywords = ("iptables-translate", "ip6tables-translate")
@@ -40,19 +40,25 @@ def run_test(name, payload):
for line in payload:
if line.startswith(keywords):
- output = subprocess.run(shlex.split(line), stdout=subprocess.PIPE)
- translation = output.stdout.decode("utf-8").rstrip(" \n")
- expected = next(payload).rstrip(" \n")
- if translation != expected:
- result.append(red("Fail"))
- result.append(magenta("src: ") + line.rstrip(" \n"))
- result.append(magenta("exp: ") + expected)
- result.append(magenta("res: ") + translation + "\n")
+ process = Popen(shlex.split(line), stdout=PIPE, stderr=PIPE)
+ (output, error) = process.communicate()
+ if process.returncode == 0:
+ translation = output.decode("utf-8").rstrip(" \n")
+ expected = next(payload).rstrip(" \n")
+ if translation != expected:
+ result.append(red("Fail"))
+ result.append(magenta("src: ") + line.rstrip(" \n"))
+ result.append(magenta("exp: ") + expected)
+ result.append(magenta("res: ") + translation + "\n")
+ test_passed = False
+ elif args.all:
+ result.append(green("Ok"))
+ result.append(magenta("src: ") + line.rstrip(" \n"))
+ result.append(magenta("res: ") + translation + "\n")
+ else:
test_passed = False
- elif args.all:
- result.append(green("Ok"))
- result.append(magenta("src: ") + line.rstrip(" \n"))
- result.append(magenta("res: ") + translation + "\n")
+ result.append(red("Error: ") + "iptables-translate failure")
+ result.append(error.decode("utf-8"))
if not test_passed or args.all:
print("\n".join(result))