blob: 43c961953b9f1986a68364acf3cc454df0af9e49 [file] [log] [blame]
#!/usr/bin/python -u
# -*- coding: utf-8 -*-
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''rsyncs goofy and runs on a remote device.'''
import argparse
import glob
import logging
import os
import re
import sys
import tempfile
import factory_common # pylint: disable=W0611
from cros.factory.test import factory
from cros.factory.utils.process_utils import Spawn
ssh_command = None # set in main
rsync_command = None
def SyncTestList(host, test_list, clear_factory_environment):'Checking release board on %s...', host)
release = Spawn(ssh_command + [host, 'cat /etc/lsb-release'],
check_output=True, log=True).stdout_data
match ='^CHROMEOS_RELEASE_BOARD=(.+)', release, re.MULTILINE)
if not match:
logging.warn('Unable to determine release board')
return None
board =
if test_list is None:'Copying test_list from %s overlay', board)
test_list_glob = os.path.join(
os.environ['CROS_WORKON_SRCROOT'], 'src',
'*-overlays', 'overlay-%s-*' % board,
'chromeos-base', 'autotest-private-board', 'files', 'test_list')
test_lists = glob.glob(test_list_glob)
if not test_lists:
logging.warn('Unable to find test list %s', test_list_glob)
test_list = test_lists[0]
if clear_factory_environment:
test_list_data = open(test_list).read().replace(
tmp_test_list = tempfile.NamedTemporaryFile(prefix='test_list.', bufsize=0)
test_list =
Spawn(rsync_command +
[test_list, host + ':/usr/local/factory/custom/test_list'],
check_call=True, log=True)
return board
def main():
parser = argparse.ArgumentParser(
description='Rsync and run Goofy on a remote device.')
parser.add_argument('host', metavar='HOST',
help='host to run on')
parser.add_argument('-a', dest='clear_state', action='store_true',
help='clear Goofy state and logs on device')
parser.add_argument('-e', dest='clear_factory_environment',
help='set _FACTORY_ENVIRONMENT = False in test_list')
parser.add_argument('--autotest', dest='autotest', action='store_true',
help='also rsync autotest directory')
parser.add_argument('--norestart', dest='restart', action='store_false',
help="don't restart Goofy")
parser.add_argument('--hwid', action='store_true',
help="update HWID bundle")
help=("test list to use (defaults to the one in "
"the board's overlay"))
args = parser.parse_args()
# Copy testing_rsa into a private file since otherwise ssh will ignore it
testing_rsa = tempfile.NamedTemporaryFile(prefix='testing_rsa.')
SRCROOT, 'src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa')).read())
os.fchmod(testing_rsa.fileno(), 0400)
global ssh_command, rsync_command # pylint: disable=W0603
ssh_command = ['ssh',
'-o', 'IdentityFile=%s' %,
'-o', 'UserKnownHostsFile=/dev/null',
'-o', 'User=root',
'-o', 'StrictHostKeyChecking=no']
rsync_command = ['rsync', '-e', ' '.join(ssh_command)]
Spawn(['make', '--quiet'], cwd=factory.FACTORY_PATH,
check_call=True, log=True)
board = SyncTestList(, args.test_list, args.clear_factory_environment)
if args.autotest:
Spawn(rsync_command +
['-aC', '--exclude', 'tests'] +
[os.path.join(SRCROOT, 'src/third_party/autotest/files/client/'),
'%s:/usr/local/autotest/' %],
check_call=True, log=True)
Spawn(rsync_command +
['-aC', '--exclude', '*.pyc'] +
[os.path.join(factory.FACTORY_PATH, x)
for x in ('bin', 'py', 'py_pkg', 'sh', 'test_lists', 'third_party')] +
['%s:/usr/local/factory' %],
check_call=True, log=True)
if args.hwid:
if not board:
sys.exit('Cannot update hwid without board')
chromeos_hwid_path = os.path.join(
os.path.dirname(factory.FACTORY_PATH), 'chromeos-hwid')
Spawn(['./create_bundle', board.upper()],
cwd=chromeos_hwid_path, check_call=True, log=True)
Spawn(ssh_command + [, 'bash'],
'' % board.upper())),
check_call=True, log=True)
if args.restart:
Spawn(ssh_command +
[, '/usr/local/factory/bin/restart'] +
(['-a'] if args.clear_state else []),
check_call=True, log=True)
if __name__ == '__main__':