[Piuparts-commits] [SCM] piuparts git repository branch, master, updated. eda668423fa87898c59d1075118693714aa5a053

Holger Levsen holger at layer-acht.org
Fri Dec 23 10:27:28 UTC 2011


The following commit has been merged in the master branch:
commit 2a550c64635bf85aff342060b3d0268274415747
Merge: 46241f93d473d24229cf0b4f287aee313d6e5fa9 57d6c35fa6eb065049b4015a8f06421b50c15876
Author: Holger Levsen <holger at layer-acht.org>
Date:   Sun Nov 27 23:19:37 2011 +0100

    Merge branch 'fix/temp_tgz-handling' into develop

diff --combined piuparts.py
index a35d998,0b98969..d17b241
--- a/piuparts.py
+++ b/piuparts.py
@@@ -131,7 -131,7 +131,7 @@@ class Settings
      def __init__(self):
          self.defaults = None
          self.tmpdir = None
 -        self.scriptsdir = None
 +        self.scriptsdirs = []
          self.keep_tmpdir = False
          self.single_changes_list = False
          # limit output of logfiles to the last megabyte:
@@@ -715,41 -715,41 +715,43 @@@ class Chroot
          os.chmod(self.name, 0755)
          logging.debug("Created temporary directory %s" % self.name)
  
-     def create(self):
+     def create(self, temp_tgz = None):
          """Create a chroot according to user's wishes."""
          self.create_temp_dir()
          cid = do_on_panic(self.remove)
  
-         if settings.basetgz:
+         if temp_tgz:
+             self.unpack_from_tgz(temp_tgz)
+         elif settings.basetgz:
              self.unpack_from_tgz(settings.basetgz)
          elif settings.lvm_volume:
              self.setup_from_lvm(settings.lvm_volume)
          else:
              self.setup_minimal_chroot()
  
-         self.configure_chroot()
          self.mount_proc()
          self.mount_selinux()
+         self.configure_chroot()
          if settings.basetgz:
              self.run(["apt-get", "-yf", "upgrade"])
          self.minimize()
  
 -        #copy scripts dir into the chroot
 -        if settings.scriptsdir is not None:
 +        # Copy scripts dirs into the chroot, merging all dirs together,
 +        # later files overwriting earlier ones.
 +        if settings.scriptsdirs:
              dest = self.relative("tmp/scripts/")
              if not os.path.exists(self.relative("tmp/scripts/")):
                  os.mkdir(dest)
 -            logging.debug("Copying scriptsdir to %s" % dest)
 -            for sfile in os.listdir(settings.scriptsdir):
 -                if (sfile.startswith("post_") or sfile.startswith("pre_")) and os.path.isfile(os.path.join((settings.scriptsdir), sfile)):
 -                    shutil.copy(os.path.join((settings.scriptsdir), sfile), dest) 
 +            for sdir in settings.scriptsdirs:
 +                logging.debug("Copying scriptsdir %s to %s" % (sdir, dest))
 +                for sfile in os.listdir(sdir):
 +                    if (sfile.startswith("post_") or sfile.startswith("pre_")) and os.path.isfile(os.path.join(sdir, sfile)):
 +                        shutil.copy(os.path.join(sdir, sfile), dest)
  
          # Run custom scripts after creating the chroot.
          self.run_scripts("post_setup")
  
-         if settings.savetgz:
+         if settings.savetgz and not temp_tgz:
              self.pack_into_tgz(settings.savetgz)
  
          dont_do_on_panic(cid)
@@@ -775,12 -775,18 +777,18 @@@
          (fd, temp_tgz) = create_temp_file()
          return temp_tgz
  
+     def remove_temp_tgz_file(self, temp_tgz):
+         """Remove the file that was used as a temporary tgz file"""
+         # Yes, remove_files() would work just as well, but putting it in
+         # the interface for Chroot allows the VirtServ hack to work.
+         remove_files([temp_tgz])
+ 
      def pack_into_tgz(self, result):
          """Tar and compress all files in the chroot."""
          self.run(["apt-get", "clean"])
          logging.debug("Saving %s to %s." % (self.name, result))
  
-         run(['tar', '--exclude', './proc/*', '-czf', result, '-C', self.name, './'])
+         run(['tar', '-czf', result, '--one-file-system', '--exclude', 'tmp/scripts', '-C', self.name, './'])
  
      def unpack_from_tgz(self, tarball):
          """Unpack a tarball to a chroot."""
@@@ -898,7 -904,6 +906,7 @@@
  
      def configure_chroot(self):
          """Configure a chroot according to current settings"""
 +        os.environ["PIUPARTS_DISTRIBUTION"] = settings.debian_distros[0]
          if not settings.keep_sources_list:
              self.create_apt_sources(settings.debian_distros[0])
          self.create_apt_conf()
