Merge lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug into lp:ubuntu-archive-tools

Proposed by Łukasz Zemczak
Status: Merged
Merged at revision: 1132
Proposed branch: lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug
Merge into: lp:ubuntu-archive-tools
Diff against target: 427 lines (+142/-234)
3 files modified
sru-accept (+4/-117)
sru-review (+4/-117)
sru_workflow.py (+134/-0)
To merge this branch: bzr merge lp:~sil2100/ubuntu-archive-tools/common-sru-process-bug
Reviewer Review Type Date Requested Status
Brian Murray Approve
Ubuntu Package Archive Administrators Pending
Review via email: mp+333980@code.launchpad.net

Commit message

Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance. This also slightly changes the behavior of sru-accept for more than one series.

Description of the change

Extract the process_bug() function to a common module so that both sru-review and sru-accept use the same mechanics for updating SRU bugs after acceptance. This also slightly changes the behavior of sru-accept for more than one series.

Currently we had two versions of process_bug and the sru-accept one was outdated. Having to maintain two of those was crazy.

Also, with this change, sru-accept when called with multiple targets now just runs process_bug() multiple times (e.g. adding one comment per series) instead of once with multiple series in the bug comment. I changed this because it was easier to do and mimics what happens when you use the sru-review tool.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

This looks good to me thanks for working on it - I think a docstring in sru_workflow.py would be good though. Additionally, a change of mine was recently merged to ubuntu-archive-tools which changed the content of the comment added to bug reports requesting feed back (lines 121-132) so please be sure not to loose that.

Thanks!

review: Approve
1127. By Łukasz Zemczak

Merge trunk, resolve conflicts.

1128. By Łukasz Zemczak

