[Piuparts-commits] rev 536 - in trunk: . debian

Holger Levsen holger at alioth.debian.org
Fri Dec 4 15:08:58 UTC 2009


Author: holger
Date: 2009-12-04 15:08:56 +0000 (Fri, 04 Dec 2009)
New Revision: 536

Modified:
   trunk/debian/changelog
   trunk/piuparts.1.txt
   trunk/piuparts.py
Log:
* piuparts.py:
  - Add support for using LVM snapshots. Thanks to
    Patrick Schoenfeld for the patch. (Closes: #559449)

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2009-12-03 13:31:56 UTC (rev 535)
+++ trunk/debian/changelog	2009-12-04 15:08:56 UTC (rev 536)
@@ -1,3 +1,11 @@
+piuparts (0.38) UNRELEASED; urgency=low
+
+  * piuparts.py:
+    - Add support for using LVM snapshots. Thanks to
+      Patrick Schoenfeld for the patch. (Closes: #559449)
+
+ -- Holger Levsen <holger at debian.org>  Fri, 04 Dec 2009 15:55:42 +0100
+
 piuparts (0.37) unstable; urgency=low
 
   * piuparts-report.py: report packages with update-rc.d warnings and those 

Modified: trunk/piuparts.1.txt
===================================================================
--- trunk/piuparts.1.txt	2009-12-03 13:31:56 UTC (rev 535)
+++ trunk/piuparts.1.txt	2009-12-04 15:08:56 UTC (rev 536)
@@ -47,6 +47,15 @@
 +
 The tarball can be created with the '-s' option, or you can use one that *pbuilder* has created (see '-p'). If you create one manually, make sure the root of the chroot is the root of the tarball.
 
+*--lvm-volume*='lvm-volume'::
+  Use the specified lvm-volume as source for the chroot, instead of building a
+  new one with debootstrap. This creates a snapshot of the given LVM volume and
+  mounts it to the chroot path.
+
+*--lvm-snapshot-size*='snapshot-size'::
+  Use the specified snapshot-size as snapshot size when creating a new LVM
+  snapshot (default: 1G)
+
 *-d* 'name', *--distribution*='name'::
   Which Debian distribution to use: a code name (etch, lenny, sid) or experimental. The default is sid (i.e, unstable).
 

Modified: trunk/piuparts.py
===================================================================
--- trunk/piuparts.py	2009-12-03 13:31:56 UTC (rev 535)
+++ trunk/piuparts.py	2009-12-04 15:08:56 UTC (rev 536)
@@ -49,6 +49,7 @@
 import subprocess
 import unittest
 import urllib
+import uuid
 from debian_bundle import deb822
 
 
@@ -137,6 +138,7 @@
         self.debian_distros = []
         self.bindmounts = []
         self.basetgz = None
+        self.lvm_volume = None
         self.savetgz = None
         self.endmeta = None
         self.saveendmeta = None
@@ -554,6 +556,8 @@
 
         if settings.basetgz:
             self.unpack_from_tgz(settings.basetgz)
+        elif settings.lvm_volume:
+            self.setup_from_lvm(settings.lvm_volume)
         else:
             self.setup_minimal_chroot()
 
@@ -585,6 +589,10 @@
         if not settings.keep_tmpdir and os.path.exists(self.name):
             self.unmount_proc()
             self.unmount_selinux()
+            if settings.lvm_volume:
+                logging.debug('Unmounting and removing LVM snapshot %s' % self.lvm_snapshot_name)
+                run(['umount', self.name])
+                run(['lvremove', '-f', self.lvm_snapshot])
             shutil.rmtree(self.name)
             logging.debug("Removed directory tree at %s" % self.name)
         elif settings.keep_tmpdir:
@@ -608,6 +616,18 @@
         logging.debug("Unpacking %s into %s" % (tarball, self.name))
         run(["tar", "-C", self.name, "-zxf", tarball])
 
+    def setup_from_lvm(self, lvm_volume):
+        """Create a chroot by creating an LVM snapshot."""
+        self.lvm_base = os.path.dirname(lvm_volume)
+        self.lvm_vol_name = os.path.basename(lvm_volume)
+        self.lvm_snapshot_name = self.lvm_vol_name + "-" + str(uuid.uuid1());
+        self.lvm_snapshot = os.path.join(self.lvm_base, self.lvm_snapshot_name)
+
+        logging.debug("Creating LVM snapshot %s from %s" % (self.lvm_snapshot, lvm_volume))
+        run(['lvcreate', '-n', self.lvm_snapshot, '-s', lvm_volume, '-L', settings.lvm_snapshot_size])
+        logging.info("Mounting LVM snapshot to %s" % self.name); 
+        run(['mount', self.lvm_snapshot, self.name])
+
     def run(self, command, ignore_errors=False):
         return run(["chroot", self.name] + command,
                    ignore_errors=ignore_errors)
@@ -1712,7 +1732,6 @@
 def set_basetgz_to_pbuilder(option, opt, value, parser, *args, **kwargs):
     parser.values.basetgz = "/var/cache/pbuilder/base.tgz"
 
-
 def parse_command_line():
     """Parse the command line, change global settings, return non-options."""
     
@@ -1731,7 +1750,16 @@
                       help="Use TARBALL as the contents of the initial " +
                            "chroot, instead of building a new one with " +
                            "debootstrap.")
-    
+
+    parser.add_option("--lvm-volume", metavar="LVM-VOL", action="store",
+                      help="Use LVM-VOL as source for the chroot, instead of building " +
+                           "a new one with debootstrap. This creates a snapshot of the " +
+                           "given LVM volume and mounts it to the chroot path")
+
+    parser.add_option("--lvm-snapshot-size", metavar="SNAPSHOT-SIZE", action="store",
+                      default="1G", help="Use SNAPSHOT-SIZE as snapshot size when creating " +
+                      "a new LVM snapshot (default: 1G)")
+
     parser.add_option("-B", "--end-meta", metavar="FILE",
                       help="XXX")
     
@@ -1854,6 +1882,8 @@
     settings.defaults = opts.defaults
     settings.args_are_package_files = not opts.apt
     settings.basetgz = opts.basetgz
+    settings.lvm_volume = opts.lvm_volume
+    settings.lvm_snapshot_size = opts.lvm_snapshot_size
     settings.bindmounts += opts.bindmount
     settings.debian_distros = opts.distribution
     settings.ignored_files += opts.ignore




More information about the Piuparts-commits mailing list