@@@ -913,14 -918,11 +921,14 @@@
          """Upgrade a chroot installation to each successive distro."""
          for distro in distros:
              logging.debug("Upgrading %s to %s" % (self.name, distro))
 +            os.environ["PIUPARTS_DISTRIBUTION_NEXT"] = distro
              self.create_apt_sources(distro)
              # Run custom scripts before upgrade
              self.run_scripts("pre_distupgrade")
              self.run(["apt-get", "update"])
              self.run(["apt-get", "-yf", "dist-upgrade"])
 +            os.environ["PIUPARTS_DISTRIBUTION_PREV"] = os.environ["PIUPARTS_DISTRIBUTION"]
 +            os.environ["PIUPARTS_DISTRIBUTION"] = distro
              # Sometimes dist-upgrade won't upgrade the packages we want
              # to test because the new version depends on a newer library,
              # and installing that would require removing the old version
@@@ -1028,16 -1030,13 +1036,16 @@@
          added = [ln for ln in post_install_diversions if not ln in pre_install_diversions]
          return (removed, added)
  
 -    def remove_or_purge(self, operation, packages):
 -        """Remove or purge packages in a chroot."""
 -        for name in packages:
 -            self.run(["dpkg", "--" + operation, name], ignore_errors=True)
 -        self.run(["dpkg", "--remove", "--pending"], ignore_errors=True)
 -
 +    def remove_packages(self, packages):
 +        """Remove packages in a chroot."""
 +        if packages:
 +            self.run(["apt-get", "remove"] + packages, ignore_errors=True)
  
 +    def purge_packages(self, packages):
 +        """Purge packages in a chroot."""
 +        if packages:
 +            self.run(["dpkg", "--purge"] + packages, ignore_errors=True)
 + 
      def restore_selections(self, selections, packages):
          """Restore package selections in a chroot to the state in
          'selections'."""
@@@ -1064,8 -1063,8 +1072,8 @@@
          self.run_scripts("pre_remove")
  
          # First remove all packages.
 -        self.remove_or_purge("remove", deps_to_remove + deps_to_purge +
 -                                        nondeps_to_remove + nondeps_to_purge)
 +        self.remove_packages(deps_to_remove + deps_to_purge +
 +                             nondeps_to_remove + nondeps_to_purge)
          # Run custom scripts after removing all packages. 
          self.run_scripts("post_remove")
  
@@@ -1081,13 -1080,13 +1089,13 @@@
          if not settings.skip_logrotatefiles_test and logrotatefiles:
              installed = self.install_logrotate()
              self.check_output_logrotatefiles(logrotatefiles_list)
 -            self.remove_or_purge("purge", installed)
 +            self.purge_packages(installed)
  
          # Then purge all packages being depended on.
 -        self.remove_or_purge("purge", deps_to_purge)
 +        self.purge_packages(deps_to_purge)
  
          # Finally, purge actual packages.
 -        self.remove_or_purge("purge", nondeps_to_purge)
 +        self.purge_packages(nondeps_to_purge)
  
          # Run custom scripts after purge all packages.
          self.run_scripts("post_purge")
@@@ -1339,7 -1338,7 +1347,7 @@@
      def run_scripts (self, step):
          """ Run custom scripts to given step post-install|remove|purge"""
  
 -        if settings.scriptsdir is None:
 +        if not settings.scriptsdirs:
              return
          logging.info("Running scripts "+ step)
          basepath = self.relative("tmp/scripts/")
@@@ -1432,6 -1431,9 +1440,9 @@@ class VirtServ(Chroot)
      #  adt-virt revert
      def create_temp_tgz_file(self):
          return self
+     def remove_temp_tgz_file(self, tgz):
+         if tgz is not self: self._fail('removing a tgz not supported')
+         # FIXME: anything else to do here?
      def pack_into_tgz(self, tgz):
          if tgz is not self: self._fail('packing into tgz not supported')
          if not 'revert' in self._caps: self._fail('testbed cannot revert')
