xref: /aosp_15_r20/external/autotest/site_utils/lxc/constants.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
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 the result directory in test container.
19RESULT_DIR_FMT = os.path.join(CONTAINER_AUTOTEST_DIR, 'results',
20                              '%s')
21# Attributes to retrieve about containers.
22ATTRIBUTES = ['name', 'state']
23
24# url to the folder stores base container.
25CONTAINER_BASE_FOLDER_URL = global_config.get_config_value('AUTOSERV',
26                                                    'container_base_folder_url')
27CONTAINER_BASE_URL_FMT = '%s/%%s.tar.xz' % CONTAINER_BASE_FOLDER_URL
28CONTAINER_BASE_URL = CONTAINER_BASE_URL_FMT % BASE
29# Default directory used to store LXC containers.
30DEFAULT_CONTAINER_PATH = global_config.get_config_value('AUTOSERV',
31                                                        'container_path')
32# Default directory used to store the base LXC container.
33DEFAULT_BASE_CONTAINER_PATH = global_config.get_config_value(
34        'AUTOSERV', 'base_container_path')
35# Default directory for host mounts
36DEFAULT_SHARED_HOST_PATH = global_config.get_config_value(
37        'AUTOSERV',
38        'container_shared_host_path')
39
40# The name of the linux domain socket used by the container pool.  Just one
41# exists, so this is just a hard-coded string.
42DEFAULT_CONTAINER_POOL_SOCKET = 'container_pool_socket'
43
44# Default size for the lxc container pool.
45DEFAULT_CONTAINER_POOL_SIZE = 20
46
47# Location of the host mount point in the container.
48CONTAINER_HOST_DIR = '/host'
49
50# Path to drone_temp folder in the container, which stores the control file for
51# test job to run.
52CONTROL_TEMP_PATH = os.path.join(CONTAINER_AUTOTEST_DIR, 'drone_tmp')
53
54# Bash command to return the file count in a directory. Test the existence first
55# so the command can return an error code if the directory doesn't exist.
56COUNT_FILE_CMD = '[ -d %(dir)s ] && ls %(dir)s | wc -l'
57
58# Seconds to wait for successful completion of a lxc force-destroy
59LXC_SCRUB_TIMEOUT = 300
60
61# Command line to append content to a file
62APPEND_CMD_FMT = ('echo \'%(content)s\' | sudo tee --append %(file)s'
63                  '> /dev/null')
64
65# Flag to indicate it's running in a Moblab. Due to crbug.com/457496, lxc-ls has
66# different behavior in Moblab.
67IS_MOBLAB = common_utils.is_moblab()
68
69if IS_MOBLAB:
70    SITE_PACKAGES_PATH = '/usr/lib64/python2.7/site-packages'
71    CONTAINER_SITE_PACKAGES_PATH = '/usr/local/lib/python2.7/dist-packages/'
72else:
73    SITE_PACKAGES_PATH = os.path.join(common.autotest_dir, 'site-packages')
74    CONTAINER_SITE_PACKAGES_PATH = os.path.join(CONTAINER_AUTOTEST_DIR,
75                                                'site-packages')
76
77# This is an alternate site_packages that is built to be Trusty
78# compatible.  crbug.com/1013241
79TRUSTY_SITE_PACKAGES_PATH = '/opt/trusty_site_packages'
80
81# TODO(dshi): If we are adding more logic in how lxc should interact with
82# different systems, we should consider code refactoring to use a setting-style
83# object to store following flags mapping to different systems.
84SUPPORT_SNAPSHOT_CLONE = True
85
86# Number of seconds to wait for network to be up in a container.
87NETWORK_INIT_TIMEOUT = 1200
88# Network bring up is slower in Moblab.
89# TODO(184304822) reset back to 0.1 for the main lab.
90NETWORK_INIT_CHECK_INTERVAL = 1 if IS_MOBLAB else 5
91
92# Number of seconds to download files from devserver. We chose a timeout that
93# is on the same order as the permitted CTS runtime for normal jobs (1h). In
94# principle we should not retry timeouts as they indicate server/network
95# overload, but we may be tempted to retry for other failures.
96DEVSERVER_CALL_TIMEOUT = 3600
97# Number of retries to download files from devserver. There is no point in
98# having more than one retry for a file download.
99DEVSERVER_CALL_RETRY = 2
100# Average delay before attempting a retry to download from devserver. This
101# value needs to be large enough to allow an overloaded server/network to
102# calm down even in the face of retries.
103DEVSERVER_CALL_DELAY = 600
104
105# Type string for container related metadata.
106CONTAINER_CREATE_METADB_TYPE = 'container_create'
107CONTAINER_CREATE_RETRY_METADB_TYPE = 'container_create_retry'
108CONTAINER_RUN_TEST_METADB_TYPE = 'container_run_test'
109
110# The container's hostname MUST start with `test-` or `test_`. DHCP server in
111# MobLab uses that prefix to determine the lease time.  Note that `test_` is not
112# a valid hostname as hostnames cannot contain underscores.  Work is underway to
113# migrate to `test-`.  See crbug/726131.
114CONTAINER_UTSNAME_FORMAT = 'test-%s'
115
116STATS_KEY = 'chromeos/autotest/lxc'
117
118CONTAINER_POOL_METRICS_PREFIX = 'chromeos/autotest/container_pool'
119