From 864ae115091964a4648667bc72e2c5d8f41effae Mon Sep 17 00:00:00 2001 From: wjunlu Date: Sun, 25 Jun 2023 15:20:37 +0800 Subject: [PATCH] Append detailed printing information when exec_sudo fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch tries to add more detailed info by appending error output to exec_sudo print. In current implementation, only a simple static note `Exception: exec_sudo failed` is printed: ``` INFO diskimage_builder.block_device.utils [-] Calling [sudo sgdisk /tmp/dib_image.jZaDPxtX/image0.raw -n 1:0:+550M -t 1:EF00 -c 1:ESP -n 2:0:+8M -t 2:EF02 -c 2:BSP -n 3:0:+2077M -t 3:8300 -c 3:root] ERROR diskimage_builder.block_device.blockdevice [-] Create failed; rollback initiated // ... ... diskimage_builder.block_device.exception.BlockDeviceSetupException: exec_sudo failed ``` but the root reason is missing. We can’t get more error info to make sure what the real root reason even a simple problem like `command not found`, we have to reproduce locally and manually. After this patch, the error message like: ``` INFO diskimage_builder.block_device.utils [-] Calling [sudo sgdisk /tmp/dib_image.jZaDPxtX/image0.raw -n 1:0:+550M -t 1:EF00 -c 1:ESP -n 2:0:+8M -t 2:EF02 -c 2:BSP -n 3:0:+2077M -t 3:8300 -c 3:root] ERROR diskimage_builder.block_device.blockdevice [-] Create failed; rollback initiated // ... ... diskimage_builder.block_device.exception.BlockDeviceSetupException: exec_sudo failed: sudo: sgdisk: command not found ``` We can easily find the real problem and solve it. Closes-Bug: #2024980 Change-Id: I9efcd9cb6621e6403df6de14f122b1cf371bd800 --- diskimage_builder/block_device/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diskimage_builder/block_device/utils.py b/diskimage_builder/block_device/utils.py index e0ea05e7..39919adb 100644 --- a/diskimage_builder/block_device/utils.py +++ b/diskimage_builder/block_device/utils.py @@ -136,7 +136,7 @@ def exec_sudo(cmd): proc.wait() if proc.returncode: - e = BlockDeviceSetupException("exec_sudo failed") + e = BlockDeviceSetupException("exec_sudo failed: %s" % out) e.returncode = proc.returncode e.cmd = ' '.join(sudo_cmd) e.output = out