* [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency
@ 2017-04-18 23:19 Pablo M. Bermudo Garay
2017-04-18 23:19 ` [PATCH iptables 2/2] tests: xlate: check if it is being run as root Pablo M. Bermudo Garay
2017-04-25 9:00 ` [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: Pablo M. Bermudo Garay @ 2017-04-18 23:19 UTC (permalink / raw)
To: netfilter-devel; +Cc: Pablo M. Bermudo Garay
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>
---
xlate-test.py | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/xlate-test.py b/xlate-test.py
index 006289f..37760e9 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))
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH iptables 2/2] tests: xlate: check if it is being run as root
2017-04-18 23:19 [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo M. Bermudo Garay
@ 2017-04-18 23:19 ` Pablo M. Bermudo Garay
2017-04-25 9:00 ` Pablo Neira Ayuso
2017-04-25 9:00 ` [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Pablo M. Bermudo Garay @ 2017-04-18 23:19 UTC (permalink / raw)
To: netfilter-devel; +Cc: Pablo M. Bermudo Garay
Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
xlate-test.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/xlate-test.py b/xlate-test.py
index 37760e9..43c4be1 100755
--- a/xlate-test.py
+++ b/xlate-test.py
@@ -72,7 +72,9 @@ def load_test_files():
def main():
- if args.test:
+ if os.getuid() != 0:
+ print(red("Error: ") + "You need to be root to run this, sorry")
+ elif args.test:
if not args.test.endswith(".txlate"):
args.test += ".txlate"
try:
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency
2017-04-18 23:19 [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo M. Bermudo Garay
2017-04-18 23:19 ` [PATCH iptables 2/2] tests: xlate: check if it is being run as root Pablo M. Bermudo Garay
@ 2017-04-25 9:00 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2017-04-25 9:00 UTC (permalink / raw)
To: Pablo M. Bermudo Garay; +Cc: netfilter-devel
On Wed, Apr 19, 2017 at 01:19:08AM +0200, Pablo M. Bermudo Garay wrote:
> 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.
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-04-25 9:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-18 23:19 [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo M. Bermudo Garay
2017-04-18 23:19 ` [PATCH iptables 2/2] tests: xlate: check if it is being run as root Pablo M. Bermudo Garay
2017-04-25 9:00 ` Pablo Neira Ayuso
2017-04-25 9:00 ` [PATCH iptables 1/2] tests: xlate: remove python 3.5 dependency Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.