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

[Fedora-livecd-list] Fix yum to not look at host config



Hey,
	So, I've been seeing two symptoms which suggested that yum was looking
at the hosts config/cache, when clearly the code is trying it's best not
to:

  1) If a repo in the host's config was broken, it would die in 
     doConfigSetup() - e.g. if the host which the repo is on couldn't 
     be contacted

  2) The livecd repos were clearly being at least partly cached outside 
     the install root - e.g. because /var/cache/yum/a-dev gets created.

	Attached is a patch which fixes this, I think. It writes out its own
yum.conf so that the host's repos never get initialised and uses the
installroot config item which seems to do a better job of restricting
yum to the install root.

	Oh, another side effect is that you can now use a repo called
fedora-development :-)

	There's one fly in the ointment, though - now that we're properly
caching in the install root, we hit a bug whereby we can't tell yum to
close these caches before we unmount. See:

   https://bugzilla.redhat.com/236409

	The second patch I've attached is a pretty brute force workaround for
this.

Cheers,
Mark.
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -183,20 +183,26 @@ class LiveCDYum(yum.YumBase):
         # being left and an inability to clean up after ourself
         pass
 
-    def setup(self, instroot):
-        self.installroot = instroot
-        self.doConfigSetup(root=instroot, init_plugins = False)
-        self.doGenericSetup()
+    def writeConf(self, datadir, installroot):
+        conf  = "[main]\n"
+        conf += "installroot=%s\n" % installroot
+        conf += "cachedir=/var/cache/yum\n"
+        conf += "plugins=0\n"
+        conf += "reposdir=\n"
 
-        self.conf.cachedir = "/var/cache/yum"
+        path = datadir + "/yum.conf"
 
-        # don't look at the default repos from the host config
-        map(lambda x: self.repos.delete(x), self.repos.repos.keys())
+        f = file(path, "w+")
+        f.write(conf)
+        f.close()
+
+        os.chmod(path, 0644)
 
-    def reset(self):
-        self.closeRpmDB()
-        self.doTsSetup()
-        self.doRpmDBSetup()
+        return path
+
+    def setup(self, datadir, installroot):
+        self.doConfigSetup(fn = self.writeConf(datadir, installroot))
+        self.doGenericSetup()
 
     def selectPackage(self, pkg):
         """Select a given package.  Can be specified with name.arch or name*"""
@@ -273,7 +279,7 @@ class LiveCDYum(yum.YumBase):
 
 class InstallationTarget:
     def __init__(self, repos, packages, epackages, groups, fs_label, skip_compression, skip_prelink):
-        self.ayum = LiveCDYum()
+        self.ayum = None
         self.repos = repos
         self.packages = packages
         self.epackages = epackages
@@ -418,11 +424,13 @@ class InstallationTarget:
 
         self.write_fstab()
 
-        self.ayum.setup("%s/install_root" %(self.build_dir,))
+        self.ayum = LiveCDYum()
+        self.ayum.setup(self.build_dir + "/data",
+                        self.build_dir + "/install_root")
 
     def unmount(self):
         """detaches system bind mounts and install_root for the file system and tears down loop devices used"""
-        shutil.rmtree(self.build_dir + "/yum-cache", ignore_errors=True)
+        self.ayum = None
         
         try:
             os.unlink(self.build_dir + "/install_root/etc/mtab")
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -431,7 +431,17 @@ class InstallationTarget:
     def unmount(self):
         """detaches system bind mounts and install_root for the file system and tears down loop devices used"""
         self.ayum = None
-        
+
+        # Make one last ditch effort to close fds still open
+        # in the install root; this is only needed because
+        # there's no way to ask yum to close its sqlite dbs,
+        # though. See https://bugzilla.redhat.com/236409
+        for i in range(3, os.sysconf("SC_OPEN_MAX")):
+            try:
+                os.close(i)
+            except:
+                pass
+
         try:
             os.unlink(self.build_dir + "/install_root/etc/mtab")
         except OSError:

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