[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 <[email protected]>
Reviewed-by: Simran Basi <[email protected]>
Tested-by: Richard Barnette <[email protected]>
Reviewed-by: Richard Barnette <[email protected]>
Commit-Queue: Dan Shi <[email protected]>
diff --git a/site_utils/lxc.py b/site_utils/lxc.py
index df89aff..bd62608 100644
--- a/site_utils/lxc.py
+++ b/site_utils/lxc.py
@@ -86,19 +86,12 @@
# different behavior in Moblab.
IS_MOBLAB = utils.is_moblab()
-# Flag to indicate it's running in a VM(Ganeti instance). Due to t/16003207,
-# lxc-clone does not support snapshot in Ganeti instance.
-IS_VM = utils.is_vm()
-
# TODO(dshi): If we are adding more logic in how lxc should interact with
# different systems, we should consider code refactoring to use a setting-style
# object to store following flags mapping to different systems.
# TODO(crbug.com/464834): Snapshot clone is disabled until Moblab can
# support overlayfs or aufs, which requires a newer kernel.
SUPPORT_SNAPSHOT_CLONE = not IS_MOBLAB
-# overlayfs is the default clone backend storage. However it is not supported
-# in Ganeti yet. Use aufs as the alternative.
-SNAPSHOT_CLONE_REQUIRE_AUFS = IS_VM
# Number of seconds to wait for network to be up in a container.
NETWORK_INIT_TIMEOUT = 120
@@ -662,7 +655,9 @@
use_snapshot = SUPPORT_SNAPSHOT_CLONE and not disable_snapshot_clone
snapshot = '-s' if use_snapshot else ''
- aufs = '-B aufs' if SNAPSHOT_CLONE_REQUIRE_AUFS and use_snapshot else ''
+ # overlayfs is the default clone backend storage. However it is not
+ # supported in Ganeti yet. Use aufs as the alternative.
+ aufs = '-B aufs' if utils.is_vm() and use_snapshot else ''
cmd = ('sudo lxc-clone -p %s -P %s %s' %
(self.container_path, self.container_path,
' '.join([BASE, name, snapshot, aufs])))
@@ -874,6 +869,14 @@
def main():
"""main script."""
+ # Force to run the setup as superuser.
+ # TODO(dshi): crbug.com/459344 Set remove this enforcement when test
+ # container can be unprivileged container.
+ if utils.sudo_require_password():
+ logging.warn('SSP requires root privilege to run commands, please '
+ 'grant root access to this process.')
+ utils.run('sudo true')
+
options = parse_options()
bucket = ContainerBucket(container_path=options.path)
if options.setup: