Просмотр исходного кода

Replace `dismount_os` sorting logic with `umount -R`

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 дней назад
Родитель
Сommit
0dbfa91114
2 измененных файлов с 2 добавлено и 31 удалено
  1. 1 17
      coriolis/osmorphing/osmount/base.py
  2. 1 14
      coriolis/tests/osmorphing/osmount/test_base.py

+ 1 - 17
coriolis/osmorphing/osmount/base.py

@@ -640,24 +640,8 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
 
     def dismount_os(self, root_dir):
         self._exec_cmd('sudo fuser --kill --mount %s || true' % root_dir)
-        mounted_fs = self._get_mount_destinations()
-        # Sort all mounted filesystems by length. This will ensure that
-        # the first in the list is a subfolder of the next in the list,
-        # and we unmount them in the proper order
-        mounted_fs = list(reversed(sorted(mounted_fs, key=len)))
-        for d in mounted_fs:
-            # umount these two at the very end
-            if d.endswith('/dev') or d.rstrip('/') == root_dir.rstrip('/'):
-                continue
-            if d.startswith(root_dir):
-                # mounted filesystem is a subfolder of our root_dir
-                self._exec_cmd('sudo umount %s' % d)
-
-        dev_fs = "%s/%s" % (root_dir.rstrip('/'), "dev")
-        self._exec_cmd('mountpoint -q %s && sudo umount %s' %
-                       (dev_fs, dev_fs))
         self._exec_cmd(
-            'mountpoint -q %s && sudo umount %s' % (root_dir, root_dir))
+            'mountpoint -q %s && sudo umount -R %s' % (root_dir, root_dir))
 
     def set_proxy(self, proxy_settings):
         url = proxy_settings.get('url')

+ 1 - 14
coriolis/tests/osmorphing/osmount/test_base.py

@@ -985,26 +985,13 @@ class BaseLinuxOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
     @mock.patch.object(base.BaseSSHOSMountTools, '_exec_cmd')
     def test_dismount_os(self, mock_exec_cmd):
         root_dir = "/mnt/root_dir"
-        mock_exec_cmd.side_effect = [
-            None,
-            ("/dev/sda1 /mnt/root_dir/sub_dir type ext4\n"
-             "/dev/sda2 /mnt/root_dir/dev type ext4\n"
-             "/dev/sda3 /mnt/root_dir type ext4\n"),
-            None,
-            None,
-            None,
-        ]
 
         self.base_os_mount_tools.dismount_os(root_dir)
 
         mock_exec_cmd.assert_has_calls([
             mock.call("sudo fuser --kill --mount /mnt/root_dir || true"),
-            mock.call("cat /proc/mounts"),
-            mock.call("sudo umount /mnt/root_dir/sub_dir"),
-            mock.call("mountpoint -q /mnt/root_dir/dev"
-                      " && sudo umount /mnt/root_dir/dev"),
             mock.call(
-                "mountpoint -q /mnt/root_dir && sudo umount /mnt/root_dir"),
+                "mountpoint -q /mnt/root_dir && sudo umount -R /mnt/root_dir"),
         ])
 
     @mock.patch.object(base.utils, 'get_url_with_credentials')