3 import cgi
, os
, sys
, urllib2
5 from autotest_lib
.client
.common_lib
import global_config
6 from autotest_lib
.client
.bin
import utils
7 from autotest_lib
.frontend
.afe
.json_rpc
import serviceHandler
11 Content-Type: text/plain
15 # Define function for retrieving logs
16 def _retrieve_logs_dummy(job_path
):
19 site_retrieve_logs
= utils
.import_site_function(__file__
,
20 "autotest_lib.tko.site_retrieve_logs", "site_retrieve_logs",
23 site_find_repository_host
= utils
.import_site_function(__file__
,
24 "autotest_lib.tko.site_retrieve_logs", "site_find_repository_host",
28 form
= cgi
.FieldStorage(keep_blank_values
=True)
29 # determine if this is a JSON-RPC request. we support both so that the new TKO
30 # client can use its RPC client code, but the old TKO can still use simple GET
32 _is_json_request
= form
.has_key('callback')
34 def _get_requested_path():
36 request_data
= form
['request'].value
37 request
= serviceHandler
.ServiceHandler
.translateRequest(request_data
)
38 parameters
= request
['params'][0]
39 return parameters
['path']
41 return form
['job'].value
44 def find_repository_host(job_path
):
45 """Find the machine holding the given logs and return a URL to the logs"""
46 config
= global_config
.global_config
47 drones
= config
.get_config_value('SCHEDULER', 'drones')
48 results_host
= config
.get_config_value('SCHEDULER', 'results_host')
49 archive_host
= config
.get_config_value('SCHEDULER', 'archive_host',
51 results_repos
= [results_host
]
52 for drone
in drones
.split(','):
54 if drone
not in results_repos
:
55 results_repos
.append(drone
)
57 if archive_host
and archive_host
not in results_repos
:
58 results_repos
.append(archive_host
)
60 for drone
in results_repos
:
61 if drone
== 'localhost':
63 http_path
= 'http://%s%s' % (drone
, job_path
)
65 utils
.urlopen(http_path
)
67 except urllib2
.URLError
:
70 return site_find_repository_host(log_path
)
73 def get_full_url(host
, path
):
76 host
, port
= host
.split(':')
77 prefix
= 'http://%s:%s' % (utils
.normalize_hostname(host
), port
)
79 prefix
= 'http://%s' % utils
.normalize_hostname(host
)
84 return '%s/tko/jsonp_fetcher.cgi?%s' % (prefix
,
85 os
.environ
['QUERY_STRING'])
90 log_path
= _get_requested_path()
91 host
= find_repository_host(log_path
)
92 site_retrieve_logs(log_path
)
93 print _PAGE
% get_full_url(host
, log_path
)