* [PATCH nft v2]tests: json_echo: convert to py3
@ 2019-05-28 0:36 Shekhar Sharma
2019-05-28 16:06 ` Phil Sutter
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Shekhar Sharma @ 2019-05-28 0:36 UTC (permalink / raw)
To: netfilter-devel; +Cc: Shekhar Sharma
This patch converts the run-test.py file to run on both python3 and python2.
The version history of the patch is:
v1: modified print and other statments.
v2: updated the shebang and order of import statements.
Signed-off-by: Shekhar Sharma <shekhar250198@gmail.com>
---
tests/json_echo/run-test.py | 45 +++++++++++++++++++------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py
index 0132b139..dd7797fb 100755
--- a/tests/json_echo/run-test.py
+++ b/tests/json_echo/run-test.py
@@ -1,5 +1,6 @@
-#!/usr/bin/python2
+#!/usr/bin/python
+from __future__ import print_function
import sys
import os
import json
@@ -13,8 +14,8 @@ from nftables import Nftables
os.chdir(TESTS_PATH + "/../..")
if not os.path.exists('src/.libs/libnftables.so'):
- print "The nftables library does not exist. " \
- "You need to build the project."
+ print("The nftables library does not exist. "
+ "You need to build the project.")
sys.exit(1)
nftables = Nftables(sofile = 'src/.libs/libnftables.so')
@@ -79,26 +80,26 @@ add_quota = { "add": {
# helper functions
def exit_err(msg):
- print "Error: %s" % msg
+ print("Error: %s" %msg)
sys.exit(1)
def exit_dump(e, obj):
- print "FAIL: %s" % e
- print "Output was:"
+ print("FAIL: {}".format(e))
+ print("Output was:")
json.dumps(out, sort_keys = True, indent = 4, separators = (',', ': '))
sys.exit(1)
def do_flush():
rc, out, err = nftables.json_cmd({ "nftables": [flush_ruleset] })
if not rc is 0:
- exit_err("flush ruleset failed: %s" % err)
+ exit_err("flush ruleset failed: {}".format(err))
def do_command(cmd):
if not type(cmd) is list:
cmd = [cmd]
rc, out, err = nftables.json_cmd({ "nftables": cmd })
if not rc is 0:
- exit_err("command failed: %s" % err)
+ exit_err("command failed: {}".format(err))
return out
def do_list_ruleset():
@@ -123,7 +124,7 @@ def get_handle(output, search):
if not k in data:
continue
found = True
- for key in search[k].keys():
+ for key in list(search[k].keys()):
if key == "handle":
continue
if not key in data[k] or search[k][key] != data[k][key]:
@@ -140,7 +141,7 @@ def get_handle(output, search):
do_flush()
-print "Adding table t"
+print("Adding table t")
out = do_command(add_table)
handle = get_handle(out, add_table["add"])
@@ -152,7 +153,7 @@ if handle != handle_cmp:
add_table["add"]["table"]["handle"] = handle
-print "Adding chain c"
+print("Adding chain c")
out = do_command(add_chain)
handle = get_handle(out, add_chain["add"])
@@ -164,7 +165,7 @@ if handle != handle_cmp:
add_chain["add"]["chain"]["handle"] = handle
-print "Adding set s"
+print("Adding set s")
out = do_command(add_set)
handle = get_handle(out, add_set["add"])
@@ -176,7 +177,7 @@ if handle != handle_cmp:
add_set["add"]["set"]["handle"] = handle
-print "Adding rule"
+print("Adding rule")
out = do_command(add_rule)
handle = get_handle(out, add_rule["add"])
@@ -188,7 +189,7 @@ if handle != handle_cmp:
add_rule["add"]["rule"]["handle"] = handle
-print "Adding counter"
+print("Adding counter")
out = do_command(add_counter)
handle = get_handle(out, add_counter["add"])
@@ -200,7 +201,7 @@ if handle != handle_cmp:
add_counter["add"]["counter"]["handle"] = handle
-print "Adding quota"
+print("Adding quota")
out = do_command(add_quota)
handle = get_handle(out, add_quota["add"])
@@ -222,37 +223,37 @@ add_set["add"]["set"]["name"] = "s2"
add_counter["add"]["counter"]["name"] = "c2"
add_quota["add"]["quota"]["name"] = "q2"
-print "Adding table t2"
+print("Adding table t2")
out = do_command(add_table)
handle = get_handle(out, add_table["add"])
if handle == add_table["add"]["table"]["handle"]:
exit_err("handle not changed in re-added table!")
-print "Adding chain c2"
+print("Adding chain c2")
out = do_command(add_chain)
handle = get_handle(out, add_chain["add"])
if handle == add_chain["add"]["chain"]["handle"]:
exit_err("handle not changed in re-added chain!")
-print "Adding set s2"
+print("Adding set s2")
out = do_command(add_set)
handle = get_handle(out, add_set["add"])
if handle == add_set["add"]["set"]["handle"]:
exit_err("handle not changed in re-added set!")
-print "Adding rule again"
+print("Adding rule again")
out = do_command(add_rule)
handle = get_handle(out, add_rule["add"])
if handle == add_rule["add"]["rule"]["handle"]:
exit_err("handle not changed in re-added rule!")
-print "Adding counter c2"
+print("Adding counter c2")
out = do_command(add_counter)
handle = get_handle(out, add_counter["add"])
if handle == add_counter["add"]["counter"]["handle"]:
exit_err("handle not changed in re-added counter!")
-print "Adding quota q2"
+print("Adding quota q2")
out = do_command(add_quota)
handle = get_handle(out, add_quota["add"])
if handle == add_quota["add"]["quota"]["handle"]:
@@ -269,7 +270,7 @@ add_quota["add"]["quota"]["name"] = "q"
do_flush()
-print "doing multi add"
+print("doing multi add")
# XXX: Add table separately, otherwise this triggers cache bug
out = do_command(add_table)
thandle = get_handle(out, add_table["add"])
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH nft v2]tests: json_echo: convert to py3
2019-05-28 0:36 [PATCH nft v2]tests: json_echo: convert to py3 Shekhar Sharma
@ 2019-05-28 16:06 ` Phil Sutter
2019-05-28 16:13 ` shekhar sharma
2019-05-29 7:47 ` Pablo Neira Ayuso
[not found] ` <20190529074851.sjmnulacdufhhlmx@salvia>
2 siblings, 1 reply; 6+ messages in thread
From: Phil Sutter @ 2019-05-28 16:06 UTC (permalink / raw)
To: Shekhar Sharma; +Cc: netfilter-devel
Hi,
On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> This patch converts the run-test.py file to run on both python3 and python2.
> The version history of the patch is:
> v1: modified print and other statments.
> v2: updated the shebang and order of import statements.
I personally prefer to keep the respin-changelog out of the commit
message, again in a section between commit message and diffstat. My
approach is to rather make sure the commit message itself is up to date
and contains everything relevant worth keeping from the changelog. But
the topic is rather controversial (David Miller e.g. prefers the
changelog as part of the commit message), so you've just read a purely
informational monologue. :)
> Signed-off-by: Shekhar Sharma <shekhar250198@gmail.com>
Acked-by: Phil Sutter <phil@nwl.cc>
Thanks, Phil
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH nft v2]tests: json_echo: convert to py3
2019-05-28 16:06 ` Phil Sutter
@ 2019-05-28 16:13 ` shekhar sharma
0 siblings, 0 replies; 6+ messages in thread
From: shekhar sharma @ 2019-05-28 16:13 UTC (permalink / raw)
To: Phil Sutter, netfilter-devel
On Tue, May 28, 2019, 9:36 PM Phil Sutter <phil@nwl.cc> wrote:
>
> Hi,
>
> On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> > This patch converts the run-test.py file to run on both python3 and python2.
> > The version history of the patch is:
> > v1: modified print and other statments.
> > v2: updated the shebang and order of import statements.
>
> I personally prefer to keep the respin-changelog out of the commit
> message, again in a section between commit message and diffstat. My
> approach is to rather make sure the commit message itself is up to date
> and contains everything relevant worth keeping from the changelog. But
> the topic is rather controversial (David Miller e.g. prefers the
> changelog as part of the commit message), so you've just read a purely
> informational monologue. :)
>
> > Signed-off-by: Shekhar Sharma <shekhar250198@gmail.com>
>
> Acked-by: Phil Sutter <phil@nwl.cc>
>
> Thanks, Phil
Informational monologues like these are very useful to people like me. :-).
I very highly value suggestions like these.
With regards,
Shekhar
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH nft v2]tests: json_echo: convert to py3
2019-05-28 0:36 [PATCH nft v2]tests: json_echo: convert to py3 Shekhar Sharma
2019-05-28 16:06 ` Phil Sutter
@ 2019-05-29 7:47 ` Pablo Neira Ayuso
[not found] ` <20190529074851.sjmnulacdufhhlmx@salvia>
2 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-05-29 7:47 UTC (permalink / raw)
To: Shekhar Sharma; +Cc: netfilter-devel
On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> This patch converts the run-test.py file to run on both python3 and python2.
Applied, thanks Shekhar.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH nft v2]tests: json_echo: convert to py3
[not found] ` <20190529074851.sjmnulacdufhhlmx@salvia>
@ 2019-05-29 7:49 ` Pablo Neira Ayuso
2019-05-29 9:45 ` shekhar sharma
0 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-05-29 7:49 UTC (permalink / raw)
To: Shekhar Sharma; +Cc: netfilter-devel
On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py
> index 0132b139..dd7797fb 100755
> --- a/tests/json_echo/run-test.py
> +++ b/tests/json_echo/run-test.py
> @@ -1,5 +1,6 @@
> -#!/usr/bin/python2
> +#!/usr/bin/python
>
> +from __future__ import print_function
> import sys
> import os
> import json
> @@ -13,8 +14,8 @@ from nftables import Nftables
> os.chdir(TESTS_PATH + "/../..")
>
> if not os.path.exists('src/.libs/libnftables.so'):
> - print "The nftables library does not exist. " \
> - "You need to build the project."
> + print("The nftables library does not exist. "
> + "You need to build the project.")
> sys.exit(1)
>
> nftables = Nftables(sofile = 'src/.libs/libnftables.so')
> @@ -79,26 +80,26 @@ add_quota = { "add": {
> # helper functions
>
> def exit_err(msg):
> - print "Error: %s" % msg
> + print("Error: %s" %msg)
> sys.exit(1)
>
> def exit_dump(e, obj):
> - print "FAIL: %s" % e
> - print "Output was:"
> + print("FAIL: {}".format(e))
> + print("Output was:")
> json.dumps(out, sort_keys = True, indent = 4, separators = (',', ': '))
> sys.exit(1)
>
> def do_flush():
> rc, out, err = nftables.json_cmd({ "nftables": [flush_ruleset] })
> if not rc is 0:
> - exit_err("flush ruleset failed: %s" % err)
> + exit_err("flush ruleset failed: {}".format(err))
>
> def do_command(cmd):
> if not type(cmd) is list:
> cmd = [cmd]
> rc, out, err = nftables.json_cmd({ "nftables": cmd })
> if not rc is 0:
> - exit_err("command failed: %s" % err)
> + exit_err("command failed: {}".format(err))
> return out
>
> def do_list_ruleset():
> @@ -123,7 +124,7 @@ def get_handle(output, search):
> if not k in data:
> continue
> found = True
> - for key in search[k].keys():
> + for key in list(search[k].keys()):
list() is not necessary, as Eric already mentioned, right?
Your patch is already in git.netfilter.org, so I have already pushed
it out BTW. If this is the case, just avoid this in your follow up
patches for other existing scripts. Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH nft v2]tests: json_echo: convert to py3
2019-05-29 7:49 ` Pablo Neira Ayuso
@ 2019-05-29 9:45 ` shekhar sharma
0 siblings, 0 replies; 6+ messages in thread
From: shekhar sharma @ 2019-05-29 9:45 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Netfilter Development Mailing list
On Wed, May 29, 2019 at 1:19 PM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>
> On Tue, May 28, 2019 at 06:06:53AM +0530, Shekhar Sharma wrote:
> > diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py
> > index 0132b139..dd7797fb 100755
> > --- a/tests/json_echo/run-test.py
> > +++ b/tests/json_echo/run-test.py
> > @@ -1,5 +1,6 @@
> > -#!/usr/bin/python2
> > +#!/usr/bin/python
> >
> > +from __future__ import print_function
> > import sys
> > import os
> > import json
> > @@ -13,8 +14,8 @@ from nftables import Nftables
> > os.chdir(TESTS_PATH + "/../..")
> >
> > if not os.path.exists('src/.libs/libnftables.so'):
> > - print "The nftables library does not exist. " \
> > - "You need to build the project."
> > + print("The nftables library does not exist. "
> > + "You need to build the project.")
> > sys.exit(1)
> >
> > nftables = Nftables(sofile = 'src/.libs/libnftables.so')
> > @@ -79,26 +80,26 @@ add_quota = { "add": {
> > # helper functions
> >
> > def exit_err(msg):
> > - print "Error: %s" % msg
> > + print("Error: %s" %msg)
> > sys.exit(1)
> >
> > def exit_dump(e, obj):
> > - print "FAIL: %s" % e
> > - print "Output was:"
> > + print("FAIL: {}".format(e))
> > + print("Output was:")
> > json.dumps(out, sort_keys = True, indent = 4, separators = (',', ': '))
> > sys.exit(1)
> >
> > def do_flush():
> > rc, out, err = nftables.json_cmd({ "nftables": [flush_ruleset] })
> > if not rc is 0:
> > - exit_err("flush ruleset failed: %s" % err)
> > + exit_err("flush ruleset failed: {}".format(err))
> >
> > def do_command(cmd):
> > if not type(cmd) is list:
> > cmd = [cmd]
> > rc, out, err = nftables.json_cmd({ "nftables": cmd })
> > if not rc is 0:
> > - exit_err("command failed: %s" % err)
> > + exit_err("command failed: {}".format(err))
> > return out
> >
> > def do_list_ruleset():
> > @@ -123,7 +124,7 @@ def get_handle(output, search):
> > if not k in data:
> > continue
> > found = True
> > - for key in search[k].keys():
> > + for key in list(search[k].keys()):
>
> list() is not necessary, as Eric already mentioned, right?
>
> Your patch is already in git.netfilter.org, so I have already pushed
> it out BTW. If this is the case, just avoid this in your follow up
> patches for other existing scripts. Thanks.
Sure, I will change it in the follow up patches.
Thanks!
Shekhar
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-05-29 9:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 0:36 [PATCH nft v2]tests: json_echo: convert to py3 Shekhar Sharma
2019-05-28 16:06 ` Phil Sutter
2019-05-28 16:13 ` shekhar sharma
2019-05-29 7:47 ` Pablo Neira Ayuso
[not found] ` <20190529074851.sjmnulacdufhhlmx@salvia>
2019-05-29 7:49 ` Pablo Neira Ayuso
2019-05-29 9:45 ` shekhar sharma
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.