]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest: samba-tool gpo: fix has_difference(sortlines=True)
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 14 Mar 2025 06:52:57 +0000 (19:52 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 25 Mar 2025 04:20:45 +0000 (04:20 +0000)
We had

             file1 = open(path1).readlines()
             file1.sort()
             file2 = open(path1).readlines()
             file2.sort()

which is opening path1 in both cases.

This meant we were testing nothing because the assertions are all that
the files are the same -- though the only affected check is one in
test_backup_restore_generalize().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15829

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
python/samba/tests/samba_tool/gpo.py
selftest/knownfail.d/samba-tool-gpo [new file with mode: 0644]

index 697062261de7394b08f74bbdb0e14a55a6e8eee7..3f1111f8002f1256003972a1ad7f10580f153228 100644 (file)
@@ -141,21 +141,27 @@ source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../
 provision_path = os.path.join(source_path, "source4/selftest/provisions/")
 
 def has_difference(path1, path2, binary=True, xml=True, sortlines=False):
-    """Use this function to determine if the GPO backup differs from another.
+    """Use this function to determine if the GPO backup differs from
+    another. It can compare pairs of files or pairs of directories.
 
     xml=True checks whether any xml files are equal
     binary=True checks whether any .SAMBABACKUP files are equal
+    sortlines=True ignore order of lines in comparison of single
+    files.
+
+    returns None if there is no difference between the paths,
+    otherwise *something*.
     """
     if os.path.isfile(path1):
+        with open(path1) as f1, open(path2) as f2:
+            lines1 = f1.readlines()
+            lines2 = f2.readlines()
+
         if sortlines:
-            file1 = open(path1).readlines()
-            file1.sort()
-            file2 = open(path1).readlines()
-            file2.sort()
-            if file1 != file2:
-                return path1
-
-        elif open(path1).read() != open(path2).read():
+            lines1.sort()
+            lines2.sort()
+
+        if lines1 != lines2:
             return path1
 
         return None
diff --git a/selftest/knownfail.d/samba-tool-gpo b/selftest/knownfail.d/samba-tool-gpo
new file mode 100644 (file)
index 0000000..097495b
--- /dev/null
@@ -0,0 +1,2 @@
+^samba.tests.samba_tool.gpo.+GpoCmdTestCase.test_backup_restore_generalize
+