OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Utility script to launch browser-tests on the Chromoting bot.""" | 6 """Utility script to launch browser-tests on the Chromoting bot.""" |
7 import argparse | 7 import argparse |
| 8 import glob |
8 import hashlib | 9 import hashlib |
9 import os | 10 import os |
10 from os.path import expanduser | 11 from os.path import expanduser |
11 import shutil | 12 import shutil |
12 import socket | 13 import socket |
13 import subprocess | 14 import subprocess |
14 | 15 |
15 BROWSER_TEST_ID = 'browser_tests' | 16 BROWSER_TEST_ID = 'browser_tests' |
16 PROD_DIR_ID = '#PROD_DIR#' | 17 PROD_DIR_ID = '#PROD_DIR#' |
17 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest() | 18 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest() |
18 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.' | 19 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.' |
19 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts' | 20 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts' |
20 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names | 21 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names |
| 22 CHROMOTING_HOST_PATH = '/opt/google/chrome-remote-desktop/chrome-remote-desktop' |
21 | 23 |
22 | 24 |
23 def LaunchCommand(command): | 25 def LaunchBTCommand(command): |
| 26 results, error = RunCommandInSubProcess(command) |
| 27 |
| 28 # Check that the test passed. |
| 29 if SUCCESS_INDICATOR not in results: |
| 30 # Obtain contents of Chromoting host logs. |
| 31 log_contents = '' |
| 32 # There should be only 1 log file, as we delete logs on test completion. |
| 33 # Loop through matching files, just in case there are more. |
| 34 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'): |
| 35 with open(log_file, 'r') as log: |
| 36 log_contents += '\nHOST LOG %s CONTENTS:\n%s' % (log_file, log.read()) |
| 37 print log_contents |
| 38 raise Exception( |
| 39 'Test failed. Command:%s\nResults:%s\nError:%s\n' % |
| 40 (command, results, error)) |
| 41 |
| 42 |
| 43 def RunCommandInSubProcess(command): |
| 44 """Creates a subprocess with command-line that is passed in. |
| 45 |
| 46 Args: |
| 47 command: The text of command to be executed. |
| 48 Returns: |
| 49 results: stdout contents of executing the command. |
| 50 error: stderr contents. |
| 51 """ |
| 52 |
24 cmd_line = [command] | 53 cmd_line = [command] |
25 try: | 54 try: |
26 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) | 55 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) |
27 results, err = p.communicate() | 56 results, error = p.communicate() |
28 # Check that the test passed. | |
29 if SUCCESS_INDICATOR not in results: | |
30 raise Exception( | |
31 'Test failed. Command:%s\nResults:%s\nError:%s\n' % | |
32 (command, results, err)) | |
33 except subprocess.CalledProcessError, e: | 57 except subprocess.CalledProcessError, e: |
34 raise Exception('Exception %s running command %s' % (e, command)) | 58 raise Exception('Exception %s running command %s\nError: %s' % |
| 59 (e, command, error)) |
35 else: | 60 else: |
36 print results | 61 print results |
| 62 return results, error |
| 63 |
| 64 |
| 65 def TestCleanUp(user_profile_dir): |
| 66 """Cleans up test machine so as not to impact other tests. |
| 67 |
| 68 Args: |
| 69 user_profile_dir: the user-profile folder used by Chromoting tests. |
| 70 |
| 71 """ |
| 72 # Stop the host service. |
| 73 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') |
| 74 |
| 75 # Cleanup any host logs. |
| 76 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') |
| 77 |
| 78 # Remove the user-profile dir |
| 79 if os.path.exists(user_profile_dir): |
| 80 shutil.rmtree(user_profile_dir) |
37 | 81 |
38 | 82 |
39 def InitialiseTestMachineForLinux(cfg_file, manifest_file, user_profile_dir): | 83 def InitialiseTestMachineForLinux(cfg_file, manifest_file, user_profile_dir): |
40 """Sets up a Linux machine for connect-to-host browser-tests. | 84 """Sets up a Linux machine for connect-to-host browser-tests. |
41 | 85 |
42 Copy over me2me host-config and manifest files to expected locations. | 86 Copy over me2me host-config and manifest files to expected locations. |
43 By default, the Linux me2me host expects the host-config file to be under | 87 By default, the Linux me2me host expects the host-config file to be under |
44 $HOME/.config/chrome-remote-desktop | 88 $HOME/.config/chrome-remote-desktop |
45 Its name is expected to have a hash that is specific to a machine. | 89 Its name is expected to have a hash that is specific to a machine. |
46 | 90 |
(...skipping 27 matching lines...) Expand all Loading... |
74 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE | 118 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE |
75 config_file_src = os.path.join(os.getcwd(), cfg_file) | 119 config_file_src = os.path.join(os.getcwd(), cfg_file) |
76 shutil.copyfile( | 120 shutil.copyfile( |
77 config_file_src, | 121 config_file_src, |
78 os.path.join(default_config_file_location, default_config_file_name)) | 122 os.path.join(default_config_file_location, default_config_file_name)) |
79 | 123 |
80 # Next, create a user-profile dir, and place the me2me manifest.json file in | 124 # Next, create a user-profile dir, and place the me2me manifest.json file in |
81 # the expected location for native-messating-host to work properly. | 125 # the expected location for native-messating-host to work properly. |
82 native_messaging_folder = os.path.join(user_profile_dir, NATIVE_MESSAGING_DIR) | 126 native_messaging_folder = os.path.join(user_profile_dir, NATIVE_MESSAGING_DIR) |
83 | 127 |
84 if os.path.exists(native_messaging_folder): | 128 if os.path.exists(user_profile_dir): |
85 shutil.rmtree(native_messaging_folder) | 129 shutil.rmtree(user_profile_dir) |
86 os.makedirs(native_messaging_folder) | 130 os.makedirs(native_messaging_folder) |
87 | 131 |
88 manifest_file_src = os.path.join(os.getcwd(), manifest_file) | 132 manifest_file_src = os.path.join(os.getcwd(), manifest_file) |
89 manifest_file_dest = ( | 133 manifest_file_dest = ( |
90 os.path.join(native_messaging_folder, os.path.basename(manifest_file))) | 134 os.path.join(native_messaging_folder, os.path.basename(manifest_file))) |
91 shutil.copyfile(manifest_file_src, manifest_file_dest) | 135 shutil.copyfile(manifest_file_src, manifest_file_dest) |
92 | 136 |
| 137 # Finally, start chromoting host. |
| 138 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') |
| 139 |
93 | 140 |
94 def main(): | 141 def main(): |
95 parser = argparse.ArgumentParser() | 142 parser = argparse.ArgumentParser() |
96 parser.add_argument('-f', '--commands_file', | 143 parser.add_argument('-f', '--commands_file', |
97 help='path to file listing commands to be launched.') | 144 help='path to file listing commands to be launched.') |
98 parser.add_argument('-p', '--prod_dir', | 145 parser.add_argument('-p', '--prod_dir', |
99 help='path to folder having product and test binaries.') | 146 help='path to folder having product and test binaries.') |
100 parser.add_argument('-c', '--cfg_file', | 147 parser.add_argument('-c', '--cfg_file', |
101 help='path to test host config file.') | 148 help='path to test host config file.') |
102 parser.add_argument('-m', '--manifest_file', | 149 parser.add_argument('-m', '--manifest_file', |
103 help='path to me2me host manifest file.') | 150 help='path to me2me host manifest file.') |
104 parser.add_argument( | 151 parser.add_argument( |
105 '-u', '--user_profile_dir', | 152 '-u', '--user_profile_dir', |
106 help='path to user-profile-dir, used by connect-to-host tests.') | 153 help='path to user-profile-dir, used by connect-to-host tests.') |
107 | 154 |
108 args = parser.parse_args() | 155 args = parser.parse_args() |
109 | 156 |
110 InitialiseTestMachineForLinux(args.cfg_file, args.manifest_file, | 157 InitialiseTestMachineForLinux(args.cfg_file, args.manifest_file, |
111 args.user_profile_dir) | 158 args.user_profile_dir) |
112 | 159 |
113 with open(args.commands_file) as f: | 160 with open(args.commands_file) as f: |
114 for line in f: | 161 for line in f: |
115 # Replace the PROD_DIR value in the command-line with | 162 # Replace the PROD_DIR value in the command-line with |
116 # the passed in value. | 163 # the passed in value. |
117 line = line.replace(PROD_DIR_ID, args.prod_dir) | 164 line = line.replace(PROD_DIR_ID, args.prod_dir) |
118 LaunchCommand(line) | 165 LaunchBTCommand(line) |
| 166 |
| 167 # Now, stop host, and cleanup user-profile-dir |
| 168 TestCleanUp(args.user_profile_dir) |
119 | 169 |
120 if __name__ == '__main__': | 170 if __name__ == '__main__': |
121 main() | 171 main() |
OLD | NEW |