All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft 1/6] tests/py: remove unused variables
@ 2016-01-04 10:43 Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 2/6] tests/py: fix style Pablo M. Bermudo Garay
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

Only that. The script had a lot of unused variables.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/nft-test.py | 39 +++++++++------------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index e68087f..cfea1b1 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -19,7 +19,6 @@ import subprocess
 import argparse
 import signal
 
-TERMINAL_PATH = os.getcwd()
 NFT_BIN = "src/nft"
 TESTS_PATH = os.path.dirname(os.path.abspath(__file__))
 TESTS_DIRECTORY = ["any", "arp", "bridge", "inet", "ip", "ip6"]
@@ -68,7 +67,7 @@ def print_differences_warning(filename, lineno, rule1, rule2, cmd):
         "line: " + str(lineno + 1) + ": '" + cmd + "': " + reason
 
 
-def print_differences_error(filename, lineno, output, cmd):
+def print_differences_error(filename, lineno, cmd):
     reason = "Listing is broken."
     print filename + ": " + Colors.RED + "ERROR: " + Colors.ENDC + \
         "line: " + str(lineno + 1) + ": '" + cmd + "': " + reason
@@ -89,7 +88,7 @@ def table_flush(table, filename, lineno):
     Flush a table.
     '''
     cmd = NFT_BIN + " flush table " + str(table[0]) + " " + str(table[1])
-    ret = execute_cmd(cmd, filename, lineno)
+    execute_cmd(cmd, filename, lineno)
 
     return cmd
 
@@ -453,8 +452,6 @@ def payload_check_set_elems(want, got):
 def payload_check(payload_buffer, file, cmd):
 
     file.seek(0, 0)
-
-    ret = False
     i = 0
 
     for lineno, want_line in enumerate(payload_buffer):
@@ -511,7 +508,7 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
             unit_tests += 1
             table_flush(table, filename, lineno)
             table_info = " " + table[0] + " " + table[1] + " "
-            cmd = NFT_BIN + " add rule" + table_info + chain + " " + rule[0]
+            NFT_BIN + " add rule" + table_info + chain + " " + rule[0]
 
             payload_log = os.tmpfile();
 
@@ -583,7 +580,7 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
                             if len(rule_output) <= 0:
                                 error += 1
                                 print_differences_error(filename, lineno,
-                                                        rule_output, cmd)
+                                                        cmd)
                                 if not force_all_family_option:
                                     return [ret, warning, error, unit_tests]
 
@@ -605,10 +602,10 @@ def preexec():
 def cleanup_on_exit():
     for table in table_list:
         for chain in chain_list:
-            ret = chain_delete(chain, table, "", "")
+            chain_delete(chain, table, "", "")
         if all_set:
-            ret = set_delete(all_set, table)
-        ret = table_delete(table)
+            set_delete(all_set, table)
+        table_delete(table)
 
 
 def signal_handler(signal, frame):
@@ -711,7 +708,6 @@ def payload_find_expected(payload_log, rule):
     :param rule: nft rule we are going to add
     '''
     found = 0
-    pos = 0
     payload_buffer = []
 
     while True:
