cros_sdk: make --debug more useful

We currently swallow a lot of internal and kind of significant commands
even when run with --debug turned on.  Change all of those run commands
from print_cmd=False to debug_level=logging.DEBUG.  Anyone who runs the
cros_sdk command with --debug most likely wants to see all of these.

BUG=b:149182563
TEST=CQ passes

Change-Id: I8c3771d6906f89daf7382204daf555f9268240cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2057547
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 2065b5b..0e0fb71 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -200,7 +200,7 @@
 
   logging.notice('Creating chroot. This may take a few minutes...')
   try:
-    cros_build_lib.run(cmd, print_cmd=False)
+    cros_build_lib.dbg_run(cmd)
   except cros_build_lib.RunCommandError:
     raise SystemExit('Running %r failed!' % cmd)
 
@@ -210,7 +210,7 @@
   cmd = MAKE_CHROOT + ['--chroot', chroot_path, '--delete']
   try:
     logging.notice('Deleting chroot.')
-    cros_build_lib.run(cmd, print_cmd=False)
+    cros_build_lib.dbg_run(cmd)
   except cros_build_lib.RunCommandError:
     raise SystemExit('Running %r failed!' % cmd)
 
@@ -246,8 +246,7 @@
 
   # ThinLTO opens lots of files at the same time.
   resource.setrlimit(resource.RLIMIT_NOFILE, (32768, 32768))
-  ret = cros_build_lib.run(
-      cmd, print_cmd=False, check=False, mute_output=False)
+  ret = cros_build_lib.dbg_run(cmd, check=False, mute_output=False)
   # If we were in interactive mode, ignore the exit code; it'll be whatever
   # they last ran w/in the chroot and won't matter to us one way or another.
   # Note this does allow chroot entrance to fail and be ignored during
@@ -300,7 +299,7 @@
   try:
     logging.notice('Creating snapshot %s from %s in VG %s.', snapshot_name,
                    chroot_lv, chroot_vg)
-    cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+    cros_build_lib.dbg_run(cmd, capture_output=True)
     return True
   except cros_build_lib.RunCommandError:
     raise SystemExit('Running %r failed!' % cmd)
@@ -333,7 +332,7 @@
   cmd = ['lvremove', '-f', '%s/%s' % (chroot_vg, snapshot_name)]
   try:
     logging.notice('Deleting snapshot %s in VG %s.', snapshot_name, chroot_vg)
-    cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+    cros_build_lib.dbg_run(cmd, capture_output=True)
   except cros_build_lib.RunCommandError:
     raise SystemExit('Running %r failed!' % cmd)
 
@@ -373,17 +372,17 @@
   backup_chroot_name = 'chroot-bak-%d' % random.randint(0, 1000)
   cmd = ['lvrename', chroot_vg, chroot_lv, backup_chroot_name]
   try:
-    cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+    cros_build_lib.dbg_run(cmd, capture_output=True)
   except cros_build_lib.RunCommandError:
     raise SystemExit('Running %r failed!' % cmd)
 
   cmd = ['lvrename', chroot_vg, snapshot_name, chroot_lv]
   try:
-    cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+    cros_build_lib.dbg_run(cmd, capture_output=True)
   except cros_build_lib.RunCommandError:
     cmd = ['lvrename', chroot_vg, backup_chroot_name, chroot_lv]
     try:
-      cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+      cros_build_lib.dbg_run(cmd, capture_output=True)
     except cros_build_lib.RunCommandError:
       raise SystemExit('Failed to rename %s to chroot and failed to restore '
                        '%s back to chroot.  Failed command: %r' %
@@ -405,11 +404,11 @@
   # that is already active shouldn't do anything, so this is safe to run even if
   # the -kn wasn't needed.
   cmd = ['lvchange', '-ay', chroot_lv_path]
-  cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+  cros_build_lib.dbg_run(cmd, capture_output=True)
 
   cmd = ['lvremove', '-f', '%s/%s' % (chroot_vg, backup_chroot_name)]
   try:
-    cros_build_lib.run(cmd, print_cmd=False, capture_output=True)
+    cros_build_lib.dbg_run(cmd, capture_output=True)
   except cros_build_lib.RunCommandError:
     raise SystemExit('Failed to remove backup LV %s/%s.  Failed command: %r' %
                      (chroot_vg, backup_chroot_name, cmd))
@@ -587,7 +586,7 @@
     )
     try:
       for cmd in commands:
-        cros_build_lib.run(cmd, print_cmd=False)
+        cros_build_lib.dbg_run(cmd)
     except cros_build_lib.RunCommandError:
       raise SystemExit('Running %r failed!' % (cmd,))
 
@@ -646,7 +645,7 @@
   cmd = None  # Make cros lint happy.
   try:
     for cmd in commands:
-      cros_build_lib.run(cmd, print_cmd=False)
+      cros_build_lib.dbg_run(cmd)
   except cros_build_lib.RunCommandError:
     # Clean up existing interfaces, if any.
     cmd_cleanup = ('ip', 'link', 'del', veth_host)
@@ -671,6 +670,7 @@
   """
   if os.geteuid() != 0:
     cmd = _SudoCommand() + ['--'] + argv
+    logging.debug('Reexecing self via sudo:\n%s', cros_build_lib.CmdToStr(cmd))
     os.execvp(cmd[0], cmd)
   else:
     # We must set up the cgroups mounts before we enter our own namespace.
@@ -1071,7 +1071,7 @@
                      'fstrim.', img_path, extra_gbs)
       cmd = ['fstrim', options.chroot]
       try:
-        cros_build_lib.run(cmd, print_cmd=False)
+        cros_build_lib.dbg_run(cmd)
       except cros_build_lib.RunCommandError as e:
         logging.warning(
             'Running fstrim failed. Consider running fstrim on '