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