@@ -740,16 +736,9 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
     :param filename: name of the file with the test rules
     '''
-
-    if specific_file:
-        filename_path = os.path.join(TERMINAL_PATH, filename)
-    else:
-        filename_path = os.path.join(TESTS_PATH, filename)
-
+    filename_path = os.path.join(TESTS_PATH, filename)
     f = open(filename_path)
     tests = passed = total_unit_run = total_warning = total_error = 0
-    table = ""
-    total_test_passed = True
 
     for lineno, line in enumerate(f):
         if signal_received == 1:
@@ -767,7 +756,6 @@ def run_test_file(filename, force_all_family_option, specific_file):
             table_line = line.rstrip()[1:]
             ret = table_process(table_line, filename, lineno)
             if (ret != 0):
-                total_test_passed = False
                 break
             continue
 
@@ -775,7 +763,6 @@ def run_test_file(filename, force_all_family_option, specific_file):
             chain_line = line.rstrip()[1:].split(";")
             ret = chain_process(chain_line, filename, lineno)
             if ret != 0:
-                total_test_passed = False
                 break
             continue
 
@@ -784,7 +771,6 @@ def run_test_file(filename, force_all_family_option, specific_file):
             ret = set_process(set_line, filename, lineno)
             tests += 1
             if ret == -1:
-                total_test_passed = False
                 continue
             passed += 1
             continue
@@ -794,7 +780,6 @@ def run_test_file(filename, force_all_family_option, specific_file):
             ret = set_element_process(element_line, filename, lineno)
             tests += 1
             if ret == -1:
-                total_test_passed = False
                 continue
 
             passed += 1
@@ -825,7 +810,6 @@ def run_test_file(filename, force_all_family_option, specific_file):
         total_unit_run += result[3]
 
         if ret != 0:
-            total_test_passed = False
             continue
 
         if warning == 0:  # All ok.
@@ -837,21 +821,16 @@ def run_test_file(filename, force_all_family_option, specific_file):
         for chain in chain_list:
             ret = chain_delete(chain, table, filename, lineno)
             if ret != 0:
-                total_test_passed = False
 
         # We delete sets.
         if all_set:
             ret = set_delete(all_set, table, filename, lineno)
             if ret != 0:
-                total_test_passed = False
                 reason = "There is a problem when we delete a set"
                 print_error(reason, filename, lineno)
 
         # We delete tables.
-        ret = table_delete(table, filename, lineno)
-
-        if ret != 0:
-            total_test_passed = False
+        table_delete(table, filename, lineno)
 
     if specific_file:
         if force_all_family_option:
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nft 2/6] tests/py: fix style
  2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
@ 2016-01-04 10:43 ` Pablo M. Bermudo Garay
  2016-01-04 11:32   ` Pablo Neira Ayuso
  2016-01-04 10:43 ` [PATCH nft 3/6] tests/py: simplify use of globals Pablo M. Bermudo Garay
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

- Adjust lines to 120 columns style
- Add two lines of separation between functions
- Remove redundant parentheses and semicolons
- Apply other minor style fixes

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/nft-test.py | 218 +++++++++++++++++++++------------------------------
 1 file changed, 89 insertions(+), 129 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index cfea1b1..3a2082b 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -44,33 +44,35 @@ class Colors:
         RED = ''
         ENDC = ''
 
+
 def print_msg(reason, filename=None, lineno=None, color=None, errstr=None):
     '''
     Prints a message with nice colors, indicating file and line number.
     '''
     if filename and lineno:
-        print (filename + ": " + color + "ERROR:" +
-               Colors.ENDC + " line %d: %s" % (lineno + 1, reason))
+        print filename + ": " + color + "ERROR:" + Colors.ENDC + " line %d: %s" % (lineno + 1, reason)
     else:
-        print (color + "ERROR:" + Colors.ENDC + " %s" % (reason))
+        print color + "ERROR:" + Colors.ENDC + " %s" % reason
+
 
 def print_error(reason, filename=None, lineno=None):
     print_msg(reason, filename, lineno, Colors.RED, "ERROR:")
 
+
 def print_warning(reason, filename=None, lineno=None):
     print_msg(reason, filename, lineno, Colors.YELLOW, "WARNING:")
 
 
 def print_differences_warning(filename, lineno, rule1, rule2, cmd):
     reason = "'" + rule1 + "' mismatches '" + rule2 + "'"
-    print filename + ": " + Colors.YELLOW + "WARNING: " + Colors.ENDC + \
-        "line: " + str(lineno + 1) + ": '" + cmd + "': " + reason
+    print filename + ": " + Colors.YELLOW + "WARNING: " + Colors.ENDC + "line: " + str(lineno + 1) + ": '" + cmd + \
+          "': " + reason
 
 
 def print_differences_error(filename, lineno, cmd):
     reason = "Listing is broken."
-    print filename + ": " + Colors.RED + "ERROR: " + Colors.ENDC + \
-        "line: " + str(lineno + 1) + ": '" + cmd + "': " + reason
+    print filename + ": " + Colors.RED + "ERROR: " + Colors.ENDC + "line: " + str(lineno + 1) + ": '" + cmd + "': " + \
+          reason
 
 
 def table_exist(table, filename, lineno):
@@ -97,7 +99,7 @@ def table_create(table, filename, lineno):
     '''
     Adds a table.
     '''
-    ## We check if table exists.
+    # We check if table exists.
     if table_exist(table, filename, lineno):
         reason = "Table " + table[1] + " already exists"
         print_error(reason, filename, lineno)
@@ -105,7 +107,7 @@ def table_create(table, filename, lineno):
 
     table_list.append(table)
 
-    ## We add a new table
+    # We add a new table
     cmd = NFT_BIN + " add table " + table[0] + " " + table[1]
     ret = execute_cmd(cmd, filename, lineno)
 
@@ -115,11 +117,10 @@ def table_create(table, filename, lineno):
         table_list.remove(table)
         return -1
 
-    ## We check if table was added correctly.
+    # We check if table was added correctly.
     if not table_exist(table, filename, lineno):
         table_list.remove(table)
-        reason = "I have just added the table " + table[1] + \
-            " but it does not exist. Giving up!"
+        reason = "I have just added the table " + table[1] + " but it does not exist. Giving up!"
         print_error(reason, filename, lineno)
         return -1
 
@@ -133,22 +134,19 @@ def table_delete(table, filename=None, lineno=None):
     table_info = " " + table[0] + " " + table[1] + " "
 
     if not table_exist(table, filename, lineno):
-        reason = "Table " + table[1] + \
-            " does not exist but I added it before."
+        reason = "Table " + table[1] + " does not exist but I added it before."
         print_error(reason, filename, lineno)
         return -1
 
     cmd = NFT_BIN + " delete table" + table_info
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = cmd + ": " \
-            "I cannot delete table '" + table[1] + "'. Giving up! "
+        reason = cmd + ": " + "I cannot delete table '" + table[1] + "'. Giving up! "
         print_error(reason, filename, lineno)
         return -1
 
     if table_exist(table, filename, lineno):
-        reason = "I have just deleted the table " + table[1] + \
-            " but the table still exists."
+        reason = "I have just deleted the table " + table[1] + " but the table still exists."
         print_error(reason, filename, lineno)
         return -1
 
@@ -159,7 +157,6 @@ def chain_exist(chain, table, filename, lineno):
     '''
     Checks a chain
     '''
-
     table_info = " " + table[0] + " " + table[1] + " "
     cmd = NFT_BIN + " list -nnn chain" + table_info + chain
     ret = execute_cmd(cmd, filename, lineno)
@@ -171,12 +168,10 @@ def chain_create(chain, chain_type, chain_list, table, filename, lineno):
     '''
     Adds a chain
     '''
-
     table_info = " " + table[0] + " " + table[1] + " "
 
     if chain_exist(chain, table, filename, lineno):
-        reason = "This chain '" + chain + "' exists in " + table[1] + "." + \
-            "I cannot create two chains with same name."
+        reason = "This chain '" + chain + "' exists in " + table[1] + ". I cannot create two chains with same name."
         print_error(reason, filename, lineno)
         return -1
 
@@ -191,28 +186,25 @@ def chain_create(chain, chain_type, chain_list, table, filename, lineno):
         print_error(reason, filename, lineno)
         return -1
 
-    if not chain in chain_list:
+    if chain not in chain_list:
         chain_list.append(chain)
 
     if not chain_exist(chain, table, filename, lineno):
-        reason = "I have added the chain '" + chain + \
-            "' but it does not exist in " + table[1]
+        reason = "I have added the chain '" + chain + "' but it does not exist in " + table[1]
         print_error(reason, filename, lineno)
         return -1
 
     return 0
 
 
-def chain_delete(chain, table,  filename=None, lineno=None):
+def chain_delete(chain, table, filename=None, lineno=None):
     '''
     Flushes and deletes a chain.
     '''
-
     table_info = " " + table[0] + " " + table[1] + " "
 
     if not chain_exist(chain, table, filename, lineno):
-        reason = "The chain " + chain + " does not exists in " + table[1] + \
-            ". I cannot delete it."
+        reason = "The chain " + chain + " does not exists in " + table[1] + ". I cannot delete it."
         print_error(reason, filename, lineno)
         return -1
 
@@ -231,8 +223,7 @@ def chain_delete(chain, table,  filename=None, lineno=None):
         return -1
 
     if chain_exist(chain, table, filename, lineno):
-        reason = "The chain " + chain + " exists in " + table[1] + \
-            ". I cannot delete this chain"
+        reason = "The chain " + chain + " exists in " + table[1] + ". I cannot delete this chain"
         print_error(reason, filename, lineno)
         return -1
 
@@ -243,7 +234,6 @@ def set_add(set_info, table_list, filename, lineno):
     '''
     Adds a set.
     '''
-
     if not table_list:
         reason = "Missing table to add rule"
         print_error(reason, filename, lineno)
@@ -251,8 +241,7 @@ def set_add(set_info, table_list, filename, lineno):
 
     for table in table_list:
         if set_exist(set_info[0], table, filename, lineno):
-            reason = "This set " + set_info + " exists in " + table[1] + \
-                ". I cannot add it again"
+            reason = "This set " + set_info + " exists in " + table[1] + ". I cannot add it again"
             print_error(reason, filename, lineno)
             return -1
 
@@ -261,27 +250,23 @@ def set_add(set_info, table_list, filename, lineno):
         cmd = NFT_BIN + " add set" + table_info + set_text
         ret = execute_cmd(cmd, filename, lineno)
 
-        if (ret == 0 and set_info[2].rstrip() == "fail") or \
-           (ret != 0 and set_info[2].rstrip() == "ok"):
-                reason = cmd + ": " + "I cannot add the set " + set_info[0]
-                print_error(reason, filename, lineno)
-                return -1
+        if (ret == 0 and set_info[2].rstrip() == "fail") or (ret != 0 and set_info[2].rstrip() == "ok"):
+            reason = cmd + ": " + "I cannot add the set " + set_info[0]
+            print_error(reason, filename, lineno)
+            return -1
 
         if not set_exist(set_info[0], table, filename, lineno):
-            reason = "I have just added the set " + set_info[0] + \
-                " to the table " + table[1] + " but it does not exist"
+            reason = "I have just added the set " + set_info[0] + " to the table " + table[1] + " but it does not exist"
             print_error(reason, filename, lineno)
             return -1
 
     return 0
 
 
-def set_add_elements(set_element, set_name, set_all, state, table_list,
-                     filename, lineno):
+def set_add_elements(set_element, set_name, set_all, state, table_list, filename, lineno):
     '''
     Adds elements to the set.
     '''
-
     if not table_list:
         reason = "Missing table to add rules"
         print_error(reason, filename, lineno)
@@ -289,10 +274,8 @@ def set_add_elements(set_element, set_name, set_all, state, table_list,
 
     for table in table_list:
         # Check if set exists.
-        if (not set_exist(set_name, table, filename, lineno) or
-           not set_name in set_all) and state == "ok":
-            reason = "I cannot add an element to the set " + set_name + \
-                " since it does not exist."
+        if (not set_exist(set_name, table, filename, lineno) or set_name not in set_all) and state == "ok":
+            reason = "I cannot add an element to the set " + set_name + " since it does not exist."
             print_error(reason, filename, lineno)
             return -1
 
@@ -310,21 +293,20 @@ def set_add_elements(set_element, set_name, set_all, state, table_list,
         ret = execute_cmd(cmd, filename, lineno)
 
         if (state == "fail" and ret == 0) or (state == "ok" and ret != 0):
-                test_state = "This rule should have failed."
-                reason = cmd + ": " + test_state
-                print_error(reason, filename, lineno)
-                return -1
+            test_state = "This rule should have failed."
+            reason = cmd + ": " + test_state
+            print_error(reason, filename, lineno)
+            return -1
 
         # Add element into a all_set.
-        if (ret == 0 and state == "ok"):
+        if ret == 0 and state == "ok":
             for e in set_element:
                 set_all[set_name].add(e)
 
     return 0
 
 
-def set_delete_elements(set_element, set_name, table, filename=None,
-                        lineno=None):
+def set_delete_elements(set_element, set_name, table, filename=None, lineno=None):
     '''
     Deletes elements in a set.
     '''
@@ -335,8 +317,7 @@ def set_delete_elements(set_element, set_name, table, filename=None,
         cmd = NFT_BIN + " delete element" + table_info + set_text
         ret = execute_cmd(cmd, filename, lineno)
         if ret != 0:
-            reason = "I cannot delete an element" + element + \
-                " from the set '" + set_name
+            reason = "I cannot delete an element" + element + " from the set '" + set_name
             print_error(reason, filename, lineno)
             return -1
 
@@ -347,18 +328,15 @@ def set_delete(all_set, table, filename=None, lineno=None):
     '''
     Deletes set and its content.
     '''
-
     for set_name in all_set.keys():
         # Check if exists the set
         if not set_exist(set_name, table, filename, lineno):
-            reason = "The set " + set_name + \
-                " does not exist, I cannot delete it"
+            reason = "The set " + set_name + " does not exist, I cannot delete it"
             print_error(reason, filename, lineno)
             return -1
 
         # We delete all elements in the set
-        set_delete_elements(all_set[set_name], set_name, table, filename,
-                            lineno)
+        set_delete_elements(all_set[set_name], set_name, table, filename, lineno)
 
         # We delete the set.
         table_info = " " + table[0] + " " + table[1] + " "
@@ -395,12 +373,12 @@ def set_check_element(rule1, rule2):
     end1 = rule1.find("}")
     end2 = rule2.find("}")
 
-    if ((pos1 != -1) and (pos2 != -1) and (end1 != -1) and (end2 != -1)):
+    if (pos1 != -1) and (pos2 != -1) and (end1 != -1) and (end2 != -1):
         list1 = (rule1[pos1 + 1:end1].replace(" ", "")).split(",")
         list2 = (rule2[pos2 + 1:end2].replace(" ", "")).split(",")
         list1.sort()
         list2.sort()
-        if (cmp(list1, list2) == 0):
+        if cmp(list1, list2) == 0:
             ret = 0
     return ret
 
@@ -423,6 +401,7 @@ def output_clean(pre_output, chain):
         return ""
     return rule
 
+
 def payload_check_elems_to_set(elems):
     newset = set()
 
@@ -436,8 +415,8 @@ def payload_check_elems_to_set(elems):
 
     return newset
 
-def payload_check_set_elems(want, got):
 
+def payload_check_set_elems(want, got):
     if want.find('element') < 0 or want.find('[end]') < 0:
         return 0
 
@@ -449,8 +428,8 @@ def payload_check_set_elems(want, got):
 
     return set_want == set_got
 
-def payload_check(payload_buffer, file, cmd):
 
+def payload_check(payload_buffer, file, cmd):
     file.seek(0, 0)
     i = 0
 
@@ -469,13 +448,13 @@ def payload_check(payload_buffer, file, cmd):
         if payload_check_set_elems(want_line, line):
             continue
 
-        print_differences_warning(file.name, lineno, want_line.strip(), line.strip(), cmd);
+        print_differences_warning(file.name, lineno, want_line.strip(), line.strip(), cmd)
         return 0
 
     return i > 0
 
-def rule_add(rule, table_list, chain_list, filename, lineno,
-             force_all_family_option, filename_path):
+
+def rule_add(rule, table_list, chain_list, filename, lineno, force_all_family_option, filename_path):
     '''
     Adds a rule
     '''
@@ -492,25 +471,24 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
     for table in table_list:
         try:
             payload_log = open("%s.payload.%s" % (filename_path, table[0]))
-        except (IOError):
+        except IOError:
             payload_log = open("%s.payload" % filename_path)
 
         if rule[1].strip() == "ok":
             try:
                 payload_expected.index(rule[0])
-            except (ValueError):
+            except ValueError:
                 payload_expected = payload_find_expected(payload_log, rule[0])
 
-                if payload_expected == []:
+                if not payload_expected:
                     print_error("did not find payload information for rule '%s'" % rule[0], payload_log.name, 1)
 
         for chain in chain_list:
             unit_tests += 1
             table_flush(table, filename, lineno)
             table_info = " " + table[0] + " " + table[1] + " "
-            NFT_BIN + " add rule" + table_info + chain + " " + rule[0]
 
-            payload_log = os.tmpfile();
+            payload_log = os.tmpfile()
 
             cmd = NFT_BIN + " add rule --debug=netlink" + table_info + chain + " " + rule[0]
             ret = execute_cmd(cmd, filename, lineno, payload_log)
@@ -528,12 +506,12 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
                 if not force_all_family_option:
                     return [ret, warning, error, unit_tests]
 
-            if (state == "fail" and ret != 0):
+            if state == "fail" and ret != 0:
                 ret = 0
                 continue
 
             if ret == 0:
-            # Check for matching payload
+                # Check for matching payload
                 if state == "ok" and not payload_check(payload_expected, payload_log, cmd):
                     error += 1
                     gotf = open("%s.payload.got" % filename_path, 'a')
@@ -547,10 +525,9 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
                     gotf.close()
                     print_warning("Wrote payload for rule %s" % rule[0], gotf.name, 1)
 
-            # Check output of nft
-                process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table'] + table,
-                                           shell=False, stdout=subprocess.PIPE,
-                                           preexec_fn=preexec)
+                # Check output of nft
+                process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table'] + table, shell=False,
+                                           stdout=subprocess.PIPE, preexec_fn=preexec)
                 pre_output = process.communicate()
                 output = pre_output[0].split(";")
                 if len(output) < 2:
@@ -562,32 +539,27 @@ def rule_add(rule, table_list, chain_list, filename, lineno,
                         return [ret, warning, error, unit_tests]
                 else:
                     rule_output = output_clean(pre_output, chain)
-                    if (len(rule) == 3):
+                    if len(rule) == 3:
                         teoric_exit = rule[2]
                     else:
                         teoric_exit = rule[0]
 
-                    if (rule_output.rstrip() != teoric_exit.rstrip()):
-                        if (rule[0].find("{") != -1):  # anonymous sets
-                            if (set_check_element(teoric_exit, rule_output) != 0):
+                    if rule_output.rstrip() != teoric_exit.rstrip():
+                        if rule[0].find("{") != -1:  # anonymous sets
+                            if set_check_element(teoric_exit, rule_output) != 0:
                                 warning += 1
-                                print_differences_warning(filename, lineno,
-                                                          rule[0], rule_output,
-                                                          cmd)
+                                print_differences_warning(filename, lineno, rule[0], rule_output, cmd)
                                 if not force_all_family_option:
                                     return [ret, warning, error, unit_tests]
                         else:
                             if len(rule_output) <= 0:
                                 error += 1
-                                print_differences_error(filename, lineno,
-                                                        cmd)
+                                print_differences_error(filename, lineno, cmd)
                                 if not force_all_family_option:
                                     return [ret, warning, error, unit_tests]
 
                             warning += 1
-                            print_differences_warning(filename, lineno,
-                                                      teoric_exit.rstrip(), rule_output,
-                                                      cmd)
+                            print_differences_warning(filename, lineno, teoric_exit.rstrip(), rule_output, cmd)
 
                             if not force_all_family_option:
                                 return [ret, warning, error, unit_tests]
@@ -613,7 +585,7 @@ def signal_handler(signal, frame):
     signal_received = 1
 
 
-def execute_cmd(cmd, filename, lineno, stdout_log = False):
+def execute_cmd(cmd, filename, lineno, stdout_log=False):
     '''
     Executes a command, checks for segfaults and returns the command exit
     code.
