1# Copyright 2015 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6 7import common 8from autotest_lib.client.bin import utils as common_utils 9from autotest_lib.client.common_lib.global_config import global_config 10 11 12# Name of the base container. 13BASE = global_config.get_config_value('AUTOSERV', 'container_base_name') 14 15# Path to folder that contains autotest code inside container. 16CONTAINER_AUTOTEST_DIR = '/usr/local/autotest' 17 18# Naming convention of test container, e.g., test_300_1422862512_2424, where: 19# 300: The test job ID. 20# 1422862512: The tick when container is created. 21# 2424: The PID of autoserv that starts the container. 22TEST_CONTAINER_NAME_FMT = 'test_%s_%d_%d' 23# Naming convention of the result directory in test container. 24RESULT_DIR_FMT = os.path.join(CONTAINER_AUTOTEST_DIR, 'results', 25 '%s') 26# Attributes to retrieve about containers. 27ATTRIBUTES = ['name', 'state'] 28 29# Format for mount entry to share a directory in host with container. 30# source is the directory in host, destination is the directory in container. 31# readonly is a binding flag for readonly mount, its value should be `,ro`. 32MOUNT_FMT = ('lxc.mount.entry = %(source)s %(destination)s none ' 33 'bind%(readonly)s 0 0') 34SSP_ENABLED = global_config.get_config_value('AUTOSERV', 'enable_ssp_container', 35 type=bool, default=True) 36# url to the folder stores base container. 37CONTAINER_BASE_FOLDER_URL = global_config.get_config_value('AUTOSERV', 38 'container_base_folder_url') 39CONTAINER_BASE_URL_FMT = '%s/%%s.tar.xz' % CONTAINER_BASE_FOLDER_URL 40CONTAINER_BASE_URL = CONTAINER_BASE_URL_FMT % BASE 41# Default directory used to store LXC containers. 42DEFAULT_CONTAINER_PATH = global_config.get_config_value('AUTOSERV', 43 'container_path') 44# Default directory for host mounts 45DEFAULT_SHARED_HOST_PATH = global_config.get_config_value( 46 'AUTOSERV', 47 'container_shared_host_path') 48 49# Path to drone_temp folder in the container, which stores the control file for 50# test job to run. 51CONTROL_TEMP_PATH = os.path.join(CONTAINER_AUTOTEST_DIR, 'drone_tmp') 52 53# Bash command to return the file count in a directory. Test the existence first 54# so the command can return an error code if the directory doesn't exist. 55COUNT_FILE_CMD = '[ -d %(dir)s ] && ls %(dir)s | wc -l' 56 57# Command line to append content to a file 58APPEND_CMD_FMT = ('echo \'%(content)s\' | sudo tee --append %(file)s' 59 '> /dev/null') 60 61# Flag to indicate it's running in a Moblab. Due to crbug.com/457496, lxc-ls has 62# different behavior in Moblab. 63IS_MOBLAB = common_utils.is_moblab() 64 65if IS_MOBLAB: 66 SITE_PACKAGES_PATH = '/usr/lib64/python2.7/site-packages' 67 CONTAINER_SITE_PACKAGES_PATH = '/usr/local/lib/python2.7/dist-packages/' 68else: 69 SITE_PACKAGES_PATH = os.path.join(common.autotest_dir, 'site-packages') 70 CONTAINER_SITE_PACKAGES_PATH = os.path.join(CONTAINER_AUTOTEST_DIR, 71 'site-packages') 72 73# TODO(dshi): If we are adding more logic in how lxc should interact with 74# different systems, we should consider code refactoring to use a setting-style 75# object to store following flags mapping to different systems. 76# TODO(crbug.com/464834): Snapshot clone is disabled until Moblab can 77# support overlayfs or aufs, which requires a newer kernel. 78SUPPORT_SNAPSHOT_CLONE = not IS_MOBLAB 79 80# Number of seconds to wait for network to be up in a container. 81NETWORK_INIT_TIMEOUT = 300 82# Network bring up is slower in Moblab. 83NETWORK_INIT_CHECK_INTERVAL = 2 if IS_MOBLAB else 0.1 84 85# Number of seconds to download files from devserver. We chose a timeout that 86# is on the same order as the permitted CTS runtime for normal jobs (1h). In 87# principle we should not retry timeouts as they indicate server/network 88# overload, but we may be tempted to retry for other failures. 89DEVSERVER_CALL_TIMEOUT = 3600 90# Number of retries to download files from devserver. There is no point in 91# having more than one retry for a file download. 92DEVSERVER_CALL_RETRY = 2 93# Average delay before attempting a retry to download from devserver. This 94# value needs to be large enough to allow an overloaded server/network to 95# calm down even in the face of retries. 96DEVSERVER_CALL_DELAY = 600 97 98# Type string for container related metadata. 99CONTAINER_CREATE_METADB_TYPE = 'container_create' 100CONTAINER_CREATE_RETRY_METADB_TYPE = 'container_create_retry' 101CONTAINER_RUN_TEST_METADB_TYPE = 'container_run_test' 102 103# The container's hostname MUST start with `test-` or `test_`. DHCP server in 104# MobLab uses that prefix to determine the lease time. Note that `test_` is not 105# a valid hostname as hostnames cannot contain underscores. Work is underway to 106# migrate to `test-`. See crbug/726131. 107CONTAINER_UTSNAME_FORMAT = 'test-%s' 108 109STATS_KEY = 'chromeos/autotest/lxc' 110