Skip to content

Commit f96c73e

Browse files
committed
File bugs in Core :: General when the moz.yaml's component doesn't exist
If the bugzilla component in a library's moz.yaml doesn't exist, Bugzilla rejects the bug (code 51, "There is no component named ...") and we crashed without filing anything. On the dev instance this hit seven libraries whose components only exist in production. File the bug in Core :: General instead, then file a bug in Updatebot's component asking for the moz.yaml to be fixed, blocking the first one and needinfo-ing tom and the library's maintainer. If filing that second bug fails, log it and carry on rather than losing track of the library's bug.
1 parent 2d5c043 commit f96c73e

3 files changed

Lines changed: 104 additions & 10 deletions

File tree

‎apis/bugzilla_api.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _load_json_or_raise(r, where: str):
4949
) from e
5050

5151

52-
def fileBug(url, apikey, ff_version, product, component, summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential):
52+
def fileBug(url, apikey, ff_version, product, component, summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential, mark_affected=True):
5353
assert isinstance(cc_list, list)
5454

5555
data = {
@@ -65,7 +65,7 @@ def fileBug(url, apikey, ff_version, product, component, summary, description, c
6565
'cc': ['tom@mozilla.com', 'jewilde@mozilla.com'] + cc_list
6666
}
6767

68-
if is_prod(url):
68+
if is_prod(url) and mark_affected:
6969
data['cf_status_firefox' + str(ff_version)] = 'affected'
7070

7171
if see_also:

‎components/bugzilla.py‎

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ def COULD_NOT_VENDOR_ALL_FILES(library, errormessage):
198198
s += "they are excluded from the source tree and ignored in the future."
199199
return s
200200

201+
@staticmethod
202+
def MISSING_COMPONENT(library, filed_bug_id):
203+
return ("%s specifies the Bugzilla component '%s :: %s', which doesn't exist, so Updatebot "
204+
"filed bug %s in %s :: %s instead.\n\n"
205+
"Please update the bugzilla product and component in %s, and move bug %s to the right component.") % (
206+
library.yaml_path, library.bugzilla_product, library.bugzilla_component,
207+
filed_bug_id, FALLBACK_PRODUCT_COMPONENT[0], FALLBACK_PRODUCT_COMPONENT[1],
208+
library.yaml_path, filed_bug_id)
209+
201210
@staticmethod
202211
def TRY_RUN_SUBMITTED(revision, another=False):
203212
return "I've submitted a" + ("nother" if another else "") + " try run for this commit: https://treeherder.mozilla.org/jobs?repo=try&revision=" + revision
@@ -214,6 +223,21 @@ def is_needinfo_exception(e):
214223
return 'is not currently accepting "needinfo" requests' in str(e)
215224

216225

226+
def is_missing_component_exception(e):
227+
# fileBug raises Exception(<Bugzilla's JSON error>); code 51 is "object
228+
# does not exist", which also covers e.g. unknown users.
229+
j = e.args[0] if e.args else None
230+
return isinstance(j, dict) and j.get('code') == 51 and \
231+
'There is no component named' in j.get('message', '')
232+
233+
234+
# Where a bug goes when the component in its moz.yaml doesn't exist, and where
235+
# the follow-up bug asking for the moz.yaml to be fixed goes.
236+
FALLBACK_PRODUCT_COMPONENT = ("Core", "General")
237+
UPDATEBOT_PRODUCT_COMPONENT = ("Developer Infrastructure", "Mach Vendor & Updatebot")
238+
UPDATEBOT_OWNER_BZ = "tom@mozilla.com"
239+
240+
217241
class BugzillaProvider(BaseProvider, INeedsLoggingProvider):
218242
PROTECTED_LANDING_LINK_PREFIXES = (
219243
"https://hg.mozilla.org/integration/autoland/",
@@ -240,19 +264,46 @@ def file_bug(self, library, summary, description, cc_list, needinfo=None, see_al
240264
description = description[0:65533 - len(suffix)] + suffix
241265

242266
try:
243-
bugID = fileBug(self.config['url'], self.config['apikey'], self.config['General']['ff-version'],
244-
library.bugzilla_product, library.bugzilla_component,
245-
summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential)
267+
bugID = self._file_bug(library.bugzilla_product, library.bugzilla_component,
268+
summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential)
246269
except Exception as e:
247-
if is_needinfo_exception(e):
248-
self.logger.log("Developer is not accepting needinfos, trying again without...", level=LogLevel.Info)
249-
return self.file_bug(library, summary, description, cc_list, None, see_also, depends_on, blocks, moco_confidential)
250-
else:
270+
if not is_missing_component_exception(e):
251271
raise e
272+
self.logger.log("The component %s :: %s from %s doesn't exist; filing in %s :: %s instead." % (
273+
library.bugzilla_product, library.bugzilla_component, library.yaml_path,
274+
FALLBACK_PRODUCT_COMPONENT[0], FALLBACK_PRODUCT_COMPONENT[1]), level=LogLevel.Warning)
275+
bugID = self._file_bug(FALLBACK_PRODUCT_COMPONENT[0], FALLBACK_PRODUCT_COMPONENT[1],
276+
summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential)
277+
self._file_missing_component_bug(library, bugID)
252278

253279
self.logger.log("Filed Bug with ID", bugID, level=LogLevel.Info)
254280
return bugID
255281

282+
def _file_bug(self, product, component, summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential, mark_affected=True):
283+
try:
284+
return fileBug(self.config['url'], self.config['apikey'], self.config['General']['ff-version'],
285+
product, component, summary, description, cc_list, needinfo, see_also, depends_on, blocks, moco_confidential,
286+
mark_affected=mark_affected)
287+
except Exception as e:
288+
if is_needinfo_exception(e):
289+
self.logger.log("Developer is not accepting needinfos, trying again without...", level=LogLevel.Info)
290+
return self._file_bug(product, component, summary, description, cc_list, None, see_also, depends_on, blocks, moco_confidential, mark_affected)
291+
raise e
292+
293+
def _file_missing_component_bug(self, library, filed_bug_id):
294+
needinfo = [UPDATEBOT_OWNER_BZ]
295+
if library.maintainer_bz and library.maintainer_bz != UPDATEBOT_OWNER_BZ:
296+
needinfo.append(library.maintainer_bz)
297+
try:
298+
bugID = self._file_bug(UPDATEBOT_PRODUCT_COMPONENT[0], UPDATEBOT_PRODUCT_COMPONENT[1],
299+
"Update the Bugzilla component in %s" % library.yaml_path,
300+
CommentTemplates.MISSING_COMPONENT(library, filed_bug_id),
301+
[], needinfo, None, None, filed_bug_id, False, mark_affected=False)
302+
self.logger.log("Filed Bug %s about the missing component, blocking bug %s" % (bugID, filed_bug_id), level=LogLevel.Info)
303+
except Exception as e:
304+
# The library's bug is already filed; don't lose track of it over this.
305+
self.logger.log("Could not file a bug about the missing component in %s: %s" % (library.yaml_path, e), level=LogLevel.Error)
306+
256307
@logEntryExit
257308
def comment_on_bug(self, bug_id, comment, needinfo=None, assignee=None):
258309
if len(comment) > 65535:

‎tests/bugzilla.py‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
class MockBugzillaServer(server.BaseHTTPRequestHandler):
2727
closed_bug_ids = []
28+
filed_bugs = []
2829

2930
def do_POST(self):
3031
expectedPath_file = "/bug?api_key=bob"
@@ -35,7 +36,17 @@ def do_POST(self):
3536
self.send_header("Content-type", "application/json")
3637
self.end_headers()
3738

38-
if expectedPath_file == self.path:
39+
MockBugzillaServer.filed_bugs.append(content)
40+
if content['component'] == 'Missing Component':
41+
self.wfile.write(json.dumps({'error': True, 'code': 51, 'message': "There is no component named 'Missing Component' in the 'Core' product."}).encode())
42+
elif content['product'] == 'Core' and content['component'] == 'General':
43+
self.wfile.write("{\"id\":457}".encode())
44+
elif content['component'] == 'Mach Vendor & Updatebot':
45+
if 'broken' in content['summary']:
46+
self.wfile.write(json.dumps({'error': True, 'code': 100, 'message': "Something went wrong."}).encode())
47+
else:
48+
self.wfile.write("{\"id\":458}".encode())
49+
elif expectedPath_file == self.path:
3950
expectedContent = {
4051
'version': "unspecified",
4152
'op_sys': "unspecified",
@@ -194,6 +205,38 @@ def testComment(self):
194205
self.bugzillaProvider.comment_on_bug(
195206
1237, "X" * 70000, assignee='Jon')
196207

208+
def testFileMissingComponent(self):
209+
library = Struct(**{
210+
'name': 'mylib',
211+
'bugzilla_product': 'Core',
212+
'bugzilla_component': 'Missing Component',
213+
'yaml_path': 'third_party/mylib/moz.yaml',
214+
'maintainer_bz': 'owner@example.com',
215+
})
216+
bug_id = self.bugzillaProvider.file_bug(library, "Update mylib to new version V1", "Details", [])
217+
self.assertEqual(bug_id, 457, "The bug should have been filed in Core :: General")
218+
219+
filed = [b for b in MockBugzillaServer.filed_bugs if 'mylib' in b['summary']]
220+
self.assertEqual([(b['product'], b['component']) for b in filed],
221+
[('Core', 'Missing Component'), ('Core', 'General'), ('Developer Infrastructure', 'Mach Vendor & Updatebot')])
222+
library_bug, followup = filed[1], filed[2]
223+
self.assertIn('cf_status_firefox88', library_bug)
224+
self.assertEqual(followup['blocks'], 457)
225+
self.assertEqual([f['requestee'] for f in followup['flags']], ['tom@mozilla.com', 'owner@example.com'])
226+
self.assertNotIn('cf_status_firefox88', followup)
227+
self.assertIn('third_party/mylib/moz.yaml', followup['description'])
228+
229+
def testFileMissingComponentFollowUpFails(self):
230+
library = Struct(**{
231+
'name': 'broken',
232+
'bugzilla_product': 'Core',
233+
'bugzilla_component': 'Missing Component',
234+
'yaml_path': 'third_party/broken/moz.yaml',
235+
'maintainer_bz': 'owner@example.com',
236+
})
237+
# Failing to file the follow-up must not lose the library's bug.
238+
self.assertEqual(self.bugzillaProvider.file_bug(library, "Update broken to new version V1", "Details", []), 457)
239+
197240
def testStatus(self):
198241
self.bugzillaProvider.mark_ff_version_affected(456, 76)
199242

0 commit comments

Comments
 (0)