[autotest] Add sudo -n option to avoid password prompt.
Also add a utility function to check if password is needed to run sudo command.
We can add -n option to all sudo command that SSP used. However, once the
property drone.support_ssp is set to False, no SSP code will be executed.
Therefore, there is no need to add -n everywhere.
BUG=chromium:484396
TEST=local run
Start scheduler, confirm no password promt, and drone.support_ssp is False.
Run sudo true, enter password.
Run scheduler again, confirm no password promt, and drone.support_ssp is True.
Change-Id: Ifbd302973db5d443499311e435ec99e32d24cb5b
Reviewed-on: https://chromium-review.googlesource.com/269740
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/client/common_lib/site_utils.py b/client/common_lib/site_utils.py
index 09932cd..3be5d4e 100644
--- a/client/common_lib/site_utils.py
+++ b/client/common_lib/site_utils.py
@@ -528,3 +528,17 @@
if not user:
user = os.environ.get('USER')
return user
+
+
+def sudo_require_password():
+ """Test if the process can run sudo command without using password.
+
+ @return: True if the process needs password to run sudo command.
+
+ """
+ try:
+ base_utils.run('sudo -n true')
+ return False
+ except error.CmdError:
+ logging.warn('sudo command requires password.')
+ return True