Add ItemizeChangesFromRsyncOutput to autotest_quickmerge
This CL adds a ItemizeChangesFromRsyncOutput function to
autotest_quickmerge, along with an associated unit test. The function
takes the output from an rsync command and parses out the paths of files
or directories that were added or modified in the destination directory.
This function is not yet used, but will be used in a future CL when
autotest_quickmerge gets the ability to modify the portage ownership of
files it has touched.
BUG=chromium:229234
TEST=New unit test; Manually verified that files with names of the form
"a -> b" are ignored by quickmerge.
Change-Id: I6231a1fa8d7eff0067c0936c4c57f03052cc6996
Reviewed-on: https://gerrit.chromium.org/gerrit/47603
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
diff --git a/scripts/autotest_quickmerge_unittest.py b/scripts/autotest_quickmerge_unittest.py
index 7f5b952..7736af0 100755
--- a/scripts/autotest_quickmerge_unittest.py
+++ b/scripts/autotest_quickmerge_unittest.py
@@ -6,10 +6,66 @@
"""Unit tests for autotest_quickmerge."""
+import unittest
+
+
from chromite.lib import cros_build_lib_unittest
from chromite.lib import cros_test_lib
from chromite.scripts import autotest_quickmerge
+
+RSYNC_TEST_OUTPUT = """.d..t...... ./
+>f..t...... touched file with spaces
+>f..t...... touched_file
+>f.st...... modified_contents_file
+.f...p..... modified_permissions_file
+.f....o.... modified_owner_file
+>f+++++++++ new_file
+cL+++++++++ new_symlink -> directory_a/new_file_in_directory
+.d..t...... directory_a/
+>f+++++++++ directory_a/new_file_in_directory
+>f..t...... directory_a/touched_file_in_directory
+cd+++++++++ new_empty_directory/
+.d..t...... touched_empty_directory/"""
+# The output format of rsync's itemized changes has a few unusual cases
+# that are ambiguous. For instance, if the operation involved creating a
+# symbolic link named "a -> b" to a file named "c", the rsync output would be:
+# cL+++++++++ a -> b -> c
+# which is indistinguishable from the output for creating a symbolic link named
+# "a" to a file named "b -> c".
+# Since there is no easy resolution to this ambiguity, and it seems like a case
+# that would rarely or never be encountered in the wild, rsync quickmerge
+# will exclude all files which contain the substring " -> " in their name.
+
+class ItemizeChangesFromRsyncOutput(unittest.TestCase):
+
+ def testItemizeChangesFromRsyncOutput(self):
+ """Test that rsync output parser returns correct FileMutations."""
+ destination_path = '/foo/bar'
+
+ expected_new = set(
+ [('>f+++++++++', '/foo/bar/new_file'),
+ ('>f+++++++++', '/foo/bar/directory_a/new_file_in_directory'),
+ ('cL+++++++++', '/foo/bar/new_symlink')])
+
+ expected_mod = set(
+ [('>f..t......', '/foo/bar/touched file with spaces'),
+ ('>f..t......', '/foo/bar/touched_file'),
+ ('>f.st......', '/foo/bar/modified_contents_file'),
+ ('.f...p.....', '/foo/bar/modified_permissions_file'),
+ ('.f....o....', '/foo/bar/modified_owner_file'),
+ ('>f..t......', '/foo/bar/directory_a/touched_file_in_directory')])
+
+ expected_dir = set([('cd+++++++++', '/foo/bar/new_empty_directory/')])
+
+ report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
+ RSYNC_TEST_OUTPUT, destination_path)
+
+ self.assertEqual(expected_new, set(report.new_files))
+ self.assertEqual(expected_mod, set(report.modified_files))
+ self.assertEqual(expected_dir, set(report.new_directories))
+
+
class RsyncCommandTest(cros_build_lib_unittest.RunCommandTestCase):
def testRsyncQuickmergeCommand(self):
@@ -20,6 +76,7 @@
expected_command = ['rsync', '-a', '-n', '-u', '-i',
'--exclude=**.pyc', '--exclude=**.pyo',
+ '--exclude=** -> *',
'--include-from=%s' % include_file_name,
'--exclude=*',
source_path,
@@ -35,4 +92,4 @@
if __name__ == '__main__':
- cros_test_lib.main()
\ No newline at end of file
+ cros_test_lib.main()