Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
Merge 22f48d1 into a91ba25
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLing committed Feb 23, 2016
2 parents a91ba25 + 22f48d1 commit 3f48557
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
8 changes: 7 additions & 1 deletion mozci/query_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,11 @@ def find_all_jobs_by_status(self, repo_name, revision, status):
except TreeherderError:
continue
if job_status == status:
builder_names.append(job['ref_data_name'])
if job['build_system_type'] == 'taskcluster':
platform = '[TC]'
job_type_name = job['job_type_name'].replace('-', '')
builder_name = job_type_name.split(platform)[-1].replace(' ', '')
else:
builder_name = job['job_type_name']
builder_names.append(builder_name)
return builder_names
15 changes: 10 additions & 5 deletions mozci/scripts/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mozci.utils.authentication import valid_credentials, get_credentials
from mozci.utils.log_util import setup_logging
from mozci.platforms import filter_buildernames
from mozci.query_jobs import WARNING
from mozci.query_jobs import WARNING, SUCCESS


def parse_args(argv=None):
Expand Down Expand Up @@ -151,7 +151,7 @@ def parse_args(argv=None):
help="comma-separated treeherder filters to exclude.")

parser.add_argument("--existing-only",
action="store_false",
action="store_true",
dest="existing_only",
help="Only trigger test job if the build jobs already exists.")

Expand All @@ -172,7 +172,7 @@ def validate_options(options):
error_message = ""
if not(options.buildernames or options.coalesced or options.fill_revision or
options.trigger_tests_only or options.includes or options.exclude or
options.failed_jobs):
options.existing_only or options.failed_jobs):
error_message = "A buildername is mandatory for all modes except --coalesced, " \
"--fill-revision, --trigger-only-test-jobs --include, --exclude" \
" and --failed-jobs. Use --buildername."
Expand Down Expand Up @@ -292,7 +292,6 @@ def main():
LOG = setup_logging(logging.INFO)

validate_options(options)

if not valid_credentials():
sys.exit(-1)

Expand Down Expand Up @@ -370,6 +369,12 @@ def main():
return

if options.existing_only:
existing_buildername = TreeherderApi().find_all_jobs_by_status(
repo_name=repo_name,
revision=revision,
status=SUCCESS)
buildernames = [buildername for buildername in existing_buildername
if buildername in buildernames]
cont = raw_input("The ones which have existing builds out of %i jobs will be triggered,\
do you wish to continue? y/n/d (d=show details) " % len(buildernames))
else:
Expand All @@ -383,7 +388,7 @@ def main():
if cont.lower() != 'y':
exit(1)

