OLD | NEW |
1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
| 5 import re |
| 6 import urlparse |
| 7 |
5 from recipe_engine import recipe_test_api | 8 from recipe_engine import recipe_test_api |
6 | 9 |
7 class PropertiesTestApi(recipe_test_api.RecipeTestApi): | 10 class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
8 def __call__(self, **kwargs): | 11 def __call__(self, **kwargs): |
9 ret = self.test(None) | 12 ret = self.test(None) |
10 ret.properties.update(kwargs) | 13 ret.properties.update(kwargs) |
11 return ret | 14 return ret |
12 | 15 |
13 def generic(self, **kwargs): | 16 def generic(self, **kwargs): |
14 """ | 17 """ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 """ | 50 """ |
48 ret = self.generic( | 51 ret = self.generic( |
49 branch='master', | 52 branch='master', |
50 project='', | 53 project='', |
51 repository='https://chromium.googlesource.com/chromium/src.git', | 54 repository='https://chromium.googlesource.com/chromium/src.git', |
52 revision='c14d891d44f0afff64e56ed7c9702df1d807b1ee', | 55 revision='c14d891d44f0afff64e56ed7c9702df1d807b1ee', |
53 ) | 56 ) |
54 ret.properties.update(kwargs) | 57 ret.properties.update(kwargs) |
55 return ret | 58 return ret |
56 | 59 |
| 60 def _gerrit_tryserver(self, **kwargs): |
| 61 # Call it through self.tryserver with (gerrit_project='infra/infra'). |
| 62 project = kwargs.pop('gerrit_project') |
| 63 gerrit_url = kwargs.pop('gerrit_url', None) |
| 64 git_url = kwargs.pop('git_url', None) |
| 65 if not gerrit_url and not git_url: |
| 66 gerrit_url = 'https://chromium-review.googlesource.com' |
| 67 git_url = 'https://chromium.googlesource.com/' + project |
| 68 elif gerrit_url and not git_url: |
| 69 parsed = list(urlparse.urlparse(gerrit_url)) |
| 70 m = re.match(r'^((\w+)(-\w+)*)-review.googlesource.com$', parsed[1]) |
| 71 if not m: # pragma: no cover |
| 72 raise AssertionError('Can\'t guess git_url from gerrit_url "%s", ' |
| 73 'specify it as extra kwarg' % parsed[1]) |
| 74 parsed[1] = m.group(1) + '.googlesource.com' |
| 75 parsed[2] = project |
| 76 git_url = urlparse.urlunparse(parsed) |
| 77 elif git_url and not gerrit_url: |
| 78 parsed = list(urlparse.urlparse(git_url)) |
| 79 m = re.match(r'^((\w+)(-\w+)*).googlesource.com$', parsed[1]) |
| 80 if not m: # pragma: no cover |
| 81 raise AssertionError('Can\'t guess gerrit_url from git_url "%s", ' |
| 82 'specify it as extra kwarg' % parsed[1]) |
| 83 parsed[1] = m.group(1) + '-review.googlesource.com' |
| 84 gerrit_url = urlparse.urlunparse(parsed[:2] + [''] * len(parsed[2:])) |
| 85 assert project |
| 86 assert git_url |
| 87 assert gerrit_url |
| 88 # Pop old style values from kwargs. |
| 89 patch_issue = int(kwargs.pop('issue', 456789)) |
| 90 patch_set = int(kwargs.pop('patchset', 12)) |
| 91 # Note that new Gerrit patch properties all start with 'patch_' prefix. |
| 92 ret = self.generic( |
| 93 patch_storage='gerrit', |
| 94 patch_gerrit_url=gerrit_url, |
| 95 patch_project=project, |
| 96 patch_branch='master', |
| 97 patch_issue=patch_issue, |
| 98 patch_set=patch_set, |
| 99 patch_repository_url=git_url, |
| 100 patch_ref='refs/changes/%2d/%d/%d' % ( |
| 101 patch_issue % 100, patch_issue, patch_set) |
| 102 ) |
| 103 ret.properties.update(kwargs) |
| 104 return ret |
| 105 |
57 def tryserver(self, **kwargs): | 106 def tryserver(self, **kwargs): |
58 """ | 107 """ |
59 Merge kwargs into a typical buildbot properties blob for a job fired off | 108 Merge kwargs into a typical buildbot properties blob for a job fired off |
60 by a rietveld tryjob on the tryserver, and return the blob. | 109 by a rietveld tryjob on the tryserver, and return the blob. |
| 110 |
| 111 If gerrit_project is given, generated properties for tryjobs for Gerrit |
| 112 patches as if they were scheduled by CQ. In this case, gerrit_url and |
| 113 git_url could be used to customize expectations. |
61 """ | 114 """ |
| 115 if kwargs.get('gerrit_project') is not None: |
| 116 return self._gerrit_tryserver(**kwargs) |
62 ret = self.generic( | 117 ret = self.generic( |
63 branch='', | 118 branch='', |
64 issue=12853011, | 119 issue=12853011, |
65 patchset=1, | 120 patchset=1, |
66 project='chrome', | 121 project='chrome', |
67 repository='', | 122 repository='', |
68 requester='commit-bot@chromium.org', | 123 requester='commit-bot@chromium.org', |
69 revision='HEAD', | 124 revision='HEAD', |
70 rietveld='https://codereview.chromium.org', | 125 rietveld='https://codereview.chromium.org', |
71 patch_project='chromium', | 126 patch_project='chromium', |
72 ) | 127 ) |
73 ret.properties.update(kwargs) | 128 ret.properties.update(kwargs) |
74 return ret | 129 return ret |
75 | 130 |
76 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): | 131 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): |
77 """ | 132 """ |
| 133 DEPRECATED. Use tryserver(gerrit_project='infra/infra') instead. |
| 134 |
78 Merge kwargs into a typical buildbot properties blob for a job fired off | 135 Merge kwargs into a typical buildbot properties blob for a job fired off |
79 by a gerrit tryjob on the tryserver, and return the blob. | 136 by a gerrit tryjob on the tryserver, and return the blob. |
80 | 137 |
81 Arguments: | 138 Arguments: |
82 full_project_name: (required) name of the project in Gerrit. | 139 full_project_name: (required) name of the project in Gerrit. |
83 gerrit_host: hostname of the gerrit server. | 140 gerrit_host: hostname of the gerrit server. |
84 Example: chromium-review.googlesource.com. | 141 Example: chromium-review.googlesource.com. |
85 """ | 142 """ |
| 143 # TODO(tandrii): remove this method. |
86 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' | 144 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' |
87 parts = gerrit_host.split('.') | 145 parts = gerrit_host.split('.') |
88 assert parts[0].endswith('-review') | 146 assert parts[0].endswith('-review') |
89 parts[0] = parts[0][:-len('-review')] | 147 parts[0] = parts[0][:-len('-review')] |
90 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) | 148 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) |
91 | 149 |
92 ret = self.generic( | 150 ret = self.generic( |
93 branch='', | 151 branch='', |
94 category='cq', | 152 category='cq', |
95 gerrit='https://%s' % gerrit_host, | 153 gerrit='https://%s' % gerrit_host, |
96 patch_storage='gerrit', | 154 patch_storage='gerrit', |
97 project=full_project_name, | 155 project=full_project_name, |
98 patch_project=full_project_name, | 156 patch_project=full_project_name, |
99 reason='CQ', | 157 reason='CQ', |
100 repository=repository, | 158 repository=repository, |
101 requester='commit-bot@chromium.org', | 159 requester='commit-bot@chromium.org', |
102 revision='HEAD', | 160 revision='HEAD', |
103 ) | 161 ) |
104 ret.properties.update({ | 162 ret.properties.update({ |
105 'event.change.id': u'%s~master~Ideadbeaf' % | 163 'event.change.id': u'%s~master~Ideadbeaf' % |
106 (full_project_name.replace('/', '%2F')), | 164 (full_project_name.replace('/', '%2F')), |
107 'event.change.number': 338811, | 165 'event.change.number': 338811, |
108 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, | 166 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, |
109 'event.patchSet.ref': u'refs/changes/11/338811/3', | 167 'event.patchSet.ref': u'refs/changes/11/338811/3', |
110 }) | 168 }) |
111 ret.properties.update(kwargs) | 169 ret.properties.update(kwargs) |
112 return ret | 170 return ret |
OLD | NEW |