@@ -643,18 +615,16 @@ def execute_cmd(cmd, filename, lineno, stdout_log = False):
 
 
 def print_result(filename, tests, warning, error):
-    return str(filename) + ": " + str(tests) + " unit tests, " + \
-        str(error) + " error, " + str(warning) + " warning"
+    return str(filename) + ": " + str(tests) + " unit tests, " + str(error) + " error, " + str(warning) + " warning"
 
 
 def print_result_all(filename, tests, warning, error, unit_tests):
-        return str(filename) + ": " + str(tests) + " unit tests, " +\
-            str(unit_tests) + " total test executed, " + \
-            str(error) + " error, " + \
-            str(warning) + " warning"
+    return str(filename) + ": " + str(tests) + " unit tests, " + str(unit_tests) + " total test executed, " + \
+           str(error) + " error, " + str(warning) + " warning"
 
 
 def table_process(table_line, filename, lineno):
+    table_info = []
     if ";" in table_line:
         table_info = table_line.split(";")
     else:
@@ -670,11 +640,10 @@ def chain_process(chain_line, filename, lineno):
     for table in table_list:
         if len(chain_line) > 1:
             chain_type = chain_line[1]
-        ret = chain_create(chain_name, chain_type, chain_list, table,
-                            filename, lineno)
+        ret = chain_create(chain_name, chain_type, chain_list, table, filename, lineno)
         if ret != 0:
             return -1
-    return ret
+    return 0
 
 
 def set_process(set_line, filename, lineno):
@@ -697,8 +666,8 @@ def set_element_process(element_line, filename, lineno):
     set_name = element_line[0].split(" ")[0]
     set_element = element_line[0].split(" ")
     set_element.remove(set_name)
-    return set_add_elements(set_element, set_name, all_set, rule_state,
-                            table_list, filename, lineno)
+    return set_add_elements(set_element, set_name, all_set, rule_state, table_list, filename, lineno)
+
 
 def payload_find_expected(payload_log, rule):
     '''
@@ -730,6 +699,7 @@ def payload_find_expected(payload_log, rule):
     payload_log.seek(0, 0)
     return payload_buffer
 
+
 def run_test_file(filename, force_all_family_option, specific_file):
     '''
     Runs a test file
@@ -755,7 +725,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
         if line[0] == '*':  # Table
             table_line = line.rstrip()[1:]
             ret = table_process(table_line, filename, lineno)
-            if (ret != 0):
+            if ret != 0:
                 break
             continue
 
@@ -800,8 +770,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
         elif need_fix_option:
             continue
 
-        result = rule_add(rule, table_list, chain_list, filename, lineno,
-                          force_all_family_option, filename_path)
+        result = rule_add(rule, table_list, chain_list, filename, lineno, force_all_family_option, filename_path)
         tests += 1
         ret = result[0]
         warning = result[1]
@@ -819,8 +788,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
     for table in table_list:
         # We delete chains
         for chain in chain_list:
-            ret = chain_delete(chain, table, filename, lineno)
-            if ret != 0:
+            chain_delete(chain, table, filename, lineno)
 
         # We delete sets.
         if all_set:
@@ -834,12 +802,11 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
     if specific_file:
         if force_all_family_option:
-            print print_result_all(filename, tests, total_warning, total_error,
-                                   total_unit_run)
+            print print_result_all(filename, tests, total_warning, total_error, total_unit_run)
         else:
             print print_result(filename, tests, total_warning, total_error)
     else:
-        if (tests == passed and tests > 0):
+        if tests == passed and tests > 0:
             print filename + ": " + Colors.GREEN + "OK" + Colors.ENDC
 
     f.close()
@@ -851,23 +818,15 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
 
 def main():
-    parser = argparse.ArgumentParser(description='Run nft tests',
-                                     version='1.0')
+    parser = argparse.ArgumentParser(description='Run nft tests', version='1.0')
 
-    parser.add_argument('filename', nargs='?',
-                        metavar='path/to/file.t',
-                        help='Run only this test')
+    parser.add_argument('filename', nargs='?', metavar='path/to/file.t', help='Run only this test')
 
-    parser.add_argument('-d', '--debug', action='store_true',
-                        dest='debug',
-                        help='enable debugging mode')
+    parser.add_argument('-d', '--debug', action='store_true', dest='debug', help='enable debugging mode')
 
-    parser.add_argument('-e', '--need-fix', action='store_true',
-                        dest='need_fix_line',
-                        help='run rules that need a fix')
+    parser.add_argument('-e', '--need-fix', action='store_true', dest='need_fix_line', help='run rules that need a fix')
 
-    parser.add_argument('-f', '--force-family', action='store_true',
-                        dest='force_all_family',
+    parser.add_argument('-f', '--force-family', action='store_true', dest='force_all_family',
                         help='keep testing all families on error')
 
     args = parser.parse_args()
@@ -937,11 +896,12 @@ def main():
     else:
         if not specific_file:
             if force_all_family_option:
-                print ("%d test files, %d files passed, %d unit tests, %d total executed, %d error, %d warning" %
-                      (test_files, files_ok, tests, run_total, errors, warnings))
+                print "%d test files, %d files passed, %d unit tests, %d total executed, %d error, %d warning" \
+                      % (test_files, files_ok, tests, run_total, errors, warnings)
             else:
-                print ("%d test files, %d files passed, %d unit tests, %d error, %d warning" %
-                      (test_files, files_ok, tests, errors, warnings))
+                print "%d test files, %d files passed, %d unit tests, %d error, %d warning" \
+                      % (test_files, files_ok, tests, errors, warnings)
+
 
 if __name__ == '__main__':
     main()
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nft 3/6] tests/py: simplify use of globals
  2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 2/6] tests/py: fix style Pablo M. Bermudo Garay
