blob: 8595163efbe7e99dd4b48ccb60af69a1594a3075 [file] [log] [blame]
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This tool can be used to set up a base container for test. For example,
python -s -p /tmp/container
This command will download and setup base container in directory /tmp/container.
After that command finishes, you can run lxc command to work with the base
container, e.g.,
lxc-start -P /tmp/container -n base -d
lxc-attach -P /tmp/container -n base
import argparse
import logging
import common
from autotest_lib.client.bin import utils
from autotest_lib.site_utils import lxc
def parse_options():
"""Parse command line inputs.
@raise argparse.ArgumentError: If command line arguments are invalid.
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--setup', action='store_true',
help='Set up base container.')
parser.add_argument('-p', '--path', type=str,
help='Directory to store the container.',
parser.add_argument('-f', '--force_delete', action='store_true',
help=('Force to delete existing containers and rebuild '
'base containers.'))
parser.add_argument('-n', '--name', type=str,
help='Name of the base container.',
options = parser.parse_args()
if not options.setup and not options.force_delete:
raise argparse.ArgumentError(
'Use --setup to setup a base container, or --force_delete to '
'delete all containers in given path.')
return options
def main():
"""main script."""
# Force to run the setup as superuser.
# TODO(dshi): 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.')'sudo true')
options = parse_options()
image = lxc.BaseImage(container_path=options.path)
if options.setup:
image.setup(, force_delete=options.force_delete)
elif options.force_delete:
if __name__ == '__main__':