[PATCH 10/10] Make nfsiso work in repo UI for Installation Repo.

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

 



Also refactor some mounting fuctions.
---
 data/ui/addrepo.glade     |    1 +
 pyanaconda/image.py       |   45 -----------------
 pyanaconda/iutil.py       |   13 +++++
 pyanaconda/iw/task_gui.py |   10 ++++-
 pyanaconda/yuminstall.py  |  116 ++++++++++++++++++++++++++++++++------------
 5 files changed, 107 insertions(+), 78 deletions(-)

diff --git a/data/ui/addrepo.glade b/data/ui/addrepo.glade
index 7a6637e..69cab86 100644
--- a/data/ui/addrepo.glade
+++ b/data/ui/addrepo.glade
@@ -194,6 +194,7 @@
 		  <property name="items" translatable="yes">HTTP/FTP
 CD/DVD
 NFS
+NFS ISO
 Hard Drive</property>
 		  <property name="add_tearoffs">False</property>
 		  <property name="focus_on_click">True</property>
diff --git a/pyanaconda/image.py b/pyanaconda/image.py
index 9341192..84c5511 100644
--- a/pyanaconda/image.py
+++ b/pyanaconda/image.py
@@ -122,51 +122,6 @@ def getMediaId(path):
     else:
         return None
 
-# This mounts the directory containing the iso images, and places the
-# mount point in /mnt/isodir.
-def mountDirectory(methodstr, messageWindow):
-    if methodstr.startswith("hd:"):
-        method = methodstr[3:]
-        if method.count(":") == 1:
-            (device, path) = method.split(":")
-            fstype = "auto"
-        else:
-            (device, fstype, path) = method.split(":")
-
-        if not device.startswith("/dev/") and not device.startswith("UUID=") \
-           and not device.startswith("LABEL="):
-            device = "/dev/%s" % device
-    elif methodstr.startswith("nfsiso:"):
-        device = methodstr[7:]
-        fstype = "nfs"
-    else:
-        return
-
-    # No need to mount it again.
-    if os.path.ismount("/mnt/isodir"):
-        return
-
-    while True:
-        try:
-            isys.mount(device, "/mnt/isodir", fstype = fstype)
-            break
-        except SystemError, msg:
-            log.error("couldn't mount ISO source directory: %s" % msg)
-            ans = messageWindow(_("Couldn't Mount ISO Source"),
-                          _("An error occurred mounting the source "
-                            "device %s.  This may happen if your ISO "
-                            "images are located on an advanced storage "
-                            "device like LVM or RAID, or if there was a "
-                            "problem mounting a partition.  Click exit "
-                            "to abort the installation.")
-                          % (device,), type="custom", custom_icon="error",
-                          custom_buttons=[_("_Exit"), _("_Retry")])
-
-            if ans == 0:
-                sys.exit(0)
-            else:
-                continue
-
 def mountImage(isodir, tree, discnum, messageWindow, discImages={}):
     if os.path.ismount(tree):
         raise SystemError, "trying to mount already-mounted iso image!"
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 9a1c142..3aacd12 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -1074,6 +1074,19 @@ def parseNfsUrl(nfsurl):
             host = s[0]
     return (options, host, path)
 
+def parseHdUrl(url):
+    device = ''
+    fstype = ''
+    path = ''
+    if url:
+        s = url.split(":")
+        s.pop(0)
+        if len(s) >= 3:
+            (device, fstype, path) = s[:3]
+        elif len(2) == 2:
+            (device, path) = s
+    return (device, fstype, path)
+
 def add_po_path(module, dir):
     """ Looks to see what translations are under a given path and tells
     the gettext module to use that path as the base dir """
diff --git a/pyanaconda/iw/task_gui.py b/pyanaconda/iw/task_gui.py
index 3a6392e..5da1bd1 100644
--- a/pyanaconda/iw/task_gui.py
+++ b/pyanaconda/iw/task_gui.py
@@ -104,6 +104,7 @@ class RepoEditor:
         store.append(["HTTP/FTP", "http", self._applyURL, 0])
         store.append(["NFS", "nfs", self._applyNfs, 2])
         if repotype == "method":
+            store.append(["NFS ISO", "nfsiso", self._applyNfsIso, 2])
             store.append(["CD/DVD", "cdrom", self._applyMedia, 1])
         #store.append(["HD", "hd", self._applyHd, 3])
 
@@ -111,7 +112,8 @@ class RepoEditor:
         d = {"http":"http",
              "ftp":"http",
              "cdrom":"cdrom",
-             "nfs":"nfs",
+             "nfsiso":"nfsiso",
+             "nfs:":"nfs",
              "hd":"hd"}
         for prefix in d:
             if url.startswith(prefix):
@@ -245,6 +247,12 @@ class RepoEditor:
         self.repo.url = "nfs:%s:%s:%s" % (options,server,path)
         return True
 
+    def _applyNfsIso(self):
+        if not self._applyNfs():
+            return False
+        self.repo.url = "nfsiso" + self.repo.url[3:]
+        return True
+
     def _applyHd(self):
         return True
 
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index c94f14c..84e6aca 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -234,24 +234,90 @@ class YumRepoSpec(RepoSpec):
         self.enabled = yumrepo.enabled
         self.mediaid = yumrepo.mediaid
 
-    def mount(self, ayum):
-        # TODORV: failure handling
-        if self.url.startswith("hd:"):
-            if self.url.count(":") == 2:
-                (device, path) = self.url[3:].split(":")
-            else:
-                (device, fstype, path) = self.url[3:].split(":")
+    # TODORV: handle failure (UI, setup attribute)
+    def _umountIsodir(self, ayum):
+        if os.path.ismount(ayum.tree):
+            isys.umount(ayum.tree, removeDir=False)
+            ayum.currentMedia = None
+        if os.path.isdir(ayum.isodir):
+            if os.path.ismount(ayum.isodir):
+                isys.umount(ayum.isodir, removeDir=False)
+        else:
+            os.mkdir(ayum.isodir)
+
+    def _mountUI(self, intf, device, path, fstype, options=None, msg=("","")):
+        title, msg = msg
+        while True:
+            try:
+                isys.mount(device, path, fstype=fstype, options=options)
+                break
+            except SystemError as e:
+                log.error("repository mounting failed: %s" % e)
+                ans = intf.messageWindow(title,
+                                         "%s \n%s" % (msg, e),
+                                         type="custom", custom_icon="error",
+                                         custom_buttons=[_("_Exit"), _("_Edit"), _("_Retry")])
+
+                if ans == 0:
+                    sys.exit(0)
+                elif ans == 1:
+                    self.setup = "failed"
+                    self.setup_fail_comment = msg
+                    return False
+                else:
+                    continue
+        return True
 
-            ayum.isodir = "/mnt/isodir/%s" % path
+    def _mountNfsIso(self, ayum):
+        (opts, server, path) = iutil.parseNfsUrl(self.url)
+        ayum.isodir = "/mnt/isodir"
+        title = _("Couldn't Mount ISO Source")
+        msg = _("An error occurred mounting the ISO source "
+                "on %s.") % server+":"+path
+        return self._mountIso(ayum, server+":"+path,
+                              ayum.isodir, "nfs", options=opts,
+                              msg=(title, msg))
+
+    def _mountHdIso(self, ayum):
+        (device, fstype, path) = iutil.parseHdUrl(self.url)
+        ayum.isodir = "/mnt/isodir/%s" % path
+        title = _("Couldn't Mount ISO Source")
+        msg = _("An error occurred mounting the source "
+                "device %s.  This may happen if your ISO "
+                "images are located on an advanced storage "
+                "device like LVM or RAID, or if there was a "
+                "problem mounting a partition.") % device
+        return self._mountIso(ayum, device, ayum.isodir,
+                              fstype or "auto", msg=(title, msg))
+
+    def _mountIso(self, ayum, device, path, fstype, options=None, msg=""):
+        self._umountIsodir(ayum)
+        if not self._mountUI(ayum.anaconda.intf, device, path, fstype, options=options, msg=msg):
+            return False
+        ayum._switchImage(1)
+        ayum.mediagrabber = ayum.mediaHandler
+        return True
 
-            # This takes care of mounting /mnt/isodir first.
-            ayum._switchImage(1)
-            ayum.mediagrabber = ayum.mediaHandler
+    def _mountNfs(self, ayum, dest):
+        (opts, server, path) = iutil.parseNfsUrl(self.url)
+        title = _("Couldn't Mount Source Tree")
+        msg = _("An error occured mounting the source tree on %s") % server+":"+path
+        return self._mountUI(ayum.anaconda.intf, server+":"+path, dest, "nfs",
+                             options=opts, msg=(title, msg))
+    def mount(self, ayum):
+        if self.url.startswith("hd:"):
+            if not self._mountHdIso(ayum):
+                return False
+            self.baseurl = "file://%s" % ayum.tree
         elif self.url.startswith("http") or self.url.startswith("ftp:"):
             self.baseurl = self.url
         elif self.url.startswith("cdrom:"):
             # When/if supported (KS, UI), parse device
-            if not self.media_device:
+            # nfsiso or hdiso could have been mounted to ayum.tree
+            if ayum.isodir and os.path.ismount(ayum.tree):
+                isys.umount(ayum.tree, removeDir=False)
+                ayum.currentMedia = None
+            if not self.media_device or ayum.isodir:
                 cdr = scanForMedia(ayum.tree, ayum.anaconda.storage)
                 if cdr:
                     self.media_device = cdr
@@ -274,12 +340,8 @@ class YumRepoSpec(RepoSpec):
             else:
                 dest = tempfile.mkdtemp("", self.name.replace(" ", ""), "/mnt")
 
-            (opts, server, path) = iutil.parseNfsUrl(self.url)
-            try:
-                isys.mount(server+":"+path, dest, "nfs", options=opts)
-            except Exception as e:
-                log.error("error mounting NFS repo %s: %s" % (self.name, e))
-                raise
+            if not self._mountNfs(ayum, dest):
+                return False
             self.baseurl = "file://%s" % dest
 
             # This really should be fixed in loader instead but for now see
@@ -288,18 +350,13 @@ class YumRepoSpec(RepoSpec):
             if self.type == "method":
                 images = findIsoImages(ayum.tree, ayum.anaconda.intf.messageWindow)
                 if images != {}:
-                    isys.umount(ayum.tree, removeDir=False)
                     self.url = "nfsiso:%s" % self.url[4:]
-                    # TODORV - fix properly? SPOT?
-                    # "nfsiso:" case pasted
-                    ayum.isodir = "/mnt/isodir"
-                    ayum._switchImage(1)
-                    ayum.mediagrabber = ayum.mediaHandler
+                    if not self._mountNfsIso(ayum):
+                        return False
                     self.baseurl = "file://%s" % ayum.tree
         elif self.url.startswith("nfsiso:"):
-            ayum.isodir = "/mnt/isodir"
-            ayum._switchImage(1)
-            ayum.mediagrabber = ayum.mediaHandler
+            if not self._mountNfsIso(ayum):
+                return False
             self.baseurl = "file://%s" % ayum.tree
         else:
             log.info("repo %s has unsupported url: %s" % (self.name,
@@ -614,11 +671,6 @@ class AnacondaYum(YumSorter):
         umountImage(self.tree, self.currentMedia)
         self.currentMedia = None
 
-        # mountDirectory checks before doing anything, so it's safe to
-        # call this repeatedly.
-        mountDirectory(self.anaconda.methodstr,
-                       self.anaconda.intf.messageWindow)
-
         self._discImages = mountImage(self.isodir, self.tree, discnum,
                                       self.anaconda.intf.messageWindow,
                                       discImages=self._discImages)
-- 
1.7.2

_______________________________________________
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