Dumb docstring for the sru_workflow.py file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sru-accept'
--- sru-accept 2016-06-07 22:36:28 +0000
+++ sru-accept 2017-12-07 16:28:26 +0000
@@ -24,126 +24,11 @@
2424
25import launchpadlib.errors25import launchpadlib.errors
26from launchpadlib.launchpad import Launchpad26from launchpadlib.launchpad import Launchpad
27from sru_workflow import process_bug
2728
2829
29CONSUMER_KEY = "sru-accept"30CONSUMER_KEY = "sru-accept"
3031
31bug_target_re = re.compile(
32 r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
33
34
35def join_english_list(words):
36 num_words = len(words)
37 assert num_words > 0
38 if num_words > 2:
39 # Yes, I use the Oxford comma. Deal with it.
40 return '%s, and %s' % (', '.join(words[:-1]), words[-1])
41 elif num_words == 2:
42 return '%s and %s' % (words[0], words[1])
43 else:
44 return words[0]
45
46
47def process_bug(launchpad, options, num):
48 bug = launchpad.bugs[num]
49 sourcepkg_match = False
50 distroseries_match = False
51
52 for task in bug.bug_tasks:
53 # Ugly; we have to do URL-parsing to figure this out.
54 # /ubuntu/+source/foo can be fed to launchpad.load() to get a
55 # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
56 match = bug_target_re.search(task.target.self_link)
57 if (not match or
58 (options.package and
59 match.group('source') != options.package)):
60 print("Ignoring task %s in bug %s" % (task.web_link, num))
61 continue
62 sourcepkg_match = True
63 if (match.group('suite') in options.targets and
64 task.status not in ("Invalid", "Won't Fix",
65 "Fix Released")):
66 task.status = "Fix Committed"
67 task.lp_save()
68 print("Success: task %s in bug %s" % (task.web_link, num))
69 distroseries_match = True
70
71 if sourcepkg_match and not distroseries_match:
72 # add a release task
73 lp_url = launchpad._root_uri
74 for series in options.targets:
75 series_task_url = '%subuntu/%s/+source/%s' % \
76 (lp_url, series, options.package)
77 sourcepkg_target = launchpad.load(series_task_url)
78 new_task = bug.addTask(target=sourcepkg_target)
79 new_task.status = "Fix Committed"
80 new_task.lp_save()
81 print("LP: #%s added task for %s %s" %
82 (num, options.package, series))
83 if not sourcepkg_match:
84 # warn that the bug has no source package tasks
85 print("LP: #%s has no %s tasks!" % (num, options.package))
86
87 bug.subscribe(person=launchpad.people['ubuntu-sru'])
88 bug.subscribe(person=launchpad.people['sru-verification'])
89
90 if not options.package or 'linux' not in options.package:
91 for t in ('verification-failed', 'verification-done'):
92 if t in bug.tags:
93 # this dance is needed due to
94 # https://bugs.launchpad.net/launchpadlib/+bug/254901
95 tags = bug.tags
96 tags.remove(t)
97 bug.tags = tags
98 bug.lp_save()
99
100 if 'verification-needed' not in bug.tags:
101 # this dance is needed due to
102 # https://bugs.launchpad.net/launchpadlib/+bug/254901
103 tags = bug.tags
104 tags.append('verification-needed')
105 bug.tags = tags
106 bug.lp_save()
107
108 text = ('Hello %s, or anyone else affected,\n\n' %
109 re.split(r'[,\s]', bug.owner.display_name)[0])
110
111 if options.package:
112 text += 'Accepted %s into ' % options.package
113 else:
114 text += 'Accepted into '
115 if options.package and options.version:
116 text += ('%s. The package will build now and be available at '
117 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
118 'and then in the -proposed repository.\n\n' % (
119 join_english_list([
120 '%s-proposed' % target
121 for target in options.targets]),
122 options.package, options.version))
123 else:
124 text += ('%s. The package will build now and be available in a few '
125 'hours in the -proposed repository.\n\n' % (
126 join_english_list([
127 '%s-proposed' % target
128 for target in options.targets])))
129
130 text += ('Please help us by testing this new package. See '
131 'https://wiki.ubuntu.com/Testing/EnableProposed for '
132 'documentation how to enable and use -proposed. Your feedback '
133 'will aid us getting this update out to other Ubuntu users.\n\n'
134 'If this package fixes the bug for you, please add a comment to '
135 'this bug, mentioning the version of the package you tested, and '
136 'change the tag from verification-needed to verification-done. '
137 'If it does not fix the bug for you, please add a comment '
138 'stating that, and change the tag to verification-failed. In '
139 'either case, details of your testing will help us make a better '
140 'decision.\n\n'
141 'Further information regarding the verification process can be '
142 'found at '
143 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
144 'Thank you in advance!')
145 bug.newMessage(content=text, subject='Please test proposed package')
146
14732
148def append_series(option, opt_str, value, parser):33def append_series(option, opt_str, value, parser):
149 if value.endswith('-proposed'):34 if value.endswith('-proposed'):
@@ -184,7 +69,9 @@
184 if series.status == "Current Stable Release"][0]]69 if series.status == "Current Stable Release"][0]]
185 try:70 try:
186 for num in args:71 for num in args:
187 process_bug(launchpad, options, num)72 for series in options.targets:
73 process_bug(
74 launchpad, options.package, options.version, series, num)
188 except launchpadlib.errors.HTTPError as err:75 except launchpadlib.errors.HTTPError as err:
189 print("There was an error:")76 print("There was an error:")
190 print(err.content)77 print(err.content)
19178
=== modified file 'sru-review' (properties changed: +x to -x)
--- sru-review 2017-12-04 21:56:46 +0000
+++ sru-review 2017-12-07 16:28:26 +0000
@@ -43,6 +43,7 @@
43import webbrowser43import webbrowser
4444
45from launchpadlib.launchpad import Launchpad45from launchpadlib.launchpad import Launchpad
46from sru_workflow import process_bug
46from time import sleep47from time import sleep
4748
4849
@@ -245,122 +246,6 @@
245 subject='Proposed package upload rejected')246 subject='Proposed package upload rejected')
246247
247248
248def process_bug(launchpad, upload, num):
249 bug_target_re = re.compile(
250 r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
251 bug = launchpad.bugs[num]
252 sourcepkg = upload.package_name
253 release = upload.distroseries.name
254 sourcepkg_match = False
255 distroseries_match = False
256 for task in bug.bug_tasks:
257 # Ugly; we have to do URL-parsing to figure this out.
258 # /ubuntu/+source/foo can be fed to launchpad.load() to get a
259 # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
260 match = bug_target_re.search(task.target.self_link)
261 if (not match or
262 (sourcepkg and
263 match.group('source') != sourcepkg)):
264 print("Ignoring task %s in bug %s" % (task.web_link, num))
265 continue
266 sourcepkg_match = True
267 if (match.group('suite') == release and
268 task.status not in ("Invalid", "Won't Fix",
269 "Fix Released")):
270 task.status = "Fix Committed"
271 task.lp_save()
272 print("Success: task %s in bug %s" % (task.web_link, num))
273 distroseries_match = True
274
275 if sourcepkg_match and not distroseries_match:
276 # add a release task
277 lp_url = launchpad._root_uri
278 series_task_url = '%subuntu/%s/+source/%s' % \
279 (lp_url, release, sourcepkg)
280 sourcepkg_target = launchpad.load(series_task_url)
281 new_task = bug.addTask(target=sourcepkg_target)
282 new_task.status = "Fix Committed"
283 new_task.lp_save()
284 print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
285 if not sourcepkg_match:
286 # warn that the bug has no source package tasks
287 print("LP: #%s has no %s tasks!" % (num, sourcepkg))
288
289 # XXX: it might be useful if the package signer/sponsor was
290 # subscribed to the bug report
291 bug.subscribe(person=launchpad.people['ubuntu-sru'])
292 bug.subscribe(person=launchpad.people['sru-verification'])
293
294 # there may be something else to sponsor so just warn
295 subscribers = [sub.person for sub in bug.subscriptions]
296 if launchpad.people['ubuntu-sponsors'] in subscribers:
297 print('ubuntu-sponsors is still subscribed to LP: #%s. '
298 'Is there anything left to sponsor?' % num)
299
300 if not sourcepkg or 'linux' not in sourcepkg:
301 # this dance is needed due to
302 # https://bugs.launchpad.net/launchpadlib/+bug/254901
303 btags = bug.tags
304 for t in ('verification-failed', 'verification-failed-%s' % release,
305 'verification-done', 'verification-done-%s' % release):
306 if t in btags:
307 tags = btags
308 tags.remove(t)
309 bug.tags = tags
310
311 if 'verification-needed' not in btags:
312 btags.append('verification-needed')
313 bug.tags = btags
314
315 needed_tag = 'verification-needed-%s' % release
316 if needed_tag not in btags:
317 btags.append(needed_tag)
318 bug.tags = btags
319
320 bug.lp_save()
321
322
323 text = ('Hello %s, or anyone else affected,\n\n' %
324 re.split(r'[,\s]', bug.owner.display_name)[0])
325
326 if sourcepkg:
327 text += 'Accepted %s into ' % sourcepkg
328 else:
329 text += 'Accepted into '
330 if sourcepkg and release:
331 text += ('%s-proposed. The package will build now and be available at '
332 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
333 'and then in the -proposed repository.\n\n' % (
334 release, sourcepkg, upload.package_version))
335 else:
336 text += ('%s-proposed. The package will build now and be available in '
337 'a few hours in the -proposed repository.\n\n' % (
338 release))
339
340 text += ('Please help us by testing this new package. ')
341
342 if sourcepkg == 'casper':
343 text += ('To properly test it you will need to obtain and boot '
344 'a daily build of a Live CD for %s.' % (release))
345 else:
346 text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
347 'documentation on how to enable and use -proposed.')
348
349 text += ('Your feedback will aid us getting this update out to other '
350 'Ubuntu users.\n\nIf this package fixes the bug for you, '
351 'please add a comment to this bug, mentioning the version of the '
352 'package you tested and change the tag from '
353 'verification-needed-%s to verification-done-%s. '
354 'If it does not fix the bug for you, please add a comment '
355 'stating that, and change the tag to verification-failed-%s. '
356 'In either case, without details of your testing we will not '
357 'be able to proceed.\n\nFurther information regarding the '
358 'verification process can be found at '
359 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
360 'Thank you in advance!' % (release, release, release))
361 bug.newMessage(content=text, subject='Please test proposed package')
362
363
364if __name__ == '__main__':249if __name__ == '__main__':
365250
366 default_release = 'artful'251 default_release = 'artful'
@@ -472,7 +357,9 @@
472 print("Accepted")357 print("Accepted")
473 if changes['bugs']:358 if changes['bugs']:
474 for bug_num in changes['bugs']:359 for bug_num in changes['bugs']:
475 process_bug(launchpad, upload, bug_num)360 process_bug(
361 launchpad, upload.package_name, upload.package_version,
362 upload.distroseries.name, bug_num)
476 else:363 else:
477 print("REJECT the package from -proposed? [yN] ", end="")364 print("REJECT the package from -proposed? [yN] ", end="")
478 response = sys.stdin.readline()365 response = sys.stdin.readline()
479366
=== added file 'sru_workflow.py'
--- sru_workflow.py 1970-01-01 00:00:00 +0000
+++ sru_workflow.py 2017-12-07 16:28:26 +0000
@@ -0,0 +1,134 @@
1#!/usr/bin/python3
2
3# Copyright (C) 2017 Canonical Ltd.
4# Author: Brian Murray <brian.murray@canonical.com>
5# Author: Lukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 3 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19"""Portions of SRU-related code that is re-used by various SRU tools."""
20
21import re
22
23
24def process_bug(launchpad, sourcepkg, version, release, num):
25 bug_target_re = re.compile(
26 r'/ubuntu/(?:(?P<suite>[^/]+)/)?\+source/(?P<source>[^/]+)$')
27 bug = launchpad.bugs[num]
28 sourcepkg_match = False
29 distroseries_match = False
30 for task in bug.bug_tasks:
31 # Ugly; we have to do URL-parsing to figure this out.
32 # /ubuntu/+source/foo can be fed to launchpad.load() to get a
33 # distribution_source_package, but /ubuntu/hardy/+source/foo can't.
34 match = bug_target_re.search(task.target.self_link)
35 if (not match or
36 (sourcepkg and
37 match.group('source') != sourcepkg)):
38 print("Ignoring task %s in bug %s" % (task.web_link, num))
39 continue
40 sourcepkg_match = True
41 if (match.group('suite') == release and
42 task.status not in ("Invalid", "Won't Fix",
43 "Fix Released")):
44 task.status = "Fix Committed"
45 task.lp_save()
46 print("Success: task %s in bug %s" % (task.web_link, num))
47 distroseries_match = True
48
49 if sourcepkg_match and not distroseries_match:
50 # add a release task
51 lp_url = launchpad._root_uri
52 series_task_url = '%subuntu/%s/+source/%s' % \
53 (lp_url, release, sourcepkg)
54 sourcepkg_target = launchpad.load(series_task_url)
55 new_task = bug.addTask(target=sourcepkg_target)
56 new_task.status = "Fix Committed"
57 new_task.lp_save()
58 print("LP: #%s added task for %s %s" % (num, sourcepkg, release))
59 if not sourcepkg_match:
60 # warn that the bug has no source package tasks
61 print("LP: #%s has no %s tasks!" % (num, sourcepkg))
62
63 # XXX: it might be useful if the package signer/sponsor was
64 # subscribed to the bug report
65 bug.subscribe(person=launchpad.people['ubuntu-sru'])
66 bug.subscribe(person=launchpad.people['sru-verification'])
67
68 # there may be something else to sponsor so just warn
69 subscribers = [sub.person for sub in bug.subscriptions]
70 if launchpad.people['ubuntu-sponsors'] in subscribers:
71 print('ubuntu-sponsors is still subscribed to LP: #%s. '
72 'Is there anything left to sponsor?' % num)
73
74 if not sourcepkg or 'linux' not in sourcepkg:
75 # this dance is needed due to
76 # https://bugs.launchpad.net/launchpadlib/+bug/254901
77 btags = bug.tags
78 for t in ('verification-failed', 'verification-failed-%s' % release,
79 'verification-done', 'verification-done-%s' % release):
80 if t in btags:
81 tags = btags
82 tags.remove(t)
83 bug.tags = tags
84
85 if 'verification-needed' not in btags:
86 btags.append('verification-needed')
87 bug.tags = btags
88
89 needed_tag = 'verification-needed-%s' % release
90 if needed_tag not in btags:
91 btags.append(needed_tag)
92 bug.tags = btags
93
94 bug.lp_save()
95
96 text = ('Hello %s, or anyone else affected,\n\n' %
97 re.split(r'[,\s]', bug.owner.display_name)[0])
98
99 if sourcepkg:
100 text += 'Accepted %s into ' % sourcepkg
101 else:
102 text += 'Accepted into '
103 if sourcepkg and release:
104 text += ('%s-proposed. The package will build now and be available at '
105 'https://launchpad.net/ubuntu/+source/%s/%s in a few hours, '
106 'and then in the -proposed repository.\n\n' % (
107 release, sourcepkg, version))
108 else:
109 text += ('%s-proposed. The package will build now and be available in '
110 'a few hours in the -proposed repository.\n\n' % (
111 release))
112
113 text += ('Please help us by testing this new package. ')
114
115 if sourcepkg == 'casper':
116 text += ('To properly test it you will need to obtain and boot '
117 'a daily build of a Live CD for %s.' % (release))
118 else:
119 text += ('See https://wiki.ubuntu.com/Testing/EnableProposed for '
120 'documentation on how to enable and use -proposed.')
121
122 text += ('Your feedback will aid us getting this update out to other '
123 'Ubuntu users.\n\nIf this package fixes the bug for you, '
124 'please add a comment to this bug, mentioning the version of the '
125 'package you tested and change the tag from '
126 'verification-needed-%s to verification-done-%s. '
127 'If it does not fix the bug for you, please add a comment '
128 'stating that, and change the tag to verification-failed-%s. '
129 'In either case, without details of your testing we will not '
130 'be able to proceed.\n\nFurther information regarding the '
131 'verification process can be found at '
132 'https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . '
133 'Thank you in advance!' % (release, release, release))
134 bug.newMessage(content=text, subject='Please test proposed package')

Subscribers

People subscribed via source and target branches