@ 2016-01-04 10:43 ` Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 4/6] tests/py: convert chains and tables to objects Pablo M. Bermudo Garay
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

The script made a messy use of globals, these was sometimes accessed
directly and passed as parameter in other cases.

Since is not expected having to deal with threads in the script, now the
globals are always accessed directly for the sake of simplicity.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/nft-test.py | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 3a2082b..f5d5d84 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -164,7 +164,7 @@ def chain_exist(chain, table, filename, lineno):
     return True if (ret == 0) else False
 
 
-def chain_create(chain, chain_type, chain_list, table, filename, lineno):
+def chain_create(chain, chain_type, table, filename, lineno):
     '''
     Adds a chain
     '''
@@ -230,7 +230,7 @@ def chain_delete(chain, table, filename=None, lineno=None):
     return 0
 
 
-def set_add(set_info, table_list, filename, lineno):
+def set_add(set_info, filename, lineno):
     '''
     Adds a set.
     '''
@@ -263,7 +263,7 @@ def set_add(set_info, table_list, filename, lineno):
     return 0
 
 
-def set_add_elements(set_element, set_name, set_all, state, table_list, filename, lineno):
+def set_add_elements(set_element, set_name, state, filename, lineno):
     '''
     Adds elements to the set.
     '''
@@ -274,7 +274,7 @@ def set_add_elements(set_element, set_name, set_all, state, table_list, filename
 
     for table in table_list:
         # Check if set exists.
-        if (not set_exist(set_name, table, filename, lineno) or set_name not in set_all) and state == "ok":
+        if (not set_exist(set_name, table, filename, lineno) or set_name not in all_set) and state == "ok":
             reason = "I cannot add an element to the set " + set_name + " since it does not exist."
             print_error(reason, filename, lineno)
             return -1
@@ -301,7 +301,7 @@ def set_add_elements(set_element, set_name, set_all, state, table_list, filename
         # Add element into a all_set.
         if ret == 0 and state == "ok":
             for e in set_element:
-                set_all[set_name].add(e)
+                all_set[set_name].add(e)
 
     return 0
 
@@ -324,7 +324,7 @@ def set_delete_elements(set_element, set_name, table, filename=None, lineno=None
     return 0
 
 
-def set_delete(all_set, table, filename=None, lineno=None):
+def set_delete(table, filename=None, lineno=None):
     '''
     Deletes set and its content.
     '''
@@ -454,7 +454,7 @@ def payload_check(payload_buffer, file, cmd):
     return i > 0
 
 
-def rule_add(rule, table_list, chain_list, filename, lineno, force_all_family_option, filename_path):
+def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
     '''
     Adds a rule
     '''
@@ -576,7 +576,7 @@ def cleanup_on_exit():
         for chain in chain_list:
             chain_delete(chain, table, "", "")
         if all_set:
-            set_delete(all_set, table)
+            set_delete(table)
         table_delete(table)
 
 
@@ -640,7 +640,7 @@ def chain_process(chain_line, filename, lineno):
     for table in table_list:
         if len(chain_line) > 1:
             chain_type = chain_line[1]
-        ret = chain_create(chain_name, chain_type, chain_list, table, filename, lineno)
+        ret = chain_create(chain_name, chain_type, table, filename, lineno)
         if ret != 0:
             return -1
     return 0
@@ -654,7 +654,7 @@ def set_process(set_line, filename, lineno):
     set_state = set_line[1].split(";")[1]  # ok or fail
     set_info.append(set_type)
     set_info.append(set_state)
-    ret = set_add(set_info, table_list, filename, lineno)
+    ret = set_add(set_info, filename, lineno)
     if ret == 0:
         all_set[set_name] = set()
 
@@ -666,7 +666,7 @@ def set_element_process(element_line, filename, lineno):
     set_name = element_line[0].split(" ")[0]
     set_element = element_line[0].split(" ")
     set_element.remove(set_name)
-    return set_add_elements(set_element, set_name, all_set, rule_state, table_list, filename, lineno)
+    return set_add_elements(set_element, set_name, rule_state, filename, lineno)
 
 
 def payload_find_expected(payload_log, rule):
@@ -770,7 +770,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
         elif need_fix_option:
             continue
 
-        result = rule_add(rule, table_list, chain_list, filename, lineno, force_all_family_option, filename_path)
+        result = rule_add(rule, filename, lineno, force_all_family_option, filename_path)
         tests += 1
         ret = result[0]
         warning = result[1]
@@ -792,7 +792,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
         # We delete sets.
         if all_set:
-            ret = set_delete(all_set, table, filename, lineno)
+            ret = set_delete(table, filename, lineno)
             if ret != 0:
                 reason = "There is a problem when we delete a set"
                 print_error(reason, filename, lineno)
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nft 4/6] tests/py: convert chains and tables to objects
  2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 2/6] tests/py: fix style Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 3/6] tests/py: simplify use of globals Pablo M. Bermudo Garay
@ 2016-01-04 10:43 ` Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 5/6] tests/py: modify supported test file syntax Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 6/6] tests/py: update test files syntax Pablo M. Bermudo Garay
  4 siblings, 0 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

Now these concepts are represented by objects instead of lists or sparse
parameters.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/nft-test.py | 121 +++++++++++++++++++++++++++++----------------------
 1 file changed, 68 insertions(+), 53 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index f5d5d84..e379a0f 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -45,6 +45,28 @@ class Colors:
         ENDC = ''
 
 
+class Chain:
+    """Class that represents a chain"""
+
+    def __init__(self, name, config):
+        self.name = name
+        self.config = config
+
+    def __eq__(self, other):
+        return self.__dict__ == other.__dict__
+
+
+class Table:
+    """Class that represents a table"""
+
+    def __init__(self, family, name):
+        self.family = family
+        self.name = name
+
+    def __eq__(self, other):
+        return self.__dict__ == other.__dict__
+
+
 def print_msg(reason, filename=None, lineno=None, color=None, errstr=None):
     '''
     Prints a message with nice colors, indicating file and line number.
@@ -79,7 +101,7 @@ def table_exist(table, filename, lineno):
     '''
     Exists a table.
     '''
-    cmd = NFT_BIN + " list -nnn table " + table[0] + " " + table[1]
+    cmd = NFT_BIN + " list -nnn table " + table.family + " " + table.name
     ret = execute_cmd(cmd, filename, lineno)
 
     return True if (ret == 0) else False
@@ -89,7 +111,7 @@ def table_flush(table, filename, lineno):
     '''
     Flush a table.
     '''
-    cmd = NFT_BIN + " flush table " + str(table[0]) + " " + str(table[1])
+    cmd = NFT_BIN + " flush table " + table.family + " " + table.name
     execute_cmd(cmd, filename, lineno)
 
     return cmd
@@ -101,18 +123,18 @@ def table_create(table, filename, lineno):
     '''
     # We check if table exists.
     if table_exist(table, filename, lineno):
-        reason = "Table " + table[1] + " already exists"
+        reason = "Table " + table.name + " already exists"
         print_error(reason, filename, lineno)
         return -1
 
     table_list.append(table)
 
     # We add a new table
-    cmd = NFT_BIN + " add table " + table[0] + " " + table[1]
+    cmd = NFT_BIN + " add table " + table.family + " " + table.name
     ret = execute_cmd(cmd, filename, lineno)
 
     if ret != 0:
-        reason = "Cannot add table " + table[1]
+        reason = "Cannot add table " + table.name
         print_error(reason, filename, lineno)
         table_list.remove(table)
         return -1
@@ -120,7 +142,7 @@ def table_create(table, filename, lineno):
     # We check if table was added correctly.
     if not table_exist(table, filename, lineno):
         table_list.remove(table)
-        reason = "I have just added the table " + table[1] + " but it does not exist. Giving up!"
+        reason = "I have just added the table " + table.name + " but it does not exist. Giving up!"
         print_error(reason, filename, lineno)
         return -1
 
@@ -131,22 +153,22 @@ def table_delete(table, filename=None, lineno=None):
     '''
     Deletes a table.
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
+    table_info = " " + table.family + " " + table.name + " "
 
     if not table_exist(table, filename, lineno):
-        reason = "Table " + table[1] + " does not exist but I added it before."
+        reason = "Table " + table.name + " does not exist but I added it before."
         print_error(reason, filename, lineno)
         return -1
 
     cmd = NFT_BIN + " delete table" + table_info
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = cmd + ": " + "I cannot delete table '" + table[1] + "'. Giving up! "
+        reason = cmd + ": " + "I cannot delete table '" + table.name + "'. Giving up! "
         print_error(reason, filename, lineno)
         return -1
 
     if table_exist(table, filename, lineno):
-        reason = "I have just deleted the table " + table[1] + " but the table still exists."
+        reason = "I have just deleted the table " + table.name + " but the table still exists."
         print_error(reason, filename, lineno)
         return -1
 
@@ -157,32 +179,30 @@ def chain_exist(chain, table, filename, lineno):
     '''
     Checks a chain
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
-    cmd = NFT_BIN + " list -nnn chain" + table_info + chain
+    table_info = " " + table.family + " " + table.name + " "
+    cmd = NFT_BIN + " list -nnn chain" + table_info + chain.name
     ret = execute_cmd(cmd, filename, lineno)
 
     return True if (ret == 0) else False
 
 
-def chain_create(chain, chain_type, table, filename, lineno):
+def chain_create(chain, table, filename, lineno):
     '''
     Adds a chain
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
+    table_info = " " + table.family + " " + table.name + " "
 
     if chain_exist(chain, table, filename, lineno):
-        reason = "This chain '" + chain + "' exists in " + table[1] + ". I cannot create two chains with same name."
+        reason = "This chain '" + chain.name + "' exists in " + table.name + \
+                 ". I cannot create two chains with same name."
         print_error(reason, filename, lineno)
         return -1
 
-    if chain_type:
-        cmd = NFT_BIN + " add chain" + table_info + chain + "\{ " + chain_type + "\; \}"
-    else:
-        cmd = NFT_BIN + " add chain" + table_info + chain
+    cmd = NFT_BIN + " add chain" + table_info + chain.name + "\{ " + chain.config + "\; \}"
 
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = "I cannot create the chain '" + chain
+        reason = "I cannot create the chain '" + chain.name
         print_error(reason, filename, lineno)
         return -1
 
@@ -190,7 +210,7 @@ def chain_create(chain, chain_type, table, filename, lineno):
         chain_list.append(chain)
 
     if not chain_exist(chain, table, filename, lineno):
-        reason = "I have added the chain '" + chain + "' but it does not exist in " + table[1]
+        reason = "I have added the chain '" + chain.name + "' but it does not exist in " + table.name
         print_error(reason, filename, lineno)
         return -1
 
@@ -201,21 +221,21 @@ def chain_delete(chain, table, filename=None, lineno=None):
     '''
     Flushes and deletes a chain.
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
+    table_info = " " + table.family + " " + table.name + " "
 
     if not chain_exist(chain, table, filename, lineno):
-        reason = "The chain " + chain + " does not exists in " + table[1] + ". I cannot delete it."
+        reason = "The chain " + chain.name + " does not exists in " + table.name + ". I cannot delete it."
         print_error(reason, filename, lineno)
         return -1
 
-    cmd = NFT_BIN + " flush chain" + table_info + chain
+    cmd = NFT_BIN + " flush chain" + table_info + chain.name
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = "I cannot flush this chain " + chain
+        reason = "I cannot flush this chain " + chain.name
         print_error(reason, filename, lineno)
         return -1
 
-    cmd = NFT_BIN + " delete chain" + table_info + chain
+    cmd = NFT_BIN + " delete chain" + table_info + chain.name
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
         reason = cmd + "I cannot delete this chain. DD"
@@ -223,7 +243,7 @@ def chain_delete(chain, table, filename=None, lineno=None):
         return -1
 
     if chain_exist(chain, table, filename, lineno):
-        reason = "The chain " + chain + " exists in " + table[1] + ". I cannot delete this chain"
+        reason = "The chain " + chain.name + " exists in " + table.name + ". I cannot delete this chain"
         print_error(reason, filename, lineno)
         return -1
 
@@ -241,11 +261,11 @@ def set_add(set_info, filename, lineno):
 
     for table in table_list:
         if set_exist(set_info[0], table, filename, lineno):
-            reason = "This set " + set_info + " exists in " + table[1] + ". I cannot add it again"
+            reason = "This set " + set_info + " exists in " + table.name + ". I cannot add it again"
             print_error(reason, filename, lineno)
             return -1
 
-        table_info = " " + table[0] + " " + table[1] + " "
+        table_info = " " + table.family + " " + table.name + " "
         set_text = " " + set_info[0] + " { type " + set_info[1] + " \;}"
         cmd = NFT_BIN + " add set" + table_info + set_text
         ret = execute_cmd(cmd, filename, lineno)
@@ -256,7 +276,8 @@ def set_add(set_info, filename, lineno):
             return -1
 
         if not set_exist(set_info[0], table, filename, lineno):
-            reason = "I have just added the set " + set_info[0] + " to the table " + table[1] + " but it does not exist"
+            reason = "I have just added the set " + set_info[0] + " to the table " + table.name + \
+                     " but it does not exist"
             print_error(reason, filename, lineno)
             return -1
 
@@ -279,7 +300,7 @@ def set_add_elements(set_element, set_name, state, filename, lineno):
             print_error(reason, filename, lineno)
             return -1
 
-        table_info = " " + table[0] + " " + table[1] + " "
+        table_info = " " + table.family + " " + table.name + " "
 
         element = ""
         for e in set_element:
@@ -310,7 +331,7 @@ def set_delete_elements(set_element, set_name, table, filename=None, lineno=None
     '''
     Deletes elements in a set.
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
+    table_info = " " + table.family + " " + table.name + " "
 
     for element in set_element:
         set_text = set_name + " {" + element + "}"
@@ -339,7 +360,7 @@ def set_delete(table, filename=None, lineno=None):
         set_delete_elements(all_set[set_name], set_name, table, filename, lineno)
 
         # We delete the set.
-        table_info = " " + table[0] + " " + table[1] + " "
+        table_info = " " + table.family + " " + table.name + " "
         cmd = NFT_BIN + " delete set " + table_info + " " + set_name
         ret = execute_cmd(cmd, filename, lineno)
 
@@ -356,7 +377,7 @@ def set_exist(set_name, table, filename, lineno):
     '''
     Check if the set exists.
     '''
-    table_info = " " + table[0] + " " + table[1] + " "
+    table_info = " " + table.family + " " + table.name + " "
     cmd = NFT_BIN + " list -nnn set" + table_info + set_name
     ret = execute_cmd(cmd, filename, lineno)
 
@@ -384,7 +405,7 @@ def set_check_element(rule1, rule2):
 
 
 def output_clean(pre_output, chain):
-    pos_chain = pre_output[0].find(chain)
+    pos_chain = pre_output[0].find(chain.name)
     if pos_chain == -1:
         return ""
     output_intermediate = pre_output[0][pos_chain:]
@@ -470,7 +491,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
 
     for table in table_list:
         try:
-            payload_log = open("%s.payload.%s" % (filename_path, table[0]))
+            payload_log = open("%s.payload.%s" % (filename_path, table.family))
         except IOError:
             payload_log = open("%s.payload" % filename_path)
 
@@ -486,11 +507,11 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
         for chain in chain_list:
             unit_tests += 1
             table_flush(table, filename, lineno)
-            table_info = " " + table[0] + " " + table[1] + " "
+            table_info = " " + table.family + " " + table.name + " "
 
             payload_log = os.tmpfile()
 
-            cmd = NFT_BIN + " add rule --debug=netlink" + table_info + chain + " " + rule[0]
+            cmd = NFT_BIN + " add rule --debug=netlink" + table_info + chain.name + " " + rule[0]
             ret = execute_cmd(cmd, filename, lineno, payload_log)
 
             state = rule[1].rstrip()
@@ -526,7 +547,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
                     print_warning("Wrote payload for rule %s" % rule[0], gotf.name, 1)
 
                 # Check output of nft
-                process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table'] + table, shell=False,
+                process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table', table.family, table.name], shell=False,
                                            stdout=subprocess.PIPE, preexec_fn=preexec)
                 pre_output = process.communicate()
                 output = pre_output[0].split(";")
@@ -624,24 +645,18 @@ def print_result_all(filename, tests, warning, error, unit_tests):
 
 
 def table_process(table_line, filename, lineno):
-    table_info = []
-    if ";" in table_line:
-        table_info = table_line.split(";")
-    else:
-        table_info.append("ip")
-        table_info.append(table_line)
+    table_info = table_line.split(";")
+    table = Table(table_info[0], table_info[1])
 
-    return table_create(table_info, filename, lineno)
+    return table_create(table, filename, lineno)
 
 
 def chain_process(chain_line, filename, lineno):
-    chain_name = chain_line[0]
-    chain_type = ""
+    chain_info = chain_line.split(";")
+    chain = Chain(chain_info[0], chain_info[1])
+
     for table in table_list:
-        if len(chain_line) > 1:
-            chain_type = chain_line[1]
-        ret = chain_create(chain_name, chain_type, table, filename, lineno)
-        if ret != 0:
+        if chain_create(chain, table, filename, lineno) != 0:
             return -1
     return 0
 
@@ -730,7 +745,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
             continue
 
         if line[0] == ":":  # Chain
-            chain_line = line.rstrip()[1:].split(";")
+            chain_line = line.rstrip()[1:]
             ret = chain_process(chain_line, filename, lineno)
             if ret != 0:
                 break
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nft 5/6] tests/py: modify supported test file syntax
  2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
                   ` (2 preceding siblings ...)
  2016-01-04 10:43 ` [PATCH nft 4/6] tests/py: convert chains and tables to objects Pablo M. Bermudo Garay
@ 2016-01-04 10:43 ` Pablo M. Bermudo Garay
  2016-01-04 10:43 ` [PATCH nft 6/6] tests/py: update test files syntax Pablo M. Bermudo Garay
  4 siblings, 0 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

Until now, the syntax to represent tables and chains in test files was:

*ip;test-ip4
*ip6;test-ip6
*inet;test-inet
:input;type filter hook input priority 0

Where lines starting with * are tables and lines starting with : are
chains.

This commit change the test script to deal with new syntax:

:input;type filter hook input priority 0
*ip;test-ip4;input
*ip6;test-ip6;input
*inet;test-inet;input

Now the chains should be included before tables. Also, lines defining
tables have a new third part (delimited by semicolon) where the chains
needed by the table are declared. If table needs to include more than
one chain, those must be separated by commas:

:input;type filter hook input priority 0
:forward;type filter hook forward priority 0
:output;type filter hook output priority 0
*arp;test-arp;input,forward,output

This new syntax allow to include in the same test file chains not
supported by all families of tables tested.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/nft-test.py | 50 +++++++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index e379a0f..4cde192 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -48,9 +48,10 @@ class Colors:
 class Chain:
     """Class that represents a chain"""
 
-    def __init__(self, name, config):
+    def __init__(self, name, config, lineno):
         self.name = name
         self.config = config
+        self.lineno = lineno
 
     def __eq__(self, other):
         return self.__dict__ == other.__dict__
@@ -59,9 +60,10 @@ class Chain:
 class Table:
     """Class that represents a table"""
 
-    def __init__(self, family, name):
+    def __init__(self, family, name, chains):
         self.family = family
         self.name = name
+        self.chains = chains
 
     def __eq__(self, other):
         return self.__dict__ == other.__dict__
@@ -146,6 +148,14 @@ def table_create(table, filename, lineno):
         print_error(reason, filename, lineno)
         return -1
 
+    for chain in table.chains:
+        c = next((c for c in chain_list if c.name == chain), None)
+        if c is None:
+            reason = "The chain " + chain + " requested by table " + table.name + " does not exist."
+            print_error(reason, filename, lineno)
+        else:
+            chain_create(c, table, filename)
+
     return 0
 
 
@@ -175,43 +185,40 @@ def table_delete(table, filename=None, lineno=None):
     return 0
 
 
-def chain_exist(chain, table, filename, lineno):
+def chain_exist(chain, table, filename):
     '''
     Checks a chain
     '''
     table_info = " " + table.family + " " + table.name + " "
     cmd = NFT_BIN + " list -nnn chain" + table_info + chain.name
-    ret = execute_cmd(cmd, filename, lineno)
+    ret = execute_cmd(cmd, filename, chain.lineno)
 
     return True if (ret == 0) else False
 
 
-def chain_create(chain, table, filename, lineno):
+def chain_create(chain, table, filename):
     '''
     Adds a chain
     '''
     table_info = " " + table.family + " " + table.name + " "
 
-    if chain_exist(chain, table, filename, lineno):
+    if chain_exist(chain, table, filename):
         reason = "This chain '" + chain.name + "' exists in " + table.name + \
                  ". I cannot create two chains with same name."
-        print_error(reason, filename, lineno)
+        print_error(reason, filename, chain.lineno)
         return -1
 
     cmd = NFT_BIN + " add chain" + table_info + chain.name + "\{ " + chain.config + "\; \}"
 
-    ret = execute_cmd(cmd, filename, lineno)
+    ret = execute_cmd(cmd, filename, chain.lineno)
     if ret != 0:
         reason = "I cannot create the chain '" + chain.name
-        print_error(reason, filename, lineno)
+        print_error(reason, filename, chain.lineno)
         return -1
 
-    if chain not in chain_list:
-        chain_list.append(chain)
-
-    if not chain_exist(chain, table, filename, lineno):
+    if not chain_exist(chain, table, filename):
         reason = "I have added the chain '" + chain.name + "' but it does not exist in " + table.name
-        print_error(reason, filename, lineno)
+        print_error(reason, filename, chain.lineno)
         return -1
 
     return 0
@@ -223,7 +230,7 @@ def chain_delete(chain, table, filename=None, lineno=None):
     '''
     table_info = " " + table.family + " " + table.name + " "
 
-    if not chain_exist(chain, table, filename, lineno):
+    if not chain_exist(chain, table, filename):
         reason = "The chain " + chain.name + " does not exists in " + table.name + ". I cannot delete it."
         print_error(reason, filename, lineno)
         return -1
@@ -242,7 +249,7 @@ def chain_delete(chain, table, filename=None, lineno=None):
         print_error(reason, filename, lineno)
         return -1
 
-    if chain_exist(chain, table, filename, lineno):
+    if chain_exist(chain, table, filename):
         reason = "The chain " + chain.name + " exists in " + table.name + ". I cannot delete this chain"
         print_error(reason, filename, lineno)
         return -1
@@ -646,18 +653,15 @@ def print_result_all(filename, tests, warning, error, unit_tests):
 
 def table_process(table_line, filename, lineno):
     table_info = table_line.split(";")
-    table = Table(table_info[0], table_info[1])
+    table = Table(table_info[0], table_info[1], table_info[2].split(","))
 
     return table_create(table, filename, lineno)
 
 
-def chain_process(chain_line, filename, lineno):
+def chain_process(chain_line, lineno):
     chain_info = chain_line.split(";")
-    chain = Chain(chain_info[0], chain_info[1])
+    chain_list.append(Chain(chain_info[0], chain_info[1], lineno))
 
-    for table in table_list:
-        if chain_create(chain, table, filename, lineno) != 0:
-            return -1
     return 0
 
 
@@ -746,7 +750,7 @@ def run_test_file(filename, force_all_family_option, specific_file):
 
         if line[0] == ":":  # Chain
             chain_line = line.rstrip()[1:]
-            ret = chain_process(chain_line, filename, lineno)
+            ret = chain_process(chain_line, lineno)
             if ret != 0:
                 break
             continue
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nft 6/6] tests/py: update test files syntax
  2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
                   ` (3 preceding siblings ...)
  2016-01-04 10:43 ` [PATCH nft 5/6] tests/py: modify supported test file syntax Pablo M. Bermudo Garay
@ 2016-01-04 10:43 ` Pablo M. Bermudo Garay
  4 siblings, 0 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-04 10:43 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo M. Bermudo Garay

The test files have been adapted to the syntax defined in the previous
commit "tests/py: modify supported test file syntax"

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
---
 tests/py/any/ct.t         |  8 ++++----
 tests/py/any/frag.t       | 11 ++++++-----
 tests/py/any/limit.t      | 11 ++++++-----
 tests/py/any/log.t        | 11 ++++++-----
 tests/py/any/meta.t       | 12 ++++++------
 tests/py/any/queue.t      | 12 ++++++------
 tests/py/arp/arp.t        |  3 ++-
 tests/py/arp/chains.t     |  4 ++--
 tests/py/bridge/chains.t  |  4 ++--
 tests/py/bridge/ether.t   |  4 ++--
 tests/py/bridge/reject.t  |  3 ++-
 tests/py/bridge/vlan.t    |  3 ++-
 tests/py/inet/ah.t        |  7 ++++---
 tests/py/inet/comp.t      |  8 ++++----
 tests/py/inet/dccp.t      |  7 ++++---
 tests/py/inet/esp.t       |  7 ++++---
 tests/py/inet/ether-ip.t  |  3 ++-
 tests/py/inet/ether.t     | 10 +++++-----
 tests/py/inet/ip.t        |  8 ++++----
 tests/py/inet/reject.t    |  3 ++-
 tests/py/inet/sctp.t      |  7 ++++---
 tests/py/inet/tcp.t       |  7 ++++---
 tests/py/inet/udp.t       |  7 ++++---
 tests/py/inet/udplite.t   |  7 ++++---
 tests/py/ip/chains.t      |  4 ++--
 tests/py/ip/dnat.t        |  3 ++-
 tests/py/ip/dup.t         |  3 ++-
 tests/py/ip/ether.t       |  4 ++--
 tests/py/ip/icmp.t        |  3 ++-
 tests/py/ip/ip.t          |  5 +++--
 tests/py/ip/masquerade.t  |  3 ++-
 tests/py/ip/redirect.t    |  3 ++-
 tests/py/ip/reject.t      |  3 ++-
 tests/py/ip/sets.t        |  5 +++--
 tests/py/ip/snat.t        |  3 ++-
 tests/py/ip6/chains.t     |  4 ++--
 tests/py/ip6/dnat.t       |  3 ++-
 tests/py/ip6/dst.t        |  5 +++--
 tests/py/ip6/dup.t        |  3 ++-
 tests/py/ip6/ether.t      |  4 ++--
 tests/py/ip6/hbh.t        |  5 +++--
 tests/py/ip6/icmpv6.t     |  7 ++++---
 tests/py/ip6/ip6.t        |  5 +++--
 tests/py/ip6/masquerade.t |  3 ++-
 tests/py/ip6/mh.t         |  5 +++--
 tests/py/ip6/redirect.t   |  3 ++-
 tests/py/ip6/reject.t     |  3 ++-
 tests/py/ip6/rt.t         |  5 +++--
 tests/py/ip6/sets.t       |  5 +++--
 tests/py/ip6/snat.t       |  3 ++-
 tests/py/ip6/vmap.t       |  5 +++--
 51 files changed, 156 insertions(+), 118 deletions(-)

diff --git a/tests/py/any/ct.t b/tests/py/any/ct.t
index 059402e..056d9bb 100644
--- a/tests/py/any/ct.t
+++ b/tests/py/any/ct.t
@@ -1,9 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+*ip6;test-ip6;output
+*inet;test-inet;output
+
 ct state new,established, related, untracked;ok;ct state established,related,new,untracked
 ct state != related;ok
 ct state {new,established, related, untracked};ok
diff --git a/tests/py/any/frag.t b/tests/py/any/frag.t
index d61a3d4..9138637 100644
--- a/tests/py/any/frag.t
+++ b/tests/py/any/frag.t
@@ -1,10 +1,11 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*arp;test-arp
-*bridge;test-bridge
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+*ip6;test-ip6;output
+*inet;test-inet;output
+*arp;test-arp;output
+*bridge;test-bridge;output
+
 frag nexthdr tcp;ok;frag nexthdr 6
 frag nexthdr != icmp;ok;frag nexthdr != 1
 frag nexthdr {esp, ah, comp, udp, udplite, tcp, dccp, sctp};ok;frag nexthdr { 51, 136, 132, 6, 108, 50, 17, 33}
diff --git a/tests/py/any/limit.t b/tests/py/any/limit.t
index 96ffe60..2dcab81 100644
--- a/tests/py/any/limit.t
+++ b/tests/py/any/limit.t
@@ -1,10 +1,11 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*arp;test-arp
-*bridge;test-bridge
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+*ip6;test-ip6;output
+*inet;test-inet;output
+*arp;test-arp;output
+*bridge;test-bridge;output
+
 limit rate 400/minute;ok
 limit rate 20/second;ok
 limit rate 400/hour;ok
diff --git a/tests/py/any/log.t b/tests/py/any/log.t
index 0eed580..99a7f1f 100644
--- a/tests/py/any/log.t
+++ b/tests/py/any/log.t
@@ -1,10 +1,11 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*arp;test-arp
-*bridge;test-bridge
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+*ip6;test-ip6;output
+*inet;test-inet;output
+*arp;test-arp;output
+*bridge;test-bridge;output
+
 log;ok
 log level emerg;ok
 log level alert;ok
diff --git a/tests/py/any/meta.t b/tests/py/any/meta.t
index c03e7f4..245f0ec 100644
--- a/tests/py/any/meta.t
+++ b/tests/py/any/meta.t
@@ -1,11 +1,11 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*arp;test-arp
-*bridge;test-bridge
-
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+*arp;test-arp;input
+*bridge;test-bridge;input
+
 meta length 1000;ok
 meta length 22;ok
 meta length != 233;ok
diff --git a/tests/py/any/queue.t b/tests/py/any/queue.t
index 600c112..a1aefa1 100644
--- a/tests/py/any/queue.t
+++ b/tests/py/any/queue.t
@@ -1,11 +1,11 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*arp;test-arp
-*bridge;test-bridge
-
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+*ip6;test-ip6;output
+*inet;test-inet;output
+*arp;test-arp;output
+*bridge;test-bridge;output
+
 queue;ok;queue num 0
 queue num 2;ok
 queue num 2-3;ok
diff --git a/tests/py/arp/arp.t b/tests/py/arp/arp.t
index c4e07d5..06b0fe3 100644
--- a/tests/py/arp/arp.t
+++ b/tests/py/arp/arp.t
@@ -1,7 +1,8 @@
-*arp;test-arp
 # filter chains available are: input, output, forward
 :input;type filter hook input priority 0
 
+*arp;test-arp;input
+
 arp htype 1;ok
 arp htype != 1;ok
 arp htype 22;ok
diff --git a/tests/py/arp/chains.t b/tests/py/arp/chains.t
index cf08c1a..59647f7 100644
--- a/tests/py/arp/chains.t
+++ b/tests/py/arp/chains.t
@@ -1,6 +1,6 @@
-*arp;test-arp
-
 # filter chains available are: input, output, forward
 :input;type filter hook input priority 0
 :forward;type filter hook forward priority 0
 :output;type filter hook output priority 0
+
+*arp;test-arp;input,forward,output
diff --git a/tests/py/bridge/chains.t b/tests/py/bridge/chains.t
index 8070de4..85dde73 100644
--- a/tests/py/bridge/chains.t
+++ b/tests/py/bridge/chains.t
@@ -1,8 +1,8 @@
-*bridge;test-bridge
-
 # filter chains available are: prerouting, input, output, forward, postrouting
 :filter-pre;type filter hook input priority 0
 :filter-output;type filter hook output priority 0
 :filter-forward;type filter hook forward priority 0
 :filter-input;type filter hook input priority 0
 :filter-post;type filter hook input priority 0
+
+*bridge;test-bridge;filter-pre,filter-output,filter-forward,filter-input,filter-post
diff --git a/tests/py/bridge/ether.t b/tests/py/bridge/ether.t
index 6257dfc..5b39fe0 100644
--- a/tests/py/bridge/ether.t
+++ b/tests/py/bridge/ether.t
@@ -1,7 +1,7 @@
-*bridge;test-bridge
-
 :input;type filter hook input priority 0
 
+*bridge;test-bridge;input
+
 tcp dport 22 iiftype ether ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4 accept
 tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4
 tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4;ok
diff --git a/tests/py/bridge/reject.t b/tests/py/bridge/reject.t
index 43e5461..4fa6ac0 100644
--- a/tests/py/bridge/reject.t
+++ b/tests/py/bridge/reject.t
@@ -1,6 +1,7 @@
-*bridge;test-bridge
 :input;type filter hook input priority 0
 
+*bridge;test-bridge;input
+
 # The output is specific for bridge family
 reject with icmp type host-unreachable;ok;ether type ip reject with icmp type host-unreachable
 reject with icmp type net-unreachable;ok;ether type ip reject with icmp type net-unreachable
diff --git a/tests/py/bridge/vlan.t b/tests/py/bridge/vlan.t
index f86561a..e7c75bb 100644
--- a/tests/py/bridge/vlan.t
+++ b/tests/py/bridge/vlan.t
@@ -1,6 +1,7 @@
-*bridge;test-bridge
 :input;type filter hook input priority 0
 
+*bridge;test-bridge;input
+
 vlan id 4094;ok
 vlan id 0;ok
 # bad vlan id
diff --git a/tests/py/inet/ah.t b/tests/py/inet/ah.t
index 666659d..f3848b7 100644
--- a/tests/py/inet/ah.t
+++ b/tests/py/inet/ah.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 # nexthdr Bug to list table.
 
 - ah nexthdr esp;ok
diff --git a/tests/py/inet/comp.t b/tests/py/inet/comp.t
index f4753bb..6396ff3 100644
--- a/tests/py/inet/comp.t
+++ b/tests/py/inet/comp.t
@@ -1,9 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 # BUG: nft: payload.c:88: payload_expr_pctx_update: Assertion `left->payload.base + 1 <= (__PROTO_BASE_MAX - 1)' failed.
 - comp nexthdr esp;ok;comp nexthdr 50
 comp nexthdr != esp;ok;comp nexthdr != 50
