tests/py: remove unused variables
PATCH v2 1/6 tests/py: remove unused variables
Only that. The script had a lot of unused variables.
---
Changes in v2:
Remove forgotten line
tests/py/nft-test.py | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-)
tests/py/nft-test.py +8 -30
@@ -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,6 @@ 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] payload_log = os.tmpfile();
@@ -583,7 +579,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 +601,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 +707,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 +735,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 +755,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 +762,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 +770,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 +779,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 +809,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 +820,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:
Signature · 1 line
2.7.0
PATCH v2 2/6 tests/py: fix style
- Adjust lines to 80 columns style
- Add two lines of separation between functions
- Remove redundant parentheses and semicolons
- Apply other minor style fixes
---
Changes in v2:
Adjust lines to 80 columns style
tests/py/nft-test.py | 209 +++++++++++++++++++++++++++------------------------ 1 file changed, 109 insertions(+), 100 deletions(-)
tests/py/nft-test.py +109 -100
@@ -44,19 +44,22 @@ 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:")
@@ -64,13 +67,13 @@ def print_warning(reason, filename=None, lineno=None): 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 + "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 +100,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 +108,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 +118,11 @@ 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!" + " but it does not exist. Giving up!" print_error(reason, filename, lineno) return -1
@@ -133,22 +136,21 @@ 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." + " but the table still exists." print_error(reason, filename, lineno) return -1
@@ -159,7 +161,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,17 +172,17 @@ 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 if chain_type: - cmd = NFT_BIN + " add chain" + table_info + chain + "\{ " + chain_type + "\; \}" + cmd = NFT_BIN + " add chain" + table_info + chain + "\{ " + \ + chain_type + "\; \}" else: cmd = NFT_BIN + " add chain" + table_info + chain
@@ -191,28 +192,27 @@ 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] + "' 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." + ". I cannot delete it." print_error(reason, filename, lineno) return -1
@@ -232,7 +232,7 @@ def chain_delete(chain, table, filename=None, lineno=None): if chain_exist(chain, table, filename, lineno): reason = "The chain " + chain + " exists in " + table[1] + \ - ". I cannot delete this chain" + ". I cannot delete this chain" print_error(reason, filename, lineno) return -1
@@ -243,7 +243,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)
@@ -252,7 +251,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" + ". I cannot add it again" print_error(reason, filename, lineno) return -1
@@ -262,14 +261,14 @@ def set_add(set_info, table_list, filename, lineno): 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 + (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" + " to the table " + table[1] + " but it does not exist" print_error(reason, filename, lineno) return -1
@@ -281,7 +280,6 @@ def set_add_elements(set_element, set_name, set_all, state, table_list, ''' Adds elements to the set. ''' - if not table_list: reason = "Missing table to add rules" print_error(reason, filename, lineno)
@@ -290,9 +288,9 @@ 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": + 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." + " since it does not exist." print_error(reason, filename, lineno) return -1
@@ -310,13 +308,13 @@ 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)
@@ -336,7 +334,7 @@ def set_delete_elements(set_element, set_name, table, filename=None, ret = execute_cmd(cmd, filename, lineno) if ret != 0: reason = "I cannot delete an element" + element + \ - " from the set '" + set_name + " from the set '" + set_name print_error(reason, filename, lineno) return -1
@@ -347,12 +345,11 @@ 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" + " does not exist, I cannot delete it" print_error(reason, filename, lineno) return -1
@@ -395,12 +392,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
@@ -418,11 +415,13 @@ def output_clean(pre_output, chain): set = set.split(";")[2].strip() + "}" return set else: - rule = pre_rule.split(";")[2].replace("\t", "").replace("\n", "").strip() + rule = pre_rule.split(";")[2].replace("\t", "").replace("\n", "").\ + strip() if len(rule) < 0: return "" return rule + def payload_check_elems_to_set(elems): newset = set()
@@ -436,8 +435,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 +448,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,11 +468,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): '''
@@ -492,26 +493,28 @@ 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 == []: - print_error("did not find payload information for rule '%s'" % rule[0], payload_log.name, 1) + 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] + " " - payload_log = os.tmpfile(); + 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 + \ + " " + rule[0] ret = execute_cmd(cmd, filename, lineno, payload_log) state = rule[1].rstrip()
@@ -527,13 +530,14 @@ 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 - if state == "ok" and not payload_check(payload_expected, payload_log, cmd): + # 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') payload_log.seek(0, 0)
@@ -544,11 +548,14 @@ def rule_add(rule, table_list, chain_list, filename, lineno, break gotf.write(line) 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, + 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) pre_output = process.communicate() output = pre_output[0].split(";")
@@ -561,14 +568,14 @@ 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,
@@ -578,15 +585,14 @@ def rule_add(rule, table_list, chain_list, filename, lineno, 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) + teoric_exit.rstrip(), + rule_output, cmd) if not force_all_family_option: return [ret, warning, error, unit_tests]
@@ -612,7 +618,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.
@@ -642,18 +648,18 @@ 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:
@@ -669,11 +675,11 @@ 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):
@@ -699,9 +705,11 @@ def set_element_process(element_line, 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): ''' - Find the netlink payload that should be generated by given rule in payload_log + Find the netlink payload that should be generated by given rule in + payload_log :param payload_log: open file handle of the payload data :param rule: nft rule we are going to add
@@ -729,6 +737,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
@@ -754,7 +763,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
@@ -786,7 +795,8 @@ def run_test_file(filename, force_all_family_option, specific_file): # Rule rule = line.split(';') # rule[1] Ok or FAIL - if len(rule) == 1 or len(rule) > 3 or rule[1].rstrip() not in {"ok", "fail"}: + if len(rule) == 1 or len(rule) > 3 or rule[1].rstrip() \ + not in {"ok", "fail"}: reason = "Skipping malformed rule test. (" + line.rstrip('\n') + ")" print_warning(reason, filename, lineno) continue
@@ -818,8 +828,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:
@@ -838,7 +847,7 @@ def run_test_file(filename, force_all_family_option, specific_file): 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()
@@ -850,20 +859,16 @@ 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', + 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', + 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') + dest='need_fix_line', help='run rules that need a fix') parser.add_argument('-f', '--force-family', action='store_true', dest='force_all_family',
@@ -936,11 +941,15 @@ 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()
Signature · 1 line
2.7.0
PATCH v2 3/6 tests/py: simplify use of globals
In reply to Pablo M. Bermudo GarayThe 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.
---
Changes in v2:
Resolve change conflicts
tests/py/nft-test.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
tests/py/nft-test.py +14 -18
@@ -168,7 +168,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 '''
@@ -239,7 +239,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. '''
@@ -275,8 +275,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. '''
@@ -288,7 +287,7 @@ 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 - set_name not in set_all) and state == "ok": + 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)
@@ -316,7 +315,7 @@ def set_add_elements(set_element, set_name, set_all, state, table_list, # 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
@@ -341,7 +340,7 @@ def set_delete_elements(set_element, set_name, table, filename=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. '''
@@ -475,8 +474,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 '''
@@ -609,7 +607,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)
@@ -675,8 +673,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
@@ -690,7 +687,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()
@@ -702,8 +699,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):
@@ -809,8 +805,8 @@ 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]
@@ -832,7 +828,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)
Signature · 1 line
2.7.0
PATCH v2 4/6 tests/py: convert chains and tables to objects
In reply to Pablo M. Bermudo GarayNow these concepts are represented by objects instead of lists or sparse parameters.
---
Changes in v2:
Resolve change conflicts
tests/py/nft-test.py | 130 ++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 58 deletions(-)
tests/py/nft-test.py +72 -58
@@ -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.
@@ -80,7 +102,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
@@ -90,7 +112,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
@@ -102,18 +124,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
@@ -121,7 +143,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] + \ + reason = "I have just added the table " + table.name + \ " but it does not exist. Giving up!" print_error(reason, filename, lineno) return -1
@@ -133,23 +155,24 @@ 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] + \ + 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] + \ + reason = "I have just deleted the table " + table.name + \ " but the table still exists." print_error(reason, filename, lineno) return -1
@@ -161,34 +184,31 @@ 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] + \ + 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
@@ -196,8 +216,8 @@ 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
@@ -208,22 +228,22 @@ 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"
@@ -231,7 +251,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] + \ + reason = "The chain " + chain.name + " exists in " + table.name + \ ". I cannot delete this chain" print_error(reason, filename, lineno) return -1
@@ -250,12 +270,12 @@ 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] + \ + 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)
@@ -268,7 +288,7 @@ def set_add(set_info, filename, lineno): 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" + " to the table " + table.name + " but it does not exist" print_error(reason, filename, lineno) return -1
@@ -293,7 +313,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:
@@ -325,7 +345,7 @@ def set_delete_elements(set_element, set_name, table, filename=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 + "}"
@@ -357,7 +377,7 @@ def set_delete(table, filename=None, lineno=None): 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)
@@ -374,7 +394,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)
@@ -402,7 +422,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:]
@@ -490,7 +510,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)
@@ -507,12 +527,12 @@ 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()
@@ -550,8 +570,8 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path): gotf.name, 1) # Check output of nft - process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table'] + - table, + process = subprocess.Popen([NFT_BIN, '-nnn', 'list', 'table', + table.family, table.name], shell=False, stdout=subprocess.PIPE, preexec_fn=preexec)
@@ -657,24 +677,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
@@ -764,7 +778,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
Signature · 1 line
2.7.0
PATCH v2 5/6 tests/py: modify supported test file syntax
In reply to Pablo M. Bermudo GarayUntil 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.
---
Changes in v2:
Resolve change conflicts
tests/py/nft-test.py | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-)
tests/py/nft-test.py +28 -23
@@ -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__
@@ -148,6 +150,15 @@ 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
@@ -180,45 +191,42 @@ 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
@@ -230,7 +238,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)
@@ -250,7 +258,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)
@@ -678,18 +686,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
@@ -779,7 +784,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
Signature · 1 line
2.7.0
PATCH v2 6/6 tests/py: update test files syntax
In reply to Pablo M. Bermudo GarayThe test files have been adapted to the syntax defined in the previous commit "tests/py: modify supported test file syntax"
---
Changes in v2:
Update new test file (ip/ct.t) syntax
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/ct.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 +++-- 52 files changed, 158 insertions(+), 120 deletions(-)
tests/py/any/ct.t +4 -4
@@ -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
tests/py/any/frag.t +6 -5
@@ -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}
tests/py/any/limit.t +6 -5
@@ -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
tests/py/any/log.t +6 -5
@@ -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
tests/py/any/meta.t +6 -6
@@ -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
tests/py/any/queue.t +6 -6
@@ -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
tests/py/arp/arp.t +2 -1
@@ -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
tests/py/arp/chains.t +2 -2
@@ -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
tests/py/bridge/chains.t +2 -2
@@ -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
tests/py/bridge/ether.t +2 -2
@@ -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
tests/py/bridge/reject.t +2 -1
@@ -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
tests/py/bridge/vlan.t +2 -1
@@ -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
tests/py/inet/ah.t +4 -3
@@ -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
tests/py/inet/comp.t +4 -4
@@ -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
tests/py/inet/dccp.t +4 -3
@@ -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
tests/py/inet/esp.t +4 -3
@@ -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
tests/py/inet/ether-ip.t +2 -1
@@ -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
tests/py/inet/ether.t +5 -5
@@ -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
tests/py/inet/ip.t +4 -4
@@ -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
tests/py/inet/reject.t +2 -1
@@ -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
tests/py/inet/sctp.t +4 -3
@@ -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
tests/py/inet/tcp.t +4 -3
@@ -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
tests/py/inet/udp.t +4 -3
@@ -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
tests/py/inet/udplite.t +4 -3
@@ -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
tests/py/ip/chains.t +2 -2
@@ -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
tests/py/ip/ct.t +2 -2
@@ -1,7 +1,7 @@ -*ip;test-ip4 - :output;type filter hook output priority 0 +*ip;test-ip4;output + ct saddr original 192.168.0.1;ok ct saddr reply 192.168.0.1;ok ct daddr original 192.168.0.1;ok
tests/py/ip/dnat.t +2 -1
@@ -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
tests/py/ip/dup.t +2 -1
@@ -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
tests/py/ip/ether.t +2 -2
@@ -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
tests/py/ip/icmp.t +2 -1
@@ -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
tests/py/ip/ip.t +3 -2
@@ -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
tests/py/ip/masquerade.t +2 -1
@@ -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
tests/py/ip/redirect.t +2 -1
@@ -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
tests/py/ip/reject.t +2 -1
@@ -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
tests/py/ip/sets.t +3 -2
@@ -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
tests/py/ip/snat.t +2 -1
@@ -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
tests/py/ip6/chains.t +2 -2
@@ -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
tests/py/ip6/dnat.t +2 -1
@@ -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
tests/py/ip6/dst.t +3 -2
@@ -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
tests/py/ip6/dup.t +2 -1
@@ -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
tests/py/ip6/ether.t +2 -2
@@ -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
tests/py/ip6/hbh.t +3 -2
@@ -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
tests/py/ip6/icmpv6.t +4 -3
@@ -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
tests/py/ip6/ip6.t +3 -2
@@ -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
tests/py/ip6/masquerade.t +2 -1
@@ -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
tests/py/ip6/mh.t +3 -2
@@ -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}
tests/py/ip6/redirect.t +2 -1
@@ -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
tests/py/ip6/reject.t +2 -1
@@ -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
tests/py/ip6/rt.t +3 -2
@@ -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}
tests/py/ip6/sets.t +3 -2
@@ -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
tests/py/ip6/snat.t +2 -1
@@ -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
tests/py/ip6/vmap.t +3 -2
@@ -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
Signature · 1 line
2.7.0