Mercurial > mozilla > hg > talosnames
annotate talosnames/api.py @ 38:ef8590b55605
determine actually correct name extension
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 24 Jul 2012 11:12:07 -0700 |
parents | 15f17eeb1813 |
children | 4dfa9c298e3d |
rev | line source |
---|---|
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
1 import os |
6 | 2 import re |
10 | 3 import require |
13
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
4 import subprocess |
1 | 5 import sqlite3 |
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
6 import sys |
13
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
7 import talos |
33 | 8 import talos.run_tests |
16 | 9 import tempfile |
1 | 10 import urllib2 |
16 | 11 import yaml |
12 | |
13 try: | |
14 call = subprocess.check_call | |
15 except: | |
16 call = subprocess.call | |
1 | 17 |
13
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
18 talos_dir = os.path.dirname(os.path.abspath(talos.__file__)) |
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
19 |
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
20 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
21 |
0 | 22 class TalosNames(object): |
23 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql' | |
1 | 24 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql' |
10 | 25 project_branches = 'http://hg.mozilla.org/build/buildbot-configs/raw-file/tip/mozilla/project_branches.py' |
26 buildbot_config = 'http://hg.mozilla.org/build/buildbot-configs/raw-file/tip/mozilla-tests/config.py' | |
1 | 27 |
5 | 28 # mapping file from builbot-configs name to tbpl codes: |
29 # http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/file/tip/js/Config.js | |
6 | 30 tbpl_map = 'http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/raw-file/tip/js/Data.js' |
5 | 31 |
2 | 32 tables = {'os_list': '(id, name text)', |
3 | 33 'branches': '(id, name text)', |
2 | 34 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)', |
35 'pagesets': '(id, name text)', | |
36 'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)' | |
37 } | |
1 | 38 |
10 | 39 ### initialization functions |
40 | |
0 | 41 def __init__(self): |
5 | 42 self.setup_database() |
43 self.tbpl_mapping() | |
10 | 44 self.setup_buildbot() |
21 | 45 |
46 # cache | |
17
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
47 self._talos_configs = {} |
21 | 48 self._tbpl_names = {} |
5 | 49 |
6 | 50 def setup_database(self): |
1 | 51 self.db = sqlite3.connect(':memory:') |
3 | 52 sql_lines = urllib2.urlopen(self.graphserver_sql).readlines() |
53 | |
54 # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have | |
55 sql_lines = [line for line in sql_lines | |
56 if 'unix_timestamp' not in line] | |
57 sql = '\n'.join(sql_lines) | |
58 | |
1 | 59 cursor = self.db.cursor() |
2 | 60 for table, schema in self.tables.items(): |
61 cursor.execute("""CREATE TABLE %s %s""" % (table, schema)) | |
3 | 62 cursor.executescript(sql) |
2 | 63 self.db.commit() |
64 cursor.close() | |
1 | 65 |
3 | 66 # create data structures |
67 self.names = {} | |
68 self.chrome = set() | |
69 cursor = self.db.cursor() | |
70 cursor.execute("SELECT * FROM tests") | |
71 for _, short_name, graphserver_name, is_chrome, _, _ in cursor.fetchall(): | |
72 self.names[short_name] = graphserver_name | |
73 if is_chrome: | |
74 self.chrome.add(short_name) | |
75 cursor.close() | |
76 | |
5 | 77 def tbpl_mapping(self): |
6 | 78 self.tbpl_regexs = {} |
79 lines = [line.strip() | |
80 for line in urllib2.urlopen(self.tbpl_map).readlines()] | |
81 lines = [line for line in lines | |
82 if line.startswith('/talos.*')] | |
83 regex = re.compile('\/talos\.\*(.*)\/.*\?.*\"([^"].*)\".*') | |
84 for line in lines: | |
85 match = regex.match(line) | |
86 assert match | |
87 _regex, name = match.groups() | |
88 self.tbpl_regexs[name] = _regex | |
5 | 89 |
10 | 90 def setup_buildbot(self): |
91 # project_branches = require.require(self.project_branches) | |
92 module = require.require(self.buildbot_config) | |
93 self.suites = module.SUITES | |
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
94 self.buildbot_commands = {} |
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
95 for key, value in self.suites.items(): |
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
96 self.buildbot_commands[key] = value['suites'] |
10 | 97 |
98 ### functions for fetching information | |
99 | |
100 def tbpl_name(self, name): | |
101 """returns the TBPL long name""" | |
21 | 102 if name in self._tbpl_names: |
103 return self._tbpl_names[name] | |
10 | 104 for tbplname, regex in self.tbpl_regexs.items(): |
105 regex = re.compile(regex) | |
106 if regex.match(name): | |
21 | 107 self._tbpl_names[name] = tbplname |
10 | 108 return tbplname |
109 | |
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
110 def buildbot_command(self, name): |
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
111 """gets the buildbot command for a particular suite""" |
23 | 112 return self.buildbot_commands.get(name)[:] |
12
a4aa9f83e3be
adding a thing for commands
Jeff Hammel <jhammel@mozilla.com>
parents:
10
diff
changeset
|
113 |
14 | 114 def talos_config(self, name): |
115 """returns talos configuration for suite `name`""" | |
21 | 116 if name in self._talos_configs: |
117 return self._talos_configs[name] | |
118 | |
13
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
119 command = self.buildbot_command(name) |
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
120 assert command is not None, "Suite not found: %s" % name |
16 | 121 outfile = tempfile.mktemp(suffix='.yml') |
122 command += ['-o', outfile] # add an output file | |
123 command += ['-e', sys.executable] # add a pretend firefox so PerfConfigurator won't whine | |
30 | 124 print "\n%s" % subprocess.list2cmdline(command) |
16 | 125 call(['PerfConfigurator'] + command, stdout=subprocess.PIPE, cwd=talos_dir) |
126 assert os.path.exists(outfile) | |
127 config = yaml.load(file(outfile)) | |
21 | 128 self._talos_configs[name] = config |
17
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
129 return config |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
130 |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
131 def test_config(self, name): |
33 | 132 config = self.talos_config(name) |
133 test_config = config['tests'] | |
134 talos.run_tests.useBaseTestDefaults(config.get('basetest', {}), test_config) | |
17
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
135 retval = {} |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
136 for test in test_config: |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
137 name = test.pop('name') |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
138 retval[name] = test |
25e91fc7ff01
getting the test config now works
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
139 return retval |
13
323a01abd180
putting off this fun for later
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
140 |
3 | 141 def __call__(self, name=None): |
26 | 142 """returns the graphserver name prefixed with `name`""" |
143 | |
3 | 144 retval = [] |
145 for short_name, graphserver_name in self.names.items(): | |
146 if (name is None) or (name == short_name or short_name.startswith(name + '_')): | |
147 retval.append((short_name, graphserver_name)) | |
148 retval.sort(key=lambda x: x[0]) | |
149 return retval | |
26 | 150 |
151 def graphserver_name(self, name): | |
152 for short_name, graphserver_name in self.names.items(): | |
153 if name == short_name: | |
154 return (short_name, graphserver_name) |