[Piuparts-commits] [piuparts] 12/23: p: add --shell-on-error option

Holger Levsen holger at layer-acht.org
Tue Jan 17 12:39:46 UTC 2017


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit 031dc264daf909bd43f58f10acd2401c04218aa7
Author: Andreas Beckmann <anbe at debian.org>
Date:   Mon Jan 16 11:59:56 2017 +0100

    p: add --shell-on-error option
    
    starts an interactive shell in the chroot for debugging
    
    does not work if piuparts is run under timeout
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
    Signed-off-by: Holger Levsen <holger at layer-acht.org>
---
 debian/changelog |  2 ++
 piuparts.1.txt   |  8 ++++++++
 piuparts.py      | 29 +++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 94ba3f8..b3a7688 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,8 @@ piuparts (0.75) UNRELEASED; urgency=medium
       + /etc/network/
       + /etc/php/7.0/ and selected subdirs
     - Run panic handlers in reverse order.
+    - Add --shell-on-error option to simplify debugging of piuparts failures.
+      Starts an interactive shell in the chroot if an error occurred.
     - Unmount /proc/sys/fs/binfmt_misc only if mounted.
   * piuparts.conf:
     - Add new suite: stretch-rcmd (test with --install-recommends).
diff --git a/piuparts.1.txt b/piuparts.1.txt
index 80ae746..751e5ee 100644
--- a/piuparts.1.txt
+++ b/piuparts.1.txt
@@ -226,6 +226,14 @@ Note that file: addresses works if the directories are made accessible from with
 *--single-packages*::
   Process every package file or package name individually, thus piuparts process runs multiple times. This option can be useful with conflicting packages.
 
+*--shell-on-error*::
+  Start an interactive shell in the chroot after an error occurred.
+  This should help debugging failures directly inside the piuparts test environment.
+  The chroot cleanup will continue after the shell terminates.
+  Note: This does not work if the piuparts command is prefixed with 'timeout',
+  which is usually the case in command lines directly copied from logfiles
+  from a master-slave setup. Removing the 'timeout' part is sufficient.
+
 *--skip-minimize*::
   Allow skip minimize chroot step. This is useful when you want to test several packages with piuparts. You can prepare a tarball already minimized and skip this step in all the tests. This is the default now.
 
diff --git a/piuparts.py b/piuparts.py
index fd64e25..73182cf 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -149,6 +149,7 @@ class Settings:
         self.defaults = None
         self.tmpdir = None
         self.keep_tmpdir = False
+        self.shell_on_error = False
         self.max_command_output_size = 8 * 1024 * 1024  # 8 MB (google-android-ndk-installer on install) (daptup on dist-upgrade)
         self.max_command_runtime = 60 * 60  # 60 minutes (texlive-full and blends metapackages on dist-upgrade)
         self.single_changes_list = False
@@ -896,6 +897,15 @@ class Chroot:
             dst = os.path.join(self.name, name)
             run(cmd + [src, dst])
 
+    def interactive_shell(self):
+        logging.info("Entering interactive shell in %s" % self.name)
+        env = os.environ.copy()
+        env['debian_chroot'] = "piuparts:%s" % self.name
+        try:
+            subprocess.call(['chroot', self.name, 'bash', '-l'], env=env)
+        except:
+            pass
+
     def run(self, command, ignore_errors=False):
         prefix = []
         if settings.eatmydata and os.path.isfile(os.path.join(self.name,
@@ -2665,6 +2675,9 @@ def install_and_upgrade_between_distros(package_files, packages_qualified):
         chroot.remove()
         return True
 
+    if settings.shell_on_error:
+        panic_handler_id = do_on_panic(lambda: chroot.interactive_shell())
+
     chroot.run_scripts("pre_test")
 
     os.environ["PIUPARTS_PHASE"] = "install"
@@ -2710,6 +2723,11 @@ def install_and_upgrade_between_distros(package_files, packages_qualified):
 
     result = check_results(chroot, chroot_state, file_owners)
 
+    if settings.shell_on_error:
+        dont_do_on_panic(panic_handler_id)
+        if not result:
+            chroot.interactive_shell()
+
     chroot.remove()
 
     return result
@@ -2996,6 +3014,10 @@ def parse_command_line():
                       action="append", default=[],
                       help="Directory where are placed the custom scripts. Can be given multiple times.")
 
+    parser.add_option("--shell-on-error", default=False,
+                      action='store_true',
+                      help="Execute an interactive shell in the chroot if an error occurred.")
+
     parser.add_option("-t", "--tmpdir", metavar="DIR",
                       help="Use DIR for temporary storage. Default is " +
                            "$TMPDIR or /tmp.")
@@ -3045,6 +3067,7 @@ def parse_command_line():
 
     settings.tmpdir = opts.tmpdir
     settings.keep_tmpdir = opts.keep_tmpdir
+    settings.shell_on_error = opts.shell_on_error
     settings.single_changes_list = opts.single_changes_list
     settings.single_packages = opts.single_packages
     settings.args_are_package_files = not opts.apt
@@ -3203,6 +3226,9 @@ def process_packages(package_list):
         chroot = get_chroot()
         chroot.create()
 
+        if settings.shell_on_error:
+            panic_handler_id = do_on_panic(lambda: chroot.interactive_shell())
+
         chroot_state = {}
         chroot_state["tree"] = chroot.save_meta_data()
         chroot_state["selections"] = chroot.get_selections()
@@ -3237,6 +3263,9 @@ def process_packages(package_list):
                     logging.error("FAIL: Installation, upgrade and purging tests.")
                     panic()
 
+        if settings.shell_on_error:
+            dont_do_on_panic(panic_handler_id)
+
         chroot.remove()
     else:
         if install_and_upgrade_between_distros(package_files, packages):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list