@@@ -1874,11 -1876,7 +1885,11 @@@ def install_purge_test(chroot, root_inf
         Assume 'root' is a directory already populated with a working
         chroot, with packages in states given by 'selections'."""
  
 +    os.environ["PIUPARTS_TEST"] = "install"
 +    chroot.run_scripts("pre_test")
 +
      # Install packages into the chroot.
 +    os.environ["PIUPARTS_PHASE"] = "install"
  
      if settings.warn_on_others:
          # Create a metapackage with dependencies from the given packages
@@@ -1914,7 -1912,7 +1925,7 @@@
          chroot.install_package_files([metapackage])
          # Now remove it
          metapackagename = os.path.basename(metapackage)[:-4]
 -        chroot.remove_or_purge("purge", [metapackagename])
 +        chroot.purge_packages([metapackagename])
          shutil.rmtree(os.path.dirname(metapackage))
  
          # Save the file ownership information so we can tell which
@@@ -1948,18 -1946,15 +1959,18 @@@ def install_upgrade_test(chroot, root_i
      """Install package via apt-get, then upgrade from package files.
      Return True if successful, False if not."""
  
 +    os.environ["PIUPARTS_TEST"] = "upgrade"
 +    chroot.run_scripts("pre_test")
 +
      # First install via apt-get.
 +    os.environ["PIUPARTS_PHASE"] = "install"
      chroot.install_packages_by_name(packages)
  
 -    chroot.run_scripts("pre_upgrade")
 -
      chroot.check_for_no_processes()
      chroot.check_for_broken_symlinks()
  
      # Then from the package files.
 +    os.environ["PIUPARTS_PHASE"] = "upgrade"
      chroot.install_package_files(package_files)
  
      chroot.check_for_no_processes()
@@@ -2019,23 -2014,20 +2030,22 @@@ def install_and_upgrade_between_distros
      # a reasonable default behaviour for distro upgrade tests, which are not 
      # done by default anyway.
  
 +    os.environ["PIUPARTS_TEST"] = "distupgrade"
 +
      chroot = get_chroot()
      chroot.create()
      cid = do_on_panic(chroot.remove)
  
-     if settings.basetgz:
-         root_tgz = settings.basetgz
-     else:
-         root_tgz = chroot.create_temp_tgz_file()
-         chroot.pack_into_tgz(root_tgz)
- 
      if settings.end_meta:
          # load root_info and selections
          root_info, selections = load_meta_data(settings.end_meta)
          chroot.pre_install_diversions = []  # FIXME: diversion info needs to be restored
      else:
+         if not settings.basetgz:
+             temp_tgz = chroot.create_temp_tgz_file()
+             # FIXME: on panic remove temp_tgz
+             chroot.pack_into_tgz(temp_tgz)
+ 
          chroot.upgrade_to_distros(settings.debian_distros[1:], [])
  
          chroot.check_for_no_processes()
@@@ -2052,31 -2044,30 +2062,36 @@@
  
          chroot.remove()
          dont_do_on_panic(cid)
+ 
+         # leave indication in logfile why we do what we do
+         logging.info("Notice: package selections and meta data from target disto saved, now starting over from source distro. See the description of --save-end-meta and --end-meta to learn why this is neccessary and how to possibly avoid it.")
+ 
          chroot = get_chroot()
-         chroot.create()
+         if settings.basetgz:
+             chroot.create()
+         else:
+             chroot.create(temp_tgz)
+             chroot.remove_temp_tgz_file(temp_tgz)
          cid = do_on_panic(chroot.remove)
  
-     # leave indication in logfile why we do what we do
-     logging.info("Notice: package selections and meta data from target disto saved, now starting over from source distro. See the description of --save-end-meta and --end-meta to learn why this is neccessary and how to possibly avoid it.")
- 
      chroot.check_for_no_processes()
  
 -    chroot.install_packages_by_name(packages)
 +    chroot.run_scripts("pre_test")
 +
 +    os.environ["PIUPARTS_PHASE"] = "install"
  
 -    chroot.run_scripts("pre_upgrade")
 +    chroot.install_packages_by_name(packages)
  
      chroot.check_for_no_processes()
  
 +    os.environ["PIUPARTS_PHASE"] = "distupgrade"
 +
      chroot.upgrade_to_distros(settings.debian_distros[1:], packages)
  
      chroot.check_for_no_processes()
  
 +    os.environ["PIUPARTS_PHASE"] = "upgrade"
 +
      chroot.install_package_files(package_files)
  
      chroot.check_for_no_processes()
@@@ -2089,8 -2080,6 +2104,6 @@@
  
      chroot.check_for_no_processes()
  
-     if root_tgz != settings.basetgz:
-         remove_files([root_tgz])
      chroot.remove()
      dont_do_on_panic(cid)
  
@@@ -2297,8 -2286,7 +2310,8 @@@ def parse_command_line()
                        help="Minimize chroot with debfoster. This used to be the default until #539142 was fixed.")
  
      parser.add_option("--scriptsdir", metavar="DIR",
 -                      help="Directory where are placed the custom scripts.")
 +                      action="append", default=[],
 +                      help="Directory where are placed the custom scripts. Can be given multiple times.")
  
      parser.add_option("-t", "--tmpdir", metavar="DIR",
                        help="Use DIR for temporary storage. Default is " +
@@@ -2414,10 -2402,11 +2427,10 @@@
          else:
              settings.tmpdir = "/tmp"
  
 -    if opts.scriptsdir is not None:
 -        settings.scriptsdir = opts.scriptsdir
 -        if not os.path.isdir(settings.scriptsdir):
 -            logging.error("Scripts directory is not a directory: %s" % 
 -                          settings.scriptsdir)
 +    settings.scriptsdirs = opts.scriptsdir
 +    for sdir in settings.scriptsdirs:
 +        if not os.path.isdir(sdir):
 +            logging.error("Scripts directory is not a directory: %s" % sdir)
              panic()
  
      if not settings.debian_distros:

-- 
piuparts git repository



More information about the Piuparts-commits mailing list