OLD | NEW |
---|---|
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Postpone commits until the tree is open.""" | 5 """Postpone commits until the tree is open.""" |
6 | 6 |
7 import calendar | 7 import calendar |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import re | |
10 import ssl | 11 import ssl |
11 import time | 12 import time |
12 import urllib2 | 13 import urllib2 |
13 | 14 |
14 from verification import base | 15 from verification import base |
15 | 16 |
16 | 17 |
17 class TreeStatus(base.IVerifierStatus): | 18 class TreeStatus(base.IVerifierStatus): |
18 tree_status_url = unicode | 19 tree_status_url = unicode |
19 issue = int | 20 issue = int |
20 last_tree_status = unicode | 21 last_tree_status = unicode |
22 description = unicode | |
21 | 23 |
22 def get_state(self): | 24 def get_state(self): |
23 return base.SUCCEEDED | 25 return base.SUCCEEDED |
24 | 26 |
25 def postpone(self): | 27 def postpone(self): |
26 self.last_tree_status = u'' | 28 self.last_tree_status = u'' |
29 if _is_skip_tree_status(self.description): | |
30 logging.debug('Skipping tree status check for CL %s' % self.issue) | |
31 return False | |
27 try: | 32 try: |
28 logging.debug('Fetching tree status for %s' % self.tree_status_url) | 33 logging.debug('Fetching tree status for %s' % self.tree_status_url) |
29 now = time.time() | 34 now = time.time() |
30 cutoff = now - 5 * 60 | 35 cutoff = now - 5 * 60 |
31 url = self.tree_status_url + '/allstatus?format=json&endTime=%d' % cutoff | 36 url = self.tree_status_url + '/allstatus?format=json&endTime=%d' % cutoff |
32 data = json.load(urllib2.urlopen(url)) | 37 data = json.load(urllib2.urlopen(url)) |
33 | 38 |
34 # Convert datetime string to epoch. | 39 # Convert datetime string to epoch. |
35 for item in data: | 40 for item in data: |
36 # The time is returned in UTC. | 41 # The time is returned in UTC. |
(...skipping 12 matching lines...) Expand all Loading... | |
49 return False | 54 return False |
50 except (ssl.SSLError, urllib2.URLError, ValueError): | 55 except (ssl.SSLError, urllib2.URLError, ValueError): |
51 logging.error('Failed to request tree status! %s' % url) | 56 logging.error('Failed to request tree status! %s' % url) |
52 return True | 57 return True |
53 | 58 |
54 def why_not(self): | 59 def why_not(self): |
55 if self.last_tree_status: | 60 if self.last_tree_status: |
56 return u'Tree is currently not open: %s' % self.last_tree_status | 61 return u'Tree is currently not open: %s' % self.last_tree_status |
57 | 62 |
58 | 63 |
64 def _is_skip_tree_status(description): | |
65 """Returns True if a description contains NOTREECHECKS=true.""" | |
66 match = re.search(r'^NOTREECHECKS=(.*)$', description, re.MULTILINE) | |
67 return match and match.group(1).lower() == 'true' | |
iannucci
2013/11/13 06:24:22
I'm not sure why this function can't be inlined as
rmistry
2013/11/13 19:44:44
No reason, this was just exactly how try_job_on_ri
| |
68 | |
69 | |
59 class TreeStatusVerifier(base.Verifier): | 70 class TreeStatusVerifier(base.Verifier): |
60 """Checks the tree status before allowing a commit.""" | 71 """Checks the tree status before allowing a commit.""" |
61 name = 'tree status' | 72 name = 'tree status' |
62 | 73 |
63 def __init__(self, tree_status_url): | 74 def __init__(self, tree_status_url): |
64 super(TreeStatusVerifier, self).__init__() | 75 super(TreeStatusVerifier, self).__init__() |
65 self.tree_status_url = tree_status_url | 76 self.tree_status_url = tree_status_url |
66 | 77 |
67 def verify(self, pending): | 78 def verify(self, pending): |
68 pending.verifications[self.name] = TreeStatus( | 79 pending.verifications[self.name] = TreeStatus( |
69 tree_status_url=self.tree_status_url, issue=pending.issue) | 80 tree_status_url=self.tree_status_url, issue=pending.issue, |
81 description=pending.description) | |
iannucci
2013/11/13 06:24:22
Another way to do it would be to process descripti
iannucci
2013/11/13 06:25:15
Actually... we could just do the description proce
rmistry
2013/11/13 19:44:44
SGTM. Done. PTAL.
| |
70 | 82 |
71 def update_status(self, queue): | 83 def update_status(self, queue): |
72 pass | 84 pass |
OLD | NEW |