# Mode 5: Use --existing-jobs or --failed-jobs to trigger jobs for particular revision
# Mode 5: Use --failed-jobs to trigger jobs for particular revision
elif options.failed_jobs:
buildernames = TreeherderApi().find_all_jobs_by_status(
repo_name=repo_name,
Expand Down
115 changes: 115 additions & 0 deletions test/test_query_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,85 @@
}
"""

MOCK_JOBS = """
[{
"submit_timestamp": 1435806434,
"build_system_type": "buildbot",
"machine_name": "tst-linux64-spot-1083",
"job_group_symbol": "M",
"job_group_name": "Mochitest",
"platform_option": "opt",
"job_type_description": "integration test",
"result_set_id": 16679,
"build_platform_id": 9,
"result": "%(result)s",
"id": 11294317,
"machine_platform_architecture": "x86_64",
"end_timestamp": 1435807607,
"build_platform": "linux64",
"job_guid": "56e77044a516ff857a21ebd52a97d73f7fdf29de",
"job_type_name": "Mochitest",
"ref_data_name": "Ubuntu VM 12.04 x64 mozilla-inbound opt test mochitest-1",
"platform": "linux64",
"state": "%(state)s",
"running_eta": 1907,
"pending_eta": 6,
"build_os": "linux",
"option_collection_hash": "102210fe594ee9b33d82058545b1ed14f4c8206e",
"who": "tests-mozilla-inbound-ubuntu64_vm-opt-unittest",
"failure_classification_id": 1,
"job_type_symbol": "1",
"reason": "scheduler",
"job_group_description": "fill me",
"tier": 1,
"job_coalesced_to_guid": null,
"machine_platform_os": "linux",
"start_timestamp": 1435806437,
"build_architecture": "x86_64",
"device_name": "vm",
"last_modified": "2015-07-02T03:29:09",
"signature": "41f96d52f5fc013ae82825172d9e13f4e517c5ac"
},
{
"submit_timestamp": 1455882877,
"build_system_type": "taskcluster",
"machine_name": "i-a5947c10",
"job_group_symbol": "tc",
"job_group_name": "Submitted by taskcluster",
"platform_option": "opt",
"job_type_description": "fill me",
"signature": "3681e7bdec56673c80e85486dcfd66d4e2c57185",
"result_set_id": 27064,
"result": "%(result)s",
"machine_platform_os": "-",
"ref_data_name": "3681e7bdec56673c80e85486dcfd66d4e2c57185",
"machine_platform_architecture": "-",
"end_timestamp": 1455884086,
"build_platform": "lint",
"job_guid": "6657633e-a463-4955-bc9c-3a561b236308/0",
"job_type_name": "[TC] - ESLint",
"id": 22009433,
"platform": "lint",
"state": "%(state)s",
"job_type_id": 4293,
"build_os": "-",
"option_collection_hash": "102210fe594ee9b33d82058545b1ed14f4c8206e",
"who": "mozilla-taskcluster-maintenance@mozilla.com",
"failure_classification_id": 1,
"job_type_symbol": "ES",
"reason": "scheduled",
"job_group_description": "fill me",
"tier": 1,
"job_coalesced_to_guid": "None",
"running_eta": 317,
"start_timestamp": 1455883462,
"build_architecture": "-",
"last_modified": "2016-02-19T12:14:47",
"build_platform_id": 144,
"job_group_id": 41
}]
"""

REPOSITORIES = """{
"repo1": {
"repo": "https://hg.mozilla.org/releases/repo1",
Expand Down Expand Up @@ -274,3 +353,39 @@ def test_matching_jobs_invalid(self):
self.query_api.get_matching_jobs(
"try", "146071751b1e",
'Invalid buildername'), [])


class TestTestTreeherderApiGetAllJobsByStatus(unittest.TestCase):
"""Test TreeherderApi fetch all jobs(buildernames for now) by job's status."""

def setUp(self):
self.query_api = TreeherderApi()
self.repo_name = 'repo_mock'
self.revision = 'revision_mock'

@patch('mozci.query_jobs.TreeherderApi.get_all_jobs',
return_value=json.loads(MOCK_JOBS % {'result': "success", 'state': "completed"}))
@patch('mozci.query_jobs.TreeherderApi.get_job_status',
return_value=SUCCESS)
def test_successful_job(self, get_all_jobs, get_job_status):
"""Test TreeherderApi find_all_jobs_by_status with a successful job."""
self.assertEqual(self.query_api.find_all_jobs_by_status(
self.repo_name, self.revision, SUCCESS), ["Mochitest", "ESLint"])

@patch('mozci.query_jobs.TreeherderApi.get_all_jobs',
return_value=json.loads(MOCK_JOBS % {'result': "testfailed", 'state': "completed"}))
@patch('mozci.query_jobs.TreeherderApi.get_job_status',
return_value=FAILURE)
def test_failed_job(self, get_all_jobs, get_job_status):
"""Test TreeherderApi find_all_jobs_by_status with a failed job."""
self.assertEqual(self.query_api.find_all_jobs_by_status(
self.repo_name, self.revision, FAILURE), ["Mochitest", "ESLint"])

@patch('mozci.query_jobs.TreeherderApi.get_all_jobs',
return_value=json.loads(MOCK_JOBS % {'result': "unknown", 'state': "pending"}))
@patch('mozci.query_jobs.TreeherderApi.get_job_status',
return_value=PENDING)
def test_pending_job(self, get_all_jobs, get_job_status):
"""Test TreeherderApi find_all_jobs_by_status with a pending job."""
self.assertEqual(self.query_api.find_all_jobs_by_status(
self.repo_name, self.revision, PENDING), ["Mochitest", "ESLint"])

0 comments on commit 3f48557

Please sign in to comment.