[master] Check if a medium is mounted from the 'mount' output instead of FSSet.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is because the information that FSSet provides depends on the
information udev is able to provide and this is incomplete for certain
virtual DVD drives.

Unittest for iutil.is_dev_mounted_on() included.

Resolves: rhbz#702511
---
 pyanaconda/iutil.py                 |    8 ++++++++
 pyanaconda/yuminstall.py            |   11 +++++------
 tests/pyanaconda_test/iutil_test.py |   31 +++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 tests/pyanaconda_test/iutil_test.py

diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 2387576..e77c5a4 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -965,3 +965,11 @@ def fork_orphan():
     # the original process waits for the intermediate child
     os.waitpid(intermediate, 0)
     return 1
+
+def is_dev_mounted_on(dev, mountpoint):
+    regex = re.compile("^%s on (\S*)" % dev)
+    for line in execWithCapture("mount", []).splitlines():
+        m = regex.match(line)
+        if m and m.group(1) == mountpoint:
+            return True
+    return False
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index 378d4a1..4211257 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -375,7 +375,11 @@ class AnacondaYum(yum.YumBase):
         # See if there's any media mounted on self.tree before continuing.
         # This saves a useless eject and insert if the user has already put
         # the disc in the drive.
-        if not self.anaconda.storage.fsset.mountpoints.has_key(self.tree):
+        if iutil.is_dev_mounted_on(dev.path, self.tree):
+            if verifyMedia(self.tree, None):
+                return
+            dev.format.unmount()
+        else:
             try:
                 dev.format.mount()
 
@@ -385,11 +389,6 @@ class AnacondaYum(yum.YumBase):
                 dev.format.unmount()
             except Exception:
                 pass
-        else:
-            if verifyMedia(self.tree, None):
-                return
-
-            dev.format.unmount()
 
         dev.eject()
 
diff --git a/tests/pyanaconda_test/iutil_test.py b/tests/pyanaconda_test/iutil_test.py
new file mode 100644
index 0000000..164351d
--- /dev/null
+++ b/tests/pyanaconda_test/iutil_test.py
@@ -0,0 +1,31 @@
+import mock
+
+
+class IutilTest(mock.TestCase):
+    def setUp(self):
+        self.setupModules(
+            ['_isys', 'logging', 'pyanaconda.anaconda_log', 'block'])
+
+        from pyanaconda import iutil
+        iutil.log = mock.Mock()
+        iutil.log = mock.Mock()
+
+    def tearDown(self):
+        self.tearDownModules()
+
+    def is_dev_mounted_on_test(self):
+        from pyanaconda import iutil
+        iutil.execWithCapture = mock.Mock()
+        iutil.execWithCapture.return_value = """
+rootfs on / type rootfs (rw,relatime)
+/proc on /proc type proc (rw,relatime)
+/dev on /dev type tmpfs (rw,relatime,seclabel)
+/dev/pts on /dev/pts type devpts (rw,relatime,seclabel,mode=600,ptmxmode=000)
+/sys on /sys type sysfs (rw,relatime,seclabel)
+none on /tmp type tmpfs (rw,relatime,seclabel,size=256000k)
+/dev/sr0 on /mnt/source type iso9660 (ro,relatime)
+/selinux on /selinux type selinuxfs (rw,relatime)
+"""
+        self.assertTrue(iutil.is_dev_mounted_on("/dev/sr0", "/mnt/source"))
+        self.assertTrue(iutil.is_dev_mounted_on("rootfs", "/"))
+        self.assertFalse(iutil.is_dev_mounted_on("/dev/sr0", "/mnt/sysimage"))
-- 
1.7.3.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux