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