remote_test.py revision f2a3ef46f75d2196a93d3ed27f4d1fcf22b54fbe
1#!/usr/bin/python
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4"""Script to wrap test_that script.
5
6This script can login to the chromeos machine using the test private key.
7"""
8
9__author__ = 'asharif@google.com (Ahmad Sharif)'
10
11import optparse
12import os
13import re
14import sys
15
16from utils import command_executer
17from utils import misc
18
19
20def Usage(parser, message):
21  print 'ERROR: ' + message
22  parser.print_help()
23  sys.exit(0)
24
25
26def Main(argv):
27  parser = optparse.OptionParser()
28  parser.add_option('-c',
29                    '--chromeos_root',
30                    dest='chromeos_root',
31                    help='ChromeOS root checkout directory')
32  parser.add_option('-r',
33                    '--remote',
34                    dest='remote',
35                    help='Remote chromeos device.')
36  options = parser.parse_args(argv)[0]
37  if options.chromeos_root is None:
38    Usage(parser, 'chromeos_root must be given')
39
40  if options.remote is None:
41    Usage(parser, 'remote must be given')
42
43  options.chromeos_root = os.path.expanduser(options.chromeos_root)
44
45  command = 'ls -lt /'
46  ce = command_executer.GetCommandExecuter()
47  ce.CrosRunCommand(command,
48                    chromeos_root=options.chromeos_root,
49                    machine=options.remote)
50
51  version_dir_path, script_name = misc.GetRoot(sys.argv[0])
52  version_dir = misc.GetRoot(version_dir_path)[1]
53
54  # Tests to copy directories and files to the chromeos box.
55  ce.CopyFiles(version_dir_path,
56               '/tmp/' + version_dir,
57               dest_machine=options.remote,
58               dest_cros=True,
59               chromeos_root=options.chromeos_root)
60  ce.CopyFiles(version_dir_path,
61               '/tmp/' + version_dir + '1',
62               dest_machine=options.remote,
63               dest_cros=True,
64               chromeos_root=options.chromeos_root)
65  ce.CopyFiles(sys.argv[0],
66               '/tmp/' + script_name,
67               recursive=False,
68               dest_machine=options.remote,
69               dest_cros=True,
70               chromeos_root=options.chromeos_root)
71  ce.CopyFiles(sys.argv[0],
72               '/tmp/' + script_name + '1',
73               recursive=False,
74               dest_machine=options.remote,
75               dest_cros=True,
76               chromeos_root=options.chromeos_root)
77
78  # Test to copy directories and files from the chromeos box.
79  ce.CopyFiles('/tmp/' + script_name,
80               '/tmp/hello',
81               recursive=False,
82               src_machine=options.remote,
83               src_cros=True,
84               chromeos_root=options.chromeos_root)
85  ce.CopyFiles('/tmp/' + script_name,
86               '/tmp/' + script_name,
87               recursive=False,
88               src_machine=options.remote,
89               src_cros=True,
90               chromeos_root=options.chromeos_root)
91  board = ce.CrosLearnBoard(options.chromeos_root, options.remote)
92  print board
93  return 0
94
95
96if __name__ == '__main__':
97  Main(sys.argv)
98