]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
kill: Check if sudo works before using it 1703/head
authorZack Cerza <zack@redhat.com>
Wed, 12 Jan 2022 19:21:27 +0000 (12:21 -0700)
committerZack Cerza <zack@redhat.com>
Wed, 16 Mar 2022 20:49:20 +0000 (14:49 -0600)
Also, use sudo's -n flag to avoid the password prompt and resulting
delay.

Fixes: https://tracker.ceph.com/issues/53853
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/kill.py

index 213600f0ff017ec8b102726ea122882336e697a7..5af11b628c95b174e76548ddcef42fae754109db 100755 (executable)
@@ -179,12 +179,18 @@ def kill_processes(run_name, pids=None):
         log.info("No teuthology processes running")
     else:
         log.info("Killing Pids: " + str(to_kill))
+        may_need_sudo = \
+            psutil.Process(int(pid)).username() != getpass.getuser()
+        if may_need_sudo:
+            sudo_works = subprocess.Popen(['sudo', '-n', 'true']).wait() == 0
+            if not sudo_works:
+                log.debug("Passwordless sudo not configured; not using sudo")
+        use_sudo = may_need_sudo and sudo_works
         for pid in to_kill:
             args = ['kill', str(pid)]
             # Don't attempt to use sudo if it's not necessary
-            proc_user = psutil.Process(int(pid)).username()
-            if proc_user != getpass.getuser():
-                args.insert(0, 'sudo')
+            if use_sudo:
+                args = ['sudo', '-n'] + args
             subprocess.call(args)