Ver código fonte

deduplicate fuse (u)mount code

Thomas Waldmann 9 anos atrás
pai
commit
41348a76ef
2 arquivos alterados com 19 adições e 26 exclusões
  1. 15 0
      borg/testsuite/__init__.py
  2. 4 26
      borg/testsuite/archiver.py

+ 15 - 0
borg/testsuite/__init__.py

@@ -93,6 +93,21 @@ class BaseTestCase(unittest.TestCase):
         for sub_diff in diff.subdirs.values():
         for sub_diff in diff.subdirs.values():
             self._assert_dirs_equal_cmp(sub_diff)
             self._assert_dirs_equal_cmp(sub_diff)
 
 
+    @contextmanager
+    def fuse_mount(self, location, mountpoint):
+        os.mkdir(mountpoint)
+        self.cmd('mount', location, mountpoint, fork=True)
+        self.wait_for_mount(mountpoint)
+        yield
+        if sys.platform.startswith('linux'):
+            cmd = 'fusermount -u %s' % mountpoint
+        else:
+            cmd = 'umount %s' % mountpoint
+        os.system(cmd)
+        os.rmdir(mountpoint)
+        # Give the daemon some time to exit
+        time.sleep(.2)
+
     def wait_for_mount(self, path, timeout=5):
     def wait_for_mount(self, path, timeout=5):
         """Wait until a filesystem is mounted on `path`
         """Wait until a filesystem is mounted on `path`
         """
         """

+ 4 - 26
borg/testsuite/archiver.py

@@ -975,45 +975,23 @@ class ArchiverTestCase(ArchiverTestCaseBase):
 
 
     @unittest.skipUnless(has_llfuse, 'llfuse not installed')
     @unittest.skipUnless(has_llfuse, 'llfuse not installed')
     def test_fuse_mount_repository(self):
     def test_fuse_mount_repository(self):
-        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
-        os.mkdir(mountpoint)
         self.cmd('init', self.repository_location)
         self.cmd('init', self.repository_location)
         self.create_test_files()
         self.create_test_files()
         self.cmd('create', self.repository_location + '::archive', 'input')
         self.cmd('create', self.repository_location + '::archive', 'input')
         self.cmd('create', self.repository_location + '::archive2', 'input')
         self.cmd('create', self.repository_location + '::archive2', 'input')
-        try:
-            self.cmd('mount', self.repository_location, mountpoint, fork=True)
-            self.wait_for_mount(mountpoint)
+        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
+        with self.fuse_mount(self.repository_location, mountpoint):
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive2', 'input'))
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive2', 'input'))
-        finally:
-            if sys.platform.startswith('linux'):
-                os.system('fusermount -u ' + mountpoint)
-            else:
-                os.system('umount ' + mountpoint)
-            os.rmdir(mountpoint)
-            # Give the daemon some time to exit
-            time.sleep(.2)
 
 
     @unittest.skipUnless(has_llfuse, 'llfuse not installed')
     @unittest.skipUnless(has_llfuse, 'llfuse not installed')
     def test_fuse_mount_archive(self):
     def test_fuse_mount_archive(self):
-        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
-        os.mkdir(mountpoint)
         self.cmd('init', self.repository_location)
         self.cmd('init', self.repository_location)
         self.create_test_files()
         self.create_test_files()
         self.cmd('create', self.repository_location + '::archive', 'input')
         self.cmd('create', self.repository_location + '::archive', 'input')
-        try:
-            self.cmd('mount', self.repository_location + '::archive', mountpoint, fork=True)
-            self.wait_for_mount(mountpoint)
+        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
+        with self.fuse_mount(self.repository_location + '::archive', mountpoint):
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'input'))
             self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'input'))
-        finally:
-            if sys.platform.startswith('linux'):
-                os.system('fusermount -u ' + mountpoint)
-            else:
-                os.system('umount ' + mountpoint)
-            os.rmdir(mountpoint)
-            # Give the daemon some time to exit
-            time.sleep(.2)
 
 
     def verify_aes_counter_uniqueness(self, method):
     def verify_aes_counter_uniqueness(self, method):
         seen = set()  # Chunks already seen
         seen = set()  # Chunks already seen