]> 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)
committerJule Anger <janger@samba.org>
Thu, 17 Apr 2025 11:31:14 +0000 (11:31 +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>
(cherry picked from commit 6b619b568f6661d3a5f0701cdfaf1e1e4943ff6f)

python/samba/tests/samba_tool/gpo.py
selftest/knownfail.d/samba-tool-gpo [new file with mode: 0644]

index 714f8e54d8d3af0387210e306c3214bf7b82b726..6df9c9fb5b61cd23e1d89433ff9022581e89588f 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
+