[nft PATCH 2/2] tests/py: Make nft-test.py a little more robust

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When adding a new test, missing payload file causes nft-test.py to choke
due to accessing undeclared variables. Fix this by making sure relevant
variables are declared outside of try-catch blocks.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 tests/py/nft-test.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 9513069c24548..334a015fe9aac 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -653,6 +653,9 @@ def payload_check(payload_buffer, file, cmd):
     file.seek(0, 0)
     i = 0
 
+    if not payload_buffer:
+        return False
+
     for lineno, want_line in enumerate(payload_buffer):
         line = file.readline()
 
@@ -698,11 +701,12 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
         return [-1, warning, error, unit_tests]
 
     if rule[1].strip() == "ok":
+        payload_expected = None
         try:
             payload_log = open("%s.payload" % filename_path)
             payload_expected = payload_find_expected(payload_log, rule[0])
         except:
-            payload_expected = None
+            payload_log = None
 
         if enable_json_option:
             try:
@@ -744,7 +748,10 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
                 payload_log = open("%s.payload.%s" % (filename_path, table.family))
                 table_payload_expected = payload_find_expected(payload_log, rule[0])
             except:
-                if not payload_expected:
+                if not payload_log:
+                    print_error("did not find any payload information",
+                                filename_path)
+                elif not payload_expected:
                     print_error("did not find payload information for "
                                 "rule '%s'" % rule[0], payload_log.name, 1)
             if not table_payload_expected:
-- 
2.18.0




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux