|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 # Integrates Talos mozharness with mach |
|
6 |
|
7 from __future__ import print_function, unicode_literals |
|
8 |
|
9 import os |
|
10 import sys |
|
11 import json |
|
12 import which |
|
13 import socket |
|
14 |
|
15 from mozbuild.base import ( |
|
16 MozbuildObject, |
|
17 MachCommandBase |
|
18 ) |
|
19 |
|
20 from mach.decorators import ( |
|
21 CommandArgument, |
|
22 CommandProvider, |
|
23 Command, |
|
24 ) |
|
25 |
|
26 class TalosRunner(MozbuildObject): |
|
27 def run_test(self, suite, repo, rev): |
|
28 """ |
|
29 We want to do couple of things before running Talos |
|
30 1. Clone mozharness |
|
31 2. Make config for Talos Mozharness |
|
32 3. Run mozharness |
|
33 """ |
|
34 |
|
35 print("Running Talos test suite %s" % suite) |
|
36 self.init_variables(suite, repo, rev) |
|
37 self.clone_mozharness() |
|
38 self.make_config() |
|
39 self.write_config() |
|
40 self.make_args() |
|
41 return self.run_mozharness() |
|
42 |
|
43 def init_variables(self, suite, repo, rev): |
|
44 self.suite = suite |
|
45 self.mozharness_repo = repo |
|
46 self.mozharness_rev = rev |
|
47 |
|
48 self.talos_dir = os.path.join(self.topsrcdir, 'testing', 'talos') |
|
49 self.mozharness_dir = os.path.join(self.topobjdir, 'mozharness') |
|
50 self.config_dir = os.path.join(self.mozharness_dir, 'configs', 'talos') |
|
51 self.talos_json = os.path.join(self.talos_dir, 'talos.json') |
|
52 self.config_filename = 'in_tree_conf.json' |
|
53 self.config_file_path = os.path.join(self.config_dir, |
|
54 self.config_filename) |
|
55 self.binary_path = self.get_binary_path() |
|
56 self.virtualenv_script = os.path.join(self.topsrcdir, 'python', |
|
57 'virtualenv', 'virtualenv.py') |
|
58 self.virtualenv_path = os.path.join(self.mozharness_dir, 'venv') |
|
59 self.python_interp = sys.executable |
|
60 |
|
61 def clone_mozharness(self): |
|
62 """Clones mozharness into topobjdir/mozharness |
|
63 using mercurial. If mozharness is already cloned, |
|
64 it updates it to the latest version""" |
|
65 try: |
|
66 mercurial = which.which('hg') |
|
67 except which.WhichError as e: |
|
68 print("You don't have hg in your PATH: {0}".format(e)) |
|
69 raise e |
|
70 clone_cmd = [mercurial, 'clone', '-r', self.mozharness_rev, |
|
71 self.mozharness_repo, self.mozharness_dir] |
|
72 pull_cmd = [mercurial, 'pull', '-r', self.mozharness_rev, '-u'] |
|
73 |
|
74 dot_hg = os.path.join(self.mozharness_dir, '.hg') |
|
75 if os.path.exists(dot_hg): |
|
76 self.run_process(args=pull_cmd, cwd=self.mozharness_dir) |
|
77 else: |
|
78 self.run_process(args=clone_cmd) |
|
79 |
|
80 def make_config(self): |
|
81 self.config = { |
|
82 'talos_json': self.talos_json, |
|
83 'binary_path': self.binary_path, |
|
84 'log_name': 'talos', |
|
85 'virtualenv_path': self.virtualenv_path, |
|
86 'pypi_url': 'http://pypi.python.org/simple', |
|
87 'use_talos_json': True, |
|
88 'base_work_dir': self.mozharness_dir, |
|
89 'exes': { |
|
90 'python': self.python_interp, |
|
91 'virtualenv': [self.python_interp, self.virtualenv_script] |
|
92 }, |
|
93 'title': socket.gethostname(), |
|
94 'default_actions': [ |
|
95 'clone-talos', |
|
96 'create-virtualenv', |
|
97 'run-tests', |
|
98 ], |
|
99 'python_webserver': True |
|
100 } |
|
101 |
|
102 def make_args(self): |
|
103 self.args = { |
|
104 'config': { |
|
105 'suite': self.suite, |
|
106 'use_talos_json': True |
|
107 }, |
|
108 'initial_config_file': self.config_file_path, |
|
109 } |
|
110 |
|
111 def write_config(self): |
|
112 try: |
|
113 config_file = open(self.config_file_path, 'wb') |
|
114 config_file.write(json.dumps(self.config)) |
|
115 except IOError as e: |
|
116 err_str = "Error writing to Talos Mozharness config file {0}:{1}" |
|
117 print(err_str.format(self.config_file_path, str(e))) |
|
118 raise e |
|
119 |
|
120 def run_mozharness(self): |
|
121 sys.path.insert(0, self.mozharness_dir) |
|
122 from mozharness.mozilla.testing.talos import Talos |
|
123 talos_mh = Talos(config=self.args['config'], |
|
124 initial_config_file=self.args['initial_config_file']) |
|
125 return talos_mh.run() |
|
126 |
|
127 @CommandProvider |
|
128 class MachCommands(MachCommandBase): |
|
129 mozharness_repo = 'https://hg.mozilla.org/build/mozharness' |
|
130 mozharness_rev = 'production' |
|
131 |
|
132 @Command('talos-test', category='testing', |
|
133 description='Run talos tests.') |
|
134 @CommandArgument('suite', help='Talos test suite to run. Valid suites are ' |
|
135 'chromez, dirtypaint, dromaeojs, other,' |
|
136 'svgr, rafx, tpn, tp5o, xperf.') |
|
137 @CommandArgument('--repo', default=mozharness_repo, |
|
138 help='The mozharness repository to clone from. ' |
|
139 'Defaults to http://hg.mozilla.org/build/mozharness') |
|
140 @CommandArgument('--rev', default=mozharness_rev, |
|
141 help='The mozharness revision to clone. Defaults to ' |
|
142 'production') |
|
143 def run_talos_test(self, suite, repo=None, rev=None): |
|
144 talos = self._spawn(TalosRunner) |
|
145 |
|
146 try: |
|
147 return talos.run_test(suite, repo, rev) |
|
148 except Exception as e: |
|
149 print(str(e)) |
|
150 return 1 |