diff --git a/tests/py/inet/dccp.t b/tests/py/inet/dccp.t
index e323992..63de1c8 100644
--- a/tests/py/inet/dccp.t
+++ b/tests/py/inet/dccp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 dccp sport 21-35;ok
 dccp sport != 21-35;ok
 dccp sport {23, 24, 25};ok
diff --git a/tests/py/inet/esp.t b/tests/py/inet/esp.t
index 3a8502d..105acb2 100644
--- a/tests/py/inet/esp.t
+++ b/tests/py/inet/esp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 esp spi 100;ok
 esp spi != 100;ok
 esp spi 111-222;ok
diff --git a/tests/py/inet/ether-ip.t b/tests/py/inet/ether-ip.t
index 3726db4..a451588 100644
--- a/tests/py/inet/ether-ip.t
+++ b/tests/py/inet/ether-ip.t
@@ -1,5 +1,6 @@
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*inet;test-inet;input
+
 tcp dport 22 iiftype ether ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4 accept
 tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04;ok
diff --git a/tests/py/inet/ether.t b/tests/py/inet/ether.t
index 9d0f972..1659a30 100644
--- a/tests/py/inet/ether.t
+++ b/tests/py/inet/ether.t
@@ -1,10 +1,10 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
-*bridge;test-bridge
-
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+*bridge;test-bridge;input
+
 tcp dport 22 iiftype ether ether saddr 00:0f:54:0c:11:4 meta nfproto ipv4 accept;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 meta nfproto ipv4 accept
 tcp dport 22 iiftype ether ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 accept
 tcp dport 22 ether saddr 00:0f:54:0c:11:04 accept;ok
diff --git a/tests/py/inet/ip.t b/tests/py/inet/ip.t
index a56c5c9..ffcb47e 100644
--- a/tests/py/inet/ip.t
+++ b/tests/py/inet/ip.t
@@ -1,7 +1,7 @@
-*ip;test-ip4
-*inet;test-inet
-*bridge;test-bridge
-
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*inet;test-inet;input
+*bridge;test-bridge;input
+
 ip saddr . ip daddr . ether saddr { 1.1.1.1 . 2.2.2.2 . ca:fe:ca:fe:ca:fe };ok
diff --git a/tests/py/inet/reject.t b/tests/py/inet/reject.t
index 52e7b28..638f329 100644
--- a/tests/py/inet/reject.t
+++ b/tests/py/inet/reject.t
@@ -1,6 +1,7 @@
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*inet;test-inet;input
+
 # The output is specific for inet family
 reject with icmp type host-unreachable;ok;meta nfproto ipv4 reject with icmp type host-unreachable
 reject with icmp type net-unreachable;ok;meta nfproto ipv4 reject with icmp type net-unreachable
diff --git a/tests/py/inet/sctp.t b/tests/py/inet/sctp.t
index 537a9b1..75c58b8 100644
--- a/tests/py/inet/sctp.t
+++ b/tests/py/inet/sctp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 sctp sport 23;ok
 sctp sport != 23;ok
 sctp sport 23-44;ok
diff --git a/tests/py/inet/tcp.t b/tests/py/inet/tcp.t
index 53a1689..cc19ed4 100644
--- a/tests/py/inet/tcp.t
+++ b/tests/py/inet/tcp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 tcp dport 22;ok
 tcp dport != 233;ok
 tcp dport 33-45;ok
diff --git a/tests/py/inet/udp.t b/tests/py/inet/udp.t
index 58f4002..30c06e4 100644
--- a/tests/py/inet/udp.t
+++ b/tests/py/inet/udp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip;test-ip6
-*ip;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip;test-ip6;input
+*ip;test-inet;input
+
 udp sport 80 accept;ok
 udp sport != 60 accept;ok
 udp sport 50-70 accept;ok
diff --git a/tests/py/inet/udplite.t b/tests/py/inet/udplite.t
index 9420ab4..ba01f67 100644
--- a/tests/py/inet/udplite.t
+++ b/tests/py/inet/udplite.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 udplite sport 80 accept;ok
 udplite sport != 60 accept;ok
 udplite sport 50-70 accept;ok
diff --git a/tests/py/ip/chains.t b/tests/py/ip/chains.t
index 8edf62b..fc3745e 100644
--- a/tests/py/ip/chains.t
+++ b/tests/py/ip/chains.t
@@ -1,5 +1,3 @@
-*ip;test-ip4
-
 # filter chains available are: input, output, forward, prerouting, postrouting
 :filter-input;type filter hook input priority 0
 :filter-pre;type filter hook prerouting priority 0
@@ -13,3 +11,5 @@
 :nat-post-t;type nat hook postrouting priority 0
 # route chain available are: output
 :route-out-t;type route hook output priority 0
+
+*ip;test-ip4;filter-input,filter-pre,filter-forw,filter-out,filter-post,nat-input-t,nat-pre-t,nat-out-t,nat-post-t,route-out-t
diff --git a/tests/py/ip/dnat.t b/tests/py/ip/dnat.t
index cdb7811..28e658d 100644
--- a/tests/py/ip/dnat.t
+++ b/tests/py/ip/dnat.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :prerouting;type nat hook prerouting priority 0
 
+*ip;test-ip4;prerouting
+
 iifname "eth0" tcp dport 80-90 dnat 192.168.3.2;ok
 iifname "eth0" tcp dport != 80-90 dnat 192.168.3.2;ok
 iifname "eth0" tcp dport {80, 90, 23} dnat 192.168.3.2;ok
diff --git a/tests/py/ip/dup.t b/tests/py/ip/dup.t
index 9320d54..ac4e83a 100644
--- a/tests/py/ip/dup.t
+++ b/tests/py/ip/dup.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+
 dup to 192.168.2.1;ok
 dup to 192.168.2.1 device eth0;ok
 dup to ip saddr map { 192.168.2.120 : 192.168.2.1 } device eth0;ok
diff --git a/tests/py/ip/ether.t b/tests/py/ip/ether.t
index 4d30f51..e1d302c 100644
--- a/tests/py/ip/ether.t
+++ b/tests/py/ip/ether.t
@@ -1,7 +1,7 @@
-*ip;test-ip
-
 :input;type filter hook input priority 0
 
+*ip;test-ip;input
+
 tcp dport 22 iiftype ether ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04 accept
 tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04;ok
 tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4;ok
diff --git a/tests/py/ip/icmp.t b/tests/py/ip/icmp.t
index bd00f5c..02027b0 100644
--- a/tests/py/ip/icmp.t
+++ b/tests/py/ip/icmp.t
@@ -1,8 +1,9 @@
-*ip;test-ip4
 # BUG: There is a bug with icmp protocol and inet family.
 # *inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+
 icmp type echo-reply accept;ok
 icmp type destination-unreachable accept;ok
 icmp type source-quench accept;ok
diff --git a/tests/py/ip/ip.t b/tests/py/ip/ip.t
index 0339c2a..152323b 100644
--- a/tests/py/ip/ip.t
+++ b/tests/py/ip/ip.t
@@ -1,7 +1,8 @@
-*ip;test-ip4
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*inet;test-inet;input
+
 - ip version 2;ok
 
 # bug ip hdrlength
diff --git a/tests/py/ip/masquerade.t b/tests/py/ip/masquerade.t
index 35001f3..0bb49a6 100644
--- a/tests/py/ip/masquerade.t
+++ b/tests/py/ip/masquerade.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :postrouting;type nat hook postrouting priority 0
 
+*ip;test-ip4;postrouting
+
 # nf_nat flags combination
 udp dport 53 masquerade;ok
 udp dport 53 masquerade random;ok
diff --git a/tests/py/ip/redirect.t b/tests/py/ip/redirect.t
index b7eecb7..8161ae6 100644
--- a/tests/py/ip/redirect.t
+++ b/tests/py/ip/redirect.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :output;type nat hook output priority 0
 
+*ip;test-ip4;output
+
 # without arguments
 udp dport 53 redirect;ok
 
diff --git a/tests/py/ip/reject.t b/tests/py/ip/reject.t
index 70a63a0..6006f05 100644
--- a/tests/py/ip/reject.t
+++ b/tests/py/ip/reject.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :output;type filter hook output priority 0
 
+*ip;test-ip4;output
+
 reject;ok
 reject with icmp type host-unreachable;ok
 reject with icmp type net-unreachable;ok
diff --git a/tests/py/ip/sets.t b/tests/py/ip/sets.t
index c199dbd..d4a72ad 100644
--- a/tests/py/ip/sets.t
+++ b/tests/py/ip/sets.t
@@ -1,7 +1,8 @@
-*ip;test-ip4
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip;test-ip4;input
+*inet;test-inet;input
+
 !set_ipv4_add ipv4_addr;ok
 !set_inet inet_proto;ok
 !set_inet_serv inet_service;ok
diff --git a/tests/py/ip/snat.t b/tests/py/ip/snat.t
index 1caf7c7..a8469a3 100644
--- a/tests/py/ip/snat.t
+++ b/tests/py/ip/snat.t
@@ -1,6 +1,7 @@
-*ip;test-ip4
 :postrouting;type nat hook postrouting priority 0
 
+*ip;test-ip4;postrouting
+
 iifname "eth0" tcp dport 80-90 snat 192.168.3.2;ok
 iifname "eth0" tcp dport != 80-90 snat 192.168.3.2;ok
 iifname "eth0" tcp dport {80, 90, 23} snat 192.168.3.2;ok
diff --git a/tests/py/ip6/chains.t b/tests/py/ip6/chains.t
index c1e41e4..e78f9e0 100644
--- a/tests/py/ip6/chains.t
+++ b/tests/py/ip6/chains.t
@@ -1,5 +1,3 @@
-*ip6;test-ip6
-
 # filter chains available are: input, output, forward, forward, prerouting and postrouting.
 :filter-input;type filter hook input priority 0
 :filter-prer;type filter hook prerouting priority 0
@@ -15,3 +13,5 @@
 
 # route chain available is output.
 :route-out;type route hook output priority 0
