Home | History | Annotate | Download | only in site_utils

Lines Matching defs:Container

6   1. Download base container from given GS location, setup the base container.
7 2. Create a snapshot as test container from base container.
8 3. Mount a directory in drone to the test container.
9 4. Run a command in the container and return the output.
10 5. Cleanup, e.g., destroy the container.
12 This tool can also be used to set up a base container for test. For example,
13 python lxc.py -s -p /tmp/container
14 This command will download and setup base container in directory /tmp/container.
16 container, e.g.,
17 lxc-start -P /tmp/container -n base -d
18 lxc-attach -P /tmp/container -n base
44 # Name of the base container.
46 # Naming convention of test container, e.g., test_300_1422862512_2424, where:
48 # 1422862512: The tick when container is created.
49 # 2424: The PID of autoserv that starts the container.
51 # Naming convention of the result directory in test container.
57 # Format for mount entry to share a directory in host with container.
58 # source is the directory in host, destination is the directory in container.
64 # url to the base container.
69 # Path to drone_temp folder in the container, which stores the control file for
96 # Number of seconds to wait for network to be up in a container.
101 # Type string for container related metadata.
108 # Timer used inside container should not include the hostname, as that will
109 # create individual timer for each container.
114 """Get a collection of container information in the given container path
123 lxc container directory.
125 container is located.
135 a container. The keys are defined in ATTRIBUTES.
142 raise error.ContainerError('When running in Moblab, container list '
163 """Get a collection of container information in the given container path.
165 This method parse the output of lxc-ls to get a list of container
176 a container. The keys are defined in ATTRIBUTES.
199 """Decorator to do cleanup if container fails to be set up.
207 """Decorator to do cleanup if container fails to be set up.
210 used to retrieve the container object by name.
228 container = bucket.get(name)
229 if container and not skip_cleanup:
230 container.destroy()
300 """Install the given package inside container.
307 a container.
316 'when test is running inside container.')
317 # Always run apt-get update before installing any container. The base
318 # container may have outdated cache.
344 """Install the given package inside container.
352 a container.
364 """Install the given python package inside container using pip.
378 class Container(object):
379 """A wrapper class of an LXC container.
381 The wrapper class provides methods to interact with a container, e.g.,
383 container, including:
384 name: Name of the container.
385 state: State of the container, e.g., ABORTING, RUNNING, STARTING, STOPPED,
388 lxc-ls can also collect other attributes of a container including:
391 autostart: If the container will autostart at system boot.
392 pid: Process ID of the container.
393 memory: Memory used by the container, as a string, e.g., "6.2MB"
394 ram: Physical ram used by the container
395 swap: swap used by the container, as a string, e.g., "1.0MB"
403 """Initialize an object of LXC container with given attribute values.
405 @param container_path: Directory that stores the container.
407 container.
410 # Path to the rootfs of the container. This will be initialized when
418 """Refresh the status information of the container.
423 'No container found in directory %s with name of %s.' %
432 """Path to the rootfs of the container.
434 This property returns the path to the rootfs of the container, that is,
435 the folder where the container stores its local files. It reads the
436 attribute lxc.rootfs from the config file of the container, e.g.,
438 If the container is created with snapshot, the rootfs is a chain of
446 Files in the rootfs will be accessible directly within container. For
448 inside container by path "/usr/local/file1". Note that symlink in the
449 host can not across host/container boundary, instead, directory mount
452 @return: Path to the rootfs of the container.
461 'Failed to locate rootfs for container %s. lxc.rootfs '
462 'in the container config file is %s' %
474 """Attach to a given container and run the given command.
476 @param command: Command to run in the container.
482 @raise error.CmdError: If container does not exist, or not running.
489 # container can be unprivileged container.
494 """Check if network is up in the container by curl base container url.
508 """Start the container.
513 @raise ContainerError: If container does not exist, or fails to start.
520 'Container %s failed to start. lxc command output:\n%s' %
536 """Stop the container.
538 @raise ContainerError: If container does not exist, or fails to start.
545 'Container %s failed to be stopped. lxc command output:\n'
552 """Destroy the container.
554 @param force: Set to True to force to destroy the container even if it's
555 running. This is faster than stop a container first then
558 @raise ContainerError: If container does not exist or failed to destroy
559 the container.
569 """Mount a directory in host to a directory in the container.
572 @param destination: Directory in container to mount the source directory
575 # Destination path in container must be relative.
577 # Create directory in container for mount.
587 """Verify autotest code is set up properly in the container.
618 container: /usr/local/lib/python2.7/dist-packages/. The modules include
622 When pip is installed inside the container, it installs requests module
645 """A wrapper class to interact with containers in a specific container path.
662 indexed by container name.
667 container = Container(self.container_path, info)
668 containers[container.name] = container
673 """Get a container with matching name.
675 @param name: Name of the container.
677 @return: A container object with matching name. Returns None if no
678 container matches the given name.
684 """Check if a container exists with the given name.
686 @param name: Name of the container.
688 @return: True if the container with the given name exists, otherwise
698 for container in sorted(containers,
700 logging.info('Destroy container %s.', container.name)
701 container.destroy()
707 """Create a container from the base container.
709 @param name: Name of the container.
712 @param force_cleanup: Force to cleanup existing container.
714 @return: A Container object for the created container.
716 @raise ContainerError: If the container already exist.
720 raise error.ContainerError('Container %s already exists.' % name)
722 # Cleanup existing container with the given name.
725 container = Container(self.container_path, {'name': name})
727 container.destroy()
729 # The container could be created in a incompleted state. Delete
730 # the container folder instead.
731 logging.warn('Failed to destroy container %s, error: %s',
753 container = self.create_from_base(
761 return container
766 """Setup base container.
768 @param name: Name of the base container, default to base.
769 @param force_delete: True to force to delete existing base container.
784 'Base container already exists. Set force_delete to True '
785 'to force to re-stage base container. Note that this '
787 # Set proper file permission. base container in moblab may have
789 # TODO(dshi): Change root to current user when test container can be
790 # unprivileged container.
795 # Destroy existing base container if exists.
798 # container, not all container.
801 # Download and untar the base container.
808 # Remove the downloaded container tar file.
811 # TODO(dshi): Change root to current user when test container can be
812 # unprivileged container.
816 # Update container config with container_path from global config.
826 """Setup test container for the test job to run.
835 to run in container.
837 @param name: Name of the container.
838 @param job_id: Job id for the test job to run in the test container.
840 @param result_path: Directory to be mounted to container to store test
845 container failures.
847 @return: A Container object for the test container.
849 @raise ContainerError: If container does not exist, or not running.
858 # Create test container from the base container.
859 container = self.create_from_base(name)
862 usr_local_path = os.path.join(container.rootfs, 'usr', 'local')
870 deploy_config_manager = lxc_config.DeployConfigManager(container)
899 # Update container config to mount directories.
901 container.mount_dir(source, destination, readonly)
904 # TODO(dshi): crbug.com/459344 Skip following action when test container
905 # can be unprivileged container.
909 container.start(name)
912 container.modify_import_order()
914 container.verify_autotest_setup(job_id)
923 logging.debug('Test container %s is set up.', name)
924 return container
935 help='Set up base container.')
937 help='Directory to store the container.',
946 'Use --setup to setup a base container, or --force_delete to '
955 # container can be unprivileged container.