1# Copyright 2020 The Chromium OS 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# repohooks/pre-upload.py currently does not run pylint. But for developers who 6# want to check their code manually we disable several harmless pylint warnings 7# which just distract from more serious remaining issues. 8# 9# The instance variable _android_gts is not defined in __init__(). 10# pylint: disable=attribute-defined-outside-init 11# 12# Many short variable names don't follow the naming convention. 13# pylint: disable=invalid-name 14 15import logging 16import os 17import shutil 18import tempfile 19 20from autotest_lib.server import utils 21from autotest_lib.server.cros.tradefed import tradefed_test 22 23# Maximum default time allowed for each individual GTS module. 24_GTS_TIMEOUT_SECONDS = 3600 25# TODO: fix it when we prepare the public control files. 26_PARTNER_GTS_BUCKET = 'gs://chromeos-partner-gts/' 27_PARTNER_GTS_LOCATION = _PARTNER_GTS_BUCKET + 'gts-8-R2-R-6955212.zip' 28_PARTNER_GTS_AUTHKEY = _PARTNER_GTS_BUCKET + 'gts-arc.json' 29_GTS_MEDIA_URI = ('https://storage.googleapis.com/youtube-test-media/gts/' + 30 'GtsYouTubeTestCases-media-1.2.zip') 31_GTS_MEDIA_LOCALPATH = '/tmp/android-gts-media/GtsYouTubeTestCases' 32 33# Internal uprev for all GTS modules. 34_GTS_LATEST_URI = 'gs://chromeos-arc-images/cts/bundle/android-gts-8-R3-R-Preview3-7012566.zip' 35 36 37class cheets_GTS_R(tradefed_test.TradefedTest): 38 """Sets up tradefed to run GTS tests.""" 39 version = 1 40 41 _SHARD_CMD = '--shard-count' 42 43 def _tradefed_retry_command(self, template, session_id): 44 """Build tradefed 'retry' command from template.""" 45 cmd = [] 46 for arg in template: 47 cmd.append(arg.format(session_id=session_id)) 48 return cmd 49 50 def _tradefed_run_command(self, template): 51 """Build tradefed 'run' command from template.""" 52 cmd = template[:] 53 # If we are running outside of the lab we can collect more data. 54 if not utils.is_in_container(): 55 logging.info('Running outside of lab, adding extra debug options.') 56 cmd.append('--log-level-display=DEBUG') 57 58 return cmd 59 60 def _get_default_bundle_url(self, bundle): 61 return _PARTNER_GTS_LOCATION 62 63 def _get_latest_bundle_url(self, bundle): 64 return _GTS_LATEST_URI 65 66 def _get_default_authkey(self): 67 return _PARTNER_GTS_AUTHKEY 68 69 def _get_tradefed_base_dir(self): 70 return 'android-gts' 71 72 def _tradefed_cmd_path(self): 73 return os.path.join(self._repository, 'tools', 'gts-tradefed') 74 75 def _tradefed_env(self): 76 if self._authkey: 77 return dict(os.environ, APE_API_KEY=self._authkey) 78 return None 79 80 def run_once(self, 81 test_name, 82 run_template, 83 retry_template=None, 84 target_module=None, 85 target_plan=None, 86 needs_push_media=False, 87 enable_default_apps=False, 88 precondition_commands=[], 89 login_precondition_commands=[], 90 authkey=None, 91 prerequisites=[], 92 timeout=_GTS_TIMEOUT_SECONDS): 93 """Runs the specified GTS once, but with several retries. 94 95 Run an arbitrary tradefed command. 96 97 @param test_name: the name of test. Used for logging. 98 @param run_template: the template to construct the run command. 99 Example: ['run', 'commandAndExit', 'cts', 100 '--skip-media-download'] 101 @param retry_template: the template to construct the retry command. 102 Example: ['run', 'commandAndExit', 'retry', 103 '--skip-media-download', '--retry', 104 '{session_id}'] 105 @param target_module: the name of test module to run. 106 @param target_plan: the name of the test plan to run. 107 @param needs_push_media: need to push test media streams. 108 @param timeout: time after which tradefed can be interrupted. 109 @param precondition_commands: a list of scripts to be run on the 110 dut before the test is run, the scripts must already be installed. 111 @param login_precondition_commands: a list of scripts to be run on the 112 dut before the log-in for the test is performed. 113 @param prerequisites: a list of prerequisites that identify rogue DUTs. 114 """ 115 # Download the GTS auth key to the local temp directory. 116 tmpdir = tempfile.mkdtemp() 117 try: 118 self._authkey = self._download_to_dir( 119 authkey or self._get_default_authkey(), tmpdir) 120 121 self._run_tradefed_with_retries( 122 test_name=test_name, 123 run_template=run_template, 124 retry_template=retry_template, 125 timeout=timeout, 126 target_module=target_module, 127 target_plan=target_plan, 128 media_asset=tradefed_test.MediaAsset( 129 _GTS_MEDIA_URI if needs_push_media else None, 130 _GTS_MEDIA_LOCALPATH), 131 enable_default_apps=enable_default_apps, 132 login_precondition_commands=login_precondition_commands, 133 precondition_commands=precondition_commands, 134 prerequisites=prerequisites) 135 finally: 136 shutil.rmtree(tmpdir) 137