+
+*ip6;test-ip6;filter-input,filter-prer,filter-forw-t,filter-out-t,filter-post-t,nat-input,nat-prerouting,nat-output,nat-postrou,route-out
diff --git a/tests/py/ip6/dnat.t b/tests/py/ip6/dnat.t
index 8341225..b061f2f 100644
--- a/tests/py/ip6/dnat.t
+++ b/tests/py/ip6/dnat.t
@@ -1,5 +1,6 @@
-*ip6;test-ip6
 :prerouting;type nat hook prerouting priority 0
 
+*ip6;test-ip6;prerouting
+
 tcp dport 80-90 dnat 2001:838:35f:1::-2001:838:35f:2:::80-100;ok
 tcp dport 80-90 dnat 2001:838:35f:1::-2001:838:35f:2:: :100;ok;tcp dport 80-90 dnat 2001:838:35f:1::-2001:838:35f:2:::100
diff --git a/tests/py/ip6/dst.t b/tests/py/ip6/dst.t
index 3207af7..f7b0979 100644
--- a/tests/py/ip6/dst.t
+++ b/tests/py/ip6/dst.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 dst nexthdr 22;ok
 dst nexthdr != 233;ok
 dst nexthdr 33-45;ok
diff --git a/tests/py/ip6/dup.t b/tests/py/ip6/dup.t
index 34f302f..e6bb78b 100644
--- a/tests/py/ip6/dup.t
+++ b/tests/py/ip6/dup.t
@@ -1,6 +1,7 @@
-*ip6;test-ip6
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+
 dup to abcd::1;ok
 dup to abcd::1 device eth0;ok
 dup to ip6 saddr map { abcd::1 : cafe::cafe } device eth0;ok
diff --git a/tests/py/ip6/ether.t b/tests/py/ip6/ether.t
index 98be273..d94a0d2 100644
--- a/tests/py/ip6/ether.t
+++ b/tests/py/ip6/ether.t
@@ -1,7 +1,7 @@
-*ip6;test-ip6
-
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+
 tcp dport 22 iiftype ether ip6 daddr 1::2 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ip6 daddr 1::2 ether saddr 00:0f:54:0c:11:04 accept
 tcp dport 22 ip6 daddr 1::2 ether saddr 00:0f:54:0c:11:04;ok;tcp dport 22 ip6 daddr 1::2 ether saddr 00:0f:54:0c:11:04
 tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip6 daddr 1::2;ok
diff --git a/tests/py/ip6/hbh.t b/tests/py/ip6/hbh.t
index 4e67c42..235cce4 100644
--- a/tests/py/ip6/hbh.t
+++ b/tests/py/ip6/hbh.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :filter-input;type filter hook input priority 0
 
+*ip6;test-ip6;filter-input
+*inet;test-inet;filter-input
+
 hbh hdrlength 22;ok
 hbh hdrlength != 233;ok
 hbh hdrlength 33-45;ok
diff --git a/tests/py/ip6/icmpv6.t b/tests/py/ip6/icmpv6.t
index fca903f..af40bf7 100644
--- a/tests/py/ip6/icmpv6.t
+++ b/tests/py/ip6/icmpv6.t
@@ -1,8 +1,9 @@
-*ip6;test-ip6
-# BUG: There is a bug with icmpv6 and inet tables
-# *inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+# BUG: There is a bug with icmpv6 and inet tables
+# *inet;test-inet;input
+
 icmpv6 type destination-unreachable accept;ok
 icmpv6 type packet-too-big accept;ok
 icmpv6 type time-exceeded accept;ok
diff --git a/tests/py/ip6/ip6.t b/tests/py/ip6/ip6.t
index d4c5c7e..ceb2a82 100644
--- a/tests/py/ip6/ip6.t
+++ b/tests/py/ip6/ip6.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 # BUG: Problem with version, priority
 # <cmdline>:1:1-38: Error: Could not process rule: Invalid argument
 # add rule ip6 test6 input ip6 version 1
diff --git a/tests/py/ip6/masquerade.t b/tests/py/ip6/masquerade.t
index 4e6c086..8040280 100644
--- a/tests/py/ip6/masquerade.t
+++ b/tests/py/ip6/masquerade.t
@@ -1,6 +1,7 @@
-*ip6;test-ip6
 :postrouting;type nat hook postrouting priority 0
 
+*ip6;test-ip6;postrouting
+
 # nf_nat flags combination
 udp dport 53 masquerade;ok
 udp dport 53 masquerade random;ok
diff --git a/tests/py/ip6/mh.t b/tests/py/ip6/mh.t
index cd652b3..099a6eb 100644
--- a/tests/py/ip6/mh.t
+++ b/tests/py/ip6/mh.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 mh nexthdr 1;ok
 mh nexthdr != 1;ok
 mh nexthdr { udplite, ipcomp, udp, ah, sctp, esp, dccp, tcp, ipv6-icmp };ok;mh nexthdr { 58, 17, 108, 6, 51, 136, 50, 132, 33}
diff --git a/tests/py/ip6/redirect.t b/tests/py/ip6/redirect.t
index 31ffe8c..d5a0a3b 100644
--- a/tests/py/ip6/redirect.t
+++ b/tests/py/ip6/redirect.t
@@ -1,6 +1,7 @@
-*ip6;test-ip6
 :output;type nat hook output priority 0
 
+*ip6;test-ip6;output
+
 # with no arguments
 redirect;ok
 udp dport 954 redirect;ok
diff --git a/tests/py/ip6/reject.t b/tests/py/ip6/reject.t
index 60dec90..2979956 100644
--- a/tests/py/ip6/reject.t
+++ b/tests/py/ip6/reject.t
@@ -1,6 +1,7 @@
-*ip6;test-ip6
 :output;type filter hook output priority 0
 
+*ip6;test-ip6;output
+
 reject;ok
 reject with icmpv6 type no-route;ok
 reject with icmpv6 type admin-prohibited;ok
diff --git a/tests/py/ip6/rt.t b/tests/py/ip6/rt.t
index eca47ca..7e700a5 100644
--- a/tests/py/ip6/rt.t
+++ b/tests/py/ip6/rt.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 rt nexthdr 1;ok
 rt nexthdr != 1;ok
 rt nexthdr {udplite, ipcomp, udp, ah, sctp, esp, dccp, tcp, ipv6-icmp};ok;rt nexthdr { 33, 136, 50, 132, 51, 17, 108, 6, 58}
diff --git a/tests/py/ip6/sets.t b/tests/py/ip6/sets.t
index 4938929..e0daa3a 100644
--- a/tests/py/ip6/sets.t
+++ b/tests/py/ip6/sets.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 !set_ipv6_add1 ipv6_addr;ok
 !set_inet1 inet_proto;ok
 !set_inet inet_service;ok
diff --git a/tests/py/ip6/snat.t b/tests/py/ip6/snat.t
index 37bf1a1..dec8dff 100644
--- a/tests/py/ip6/snat.t
+++ b/tests/py/ip6/snat.t
@@ -1,5 +1,6 @@
-*ip6;test-ip6
 :postrouting;type nat hook postrouting priority 0
 
+*ip6;test-ip6;postrouting
+
 tcp dport 80-90 snat 2001:838:35f:1::-2001:838:35f:2:: :80-100;ok;tcp dport 80-90 snat 2001:838:35f:1::-2001:838:35f:2:::80-100
 tcp dport 80-90 snat 2001:838:35f:1::-2001:838:35f:2:::100;ok
diff --git a/tests/py/ip6/vmap.t b/tests/py/ip6/vmap.t
index 301a28a..6a3a004 100644
--- a/tests/py/ip6/vmap.t
+++ b/tests/py/ip6/vmap.t
@@ -1,7 +1,8 @@
-*ip6;test-ip6
-*inet;test-inet
 :input;type filter hook input priority 0
 
+*ip6;test-ip6;input
+*inet;test-inet;input
+
 ip6 saddr vmap { abcd::3 : accept };ok
 ip6 saddr 1234:1234:1234:1234:1234:1234:1234:1234:1234;fail
 
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH nft 2/6] tests/py: fix style
  2016-01-04 10:43 ` [PATCH nft 2/6] tests/py: fix style Pablo M. Bermudo Garay
@ 2016-01-04 11:32   ` Pablo Neira Ayuso
  2016-01-06 18:55     ` Pablo M. Bermudo Garay
  0 siblings, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-01-04 11:32 UTC (permalink / raw)
  To: Pablo M. Bermudo Garay; +Cc: netfilter-devel

On Mon, Jan 04, 2016 at 11:43:52AM +0100, Pablo M. Bermudo Garay wrote:
> - Adjust lines to 120 columns style

Netfilter project coding style sticks to 80 columns. I'd rather keep
that.

BTW, I suggest next time you keep this style cleanup patches at the
end of the patchset that you submit.

Apart from that, the patchset looks good and I'd like to see this
integrated into master.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nft 2/6] tests/py: fix style
  2016-01-04 11:32   ` Pablo Neira Ayuso
@ 2016-01-06 18:55     ` Pablo M. Bermudo Garay
  0 siblings, 0 replies; 8+ messages in thread
From: Pablo M. Bermudo Garay @ 2016-01-06 18:55 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

2016-01-04 12:32 GMT+01:00 Pablo Neira Ayuso <pablo@netfilter.org>:
> On Mon, Jan 04, 2016 at 11:43:52AM +0100, Pablo M. Bermudo Garay wrote:
>> - Adjust lines to 120 columns style
>
> Netfilter project coding style sticks to 80 columns. I'd rather keep
> that.

I'm sorry. I knew about that rule of project coding style, but I
skipped it since the script is not part of main program and it has a
lot of lines exceeding 100 characters. I will submit a new version of
patchset fixing it.

> BTW, I suggest next time you keep this style cleanup patches at the
> end of the patchset that you submit.

Ok, thanks.

> Apart from that, the patchset looks good and I'd like to see this
> integrated into master.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-06 18:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-04 10:43 [PATCH nft 1/6] tests/py: remove unused variables Pablo M. Bermudo Garay
2016-01-04 10:43 ` [PATCH nft 2/6] tests/py: fix style Pablo M. Bermudo Garay
2016-01-04 11:32   ` Pablo Neira Ayuso
2016-01-06 18:55     ` Pablo M. Bermudo Garay
2016-01-04 10:43 ` [PATCH nft 3/6] tests/py: simplify use of globals Pablo M. Bermudo Garay
2016-01-04 10:43 ` [PATCH nft 4/6] tests/py: convert chains and tables to objects Pablo M. Bermudo Garay
2016-01-04 10:43 ` [PATCH nft 5/6] tests/py: modify supported test file syntax Pablo M. Bermudo Garay
2016-01-04 10:43 ` [PATCH nft 6/6] tests/py: update test files syntax Pablo M. Bermudo Garay

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.