1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test process-accepted.py"""
from cStringIO import StringIO
from debian.deb822 import Changes
from testtools.matchers import LessThan
from canonical.config import config
from canonical.launchpad.webapp.errorlog import ErrorReportingUtility
from canonical.testing.layers import LaunchpadZopelessLayer
from lp.registry.interfaces.series import SeriesStatus
from lp.services.log.logger import BufferLogger
from lp.soyuz.enums import (
ArchivePurpose,
PackagePublishingStatus,
PackageUploadStatus,
)
from lp.soyuz.scripts.processaccepted import (
get_bugs_from_changes_file,
ProcessAccepted,
)
from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
from lp.testing import TestCaseWithFactory
class TestProcessAccepted(TestCaseWithFactory):
layer = LaunchpadZopelessLayer
dbuser = config.uploadqueue.dbuser
def setUp(self):
"""Create the Soyuz test publisher."""
TestCaseWithFactory.setUp(self)
self.stp = SoyuzTestPublisher()
self.stp.prepareBreezyAutotest()
self.test_package_name = "accept-test"
self.distro = self.factory.makeDistribution()
def getScript(self, test_args=None):
"""Return a ProcessAccepted instance."""
if test_args is None:
test_args = []
test_args.append(self.distro.name)
script = ProcessAccepted("process accepted", test_args=test_args)
script.logger = BufferLogger()
script.txn = self.layer.txn
return script
def createWaitingAcceptancePackage(self, distroseries, archive=None,
sourcename=None):
"""Create some pending publications."""
if archive is None:
archive = self.distro.main_archive
if sourcename is None:
sourcename = self.test_package_name
return self.stp.getPubSource(
archive=archive, sourcename=sourcename, distroseries=distroseries,
spr_only=True)
def test_robustness(self):
"""Test that a broken package doesn't block the publication of other
packages."""
# Attempt to upload one source to a supported series
# The record is created first and then the status of the series
# is changed from DEVELOPMENT to SUPPORTED, otherwise it's impossible
# to create the record
distroseries = self.factory.makeDistroSeries(distribution=self.distro)
broken_source = self.createWaitingAcceptancePackage(
distroseries=distroseries, sourcename="notaccepted")
distroseries.status = SeriesStatus.SUPPORTED
# Also upload some other things
other_distroseries = self.factory.makeDistroSeries(
distribution=self.distro)
other_source = self.createWaitingAcceptancePackage(
distroseries=other_distroseries)
script = self.getScript([])
self.layer.txn.commit()
self.layer.switchDbUser(self.dbuser)
script.main()
# The other source should be published now
published_main = self.distro.main_archive.getPublishedSources(
name=self.test_package_name)
self.assertEqual(published_main.count(), 1)
# And an oops should be filed for the first
error_utility = ErrorReportingUtility()
error_report = error_utility.getLastOopsReport()
fp = StringIO()
error_report.write(fp)
error_text = fp.getvalue()
expected_error = "error-explanation=Failure processing queue_item"
self.assertTrue(expected_error in error_text)
def test_accept_copy_archives(self):
"""Test that publications in a copy archive are accepted properly."""
# Upload some pending packages in a copy archive.
distroseries = self.factory.makeDistroSeries(distribution=self.distro)
copy_archive = self.factory.makeArchive(
distribution=self.distro, purpose=ArchivePurpose.COPY)
copy_source = self.createWaitingAcceptancePackage(
archive=copy_archive, distroseries=distroseries)
# Also upload some stuff in the main archive.
main_source = self.createWaitingAcceptancePackage(
distroseries=distroseries)
# Before accepting, the package should not be published at all.
published_copy = copy_archive.getPublishedSources(
name=self.test_package_name)
# Using .count() until Storm fixes __nonzero__ on SQLObj result
# sets, then we can use bool() which is far more efficient than
# counting.
self.assertEqual(published_copy.count(), 0)
# Accept the packages.
script = self.getScript(['--copy-archives'])
self.layer.txn.commit()
self.layer.switchDbUser(self.dbuser)
script.main()
# Packages in main archive should not be accepted and published.
published_main = self.distro.main_archive.getPublishedSources(
name=self.test_package_name)
self.assertEqual(published_main.count(), 0)
# Check the copy archive source was accepted.
published_copy = copy_archive.getPublishedSources(
name=self.test_package_name).one()
self.assertEqual(
published_copy.status, PackagePublishingStatus.PENDING)
self.assertEqual(copy_source, published_copy.sourcepackagerelease)
def test_commits_after_each_item(self):
# Test that the script commits after each item, not just at the end.
uploads = [
self.createWaitingAcceptancePackage(
distroseries=
self.factory.makeDistroSeries(distribution=self.distro),
sourcename='source%d' % i)
for i in range(3)]
class UploadCheckingSynchronizer:
commit_count = 0
def beforeCompletion(inner_self, txn):
pass
def afterCompletion(inner_self, txn):
if txn.status != 'Committed':
return
inner_self.commit_count += 1
done_count = len([
upload for upload in uploads
if upload.package_upload.status ==
PackageUploadStatus.DONE])
self.assertEqual(
min(len(uploads), inner_self.commit_count),
done_count)
script = self.getScript([])
self.layer.txn.commit()
self.layer.switchDbUser(self.dbuser)
synch = UploadCheckingSynchronizer()
script.txn.registerSynch(synch)
script.main()
self.assertThat(len(uploads), LessThan(synch.commit_count))
class TestBugsFromChangesFile(TestCaseWithFactory):
"""Test get_bugs_from_changes_file."""
layer = LaunchpadZopelessLayer
dbuser = config.uploadqueue.dbuser
def setUp(self):
super(TestBugsFromChangesFile, self).setUp()
self.changes = Changes({
'Format': '1.8',
'Source': 'swat',
})
def getBugs(self):
"""Serialize self.changes and use get_bugs_from_changes_file to
extract bugs from it.
"""
stream = StringIO()
self.changes.dump(stream)
stream.seek(0)
return get_bugs_from_changes_file(stream)
def test_no_bugs(self):
# An empty list is returned if there are no bugs
# mentioned.
self.assertEquals([], self.getBugs())
def test_invalid_bug_id(self):
# Invalid bug ids (i.e. containing non-digit characters) are ignored.
self.changes["Launchpad-Bugs-Fixed"] = "bla"
self.assertEquals([], self.getBugs())
def test_unknown_bug_id(self):
# Unknown bug ids are ignored.
self.changes["Launchpad-Bugs-Fixed"] = "45120"
self.assertEquals([], self.getBugs())
def test_valid_bug(self):
# For valid bug ids the bug object is returned.
bug = self.factory.makeBug()
self.changes["Launchpad-Bugs-Fixed"] = "%d" % bug.id
self.assertEquals([bug], self.getBugs())
def test_case_sensitivity(self):
# The spelling of Launchpad-Bugs-Fixed is case-insensitive.
bug = self.factory.makeBug()
self.changes["LaUnchpad-Bugs-fixed"] = "%d" % bug.id
self.assertEquals([bug], self.getBugs())
def test_multiple_bugs(self):
# Multiple bug ids can be specified, separated by spaces.
bug1 = self.factory.makeBug()
bug2 = self.factory.makeBug()
self.changes["Launchpad-Bugs-Fixed"] = "%d invalid %d" % (
bug1.id, bug2.id)
self.assertEquals([bug1, bug2], self.getBugs())
|