~launchpad-pqm/launchpad/devel

13233.1.1 by Jeroen Vermeulen
Lint.
1
DIST-UPGRADE upload
2
===================
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
3
4
This test will check the upload of dist-upgrade tarballs
5
13233.1.1 by Jeroen Vermeulen
Lint.
6
    >>> from lp.registry.interfaces.distribution import IDistributionSet
7
8
    >>> from lp.archiveuploader.nascentupload import NascentUpload
9
    >>> from lp.archiveuploader.tests import datadir, getPolicy
10
11
    >>> ubuntutest = getUtility(IDistributionSet)['ubuntutest']
12
    >>> breezy_autotest = ubuntutest['breezy-autotest']
13
14
    >>> from canonical.launchpad.ftests import import_public_test_keys
15
    >>> import_public_test_keys()
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
16
17
Login as an admin.
18
13233.1.1 by Jeroen Vermeulen
Lint.
19
    >>> login('foo.bar@canonical.com')
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
20
3147.2.54 by Celso Providelo
Fix corner-cases for dist-upgrader uploads workflow, add tests
21
First, test the rejection of a missapplied changesfile name:
22
13233.1.1 by Jeroen Vermeulen
Lint.
23
    >>> sync_policy = getPolicy(
24
    ...     name='sync', distro='ubuntutest', distroseries=None)
3804.1.24 by Celso Providelo
fix doc/distroreleasequeue* tests.
25
13233.1.1 by Jeroen Vermeulen
Lint.
26
    >>> from lp.services.log.logger import FakeLogger
27
    >>> upload = NascentUpload.from_changesfile_path(
28
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120.changes'),
29
    ...     sync_policy, FakeLogger())
30
    DEBUG dist-upgrader_20060302.0120.changes can be unsigned.
31
    >>> upload.process()
32
    Traceback (most recent call last):
33
    ...
34
    EarlyReturnUploadError: An error occurred that prevented further
35
    processing.
3147.2.54 by Celso Providelo
Fix corner-cases for dist-upgrader uploads workflow, add tests
36
37
Now do a proper upload into the system.
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
38
13233.1.1 by Jeroen Vermeulen
Lint.
39
    >>> insecure_policy = getPolicy(
40
    ...     name='insecure', distro='ubuntutest', distroseries=None)
41
42
    >>> upload = NascentUpload.from_changesfile_path(
43
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120_all.changes'),
44
    ...     insecure_policy, FakeLogger())
45
    DEBUG Verifying signature on dist-upgrader_20060302.0120_all.changes
46
47
    >>> upload.process()
48
    DEBUG Beginning processing.
49
    DEBUG Verifying the changes file.
50
    DEBUG Verifying files in upload.
51
    DEBUG Single Custom Upload detected.
52
    DEBUG Finished checking upload.
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
53
54
It was not rejected.
55
13233.1.1 by Jeroen Vermeulen
Lint.
56
    >>> upload.is_rejected
57
    False
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
58
13233.1.1 by Jeroen Vermeulen
Lint.
59
    >>> success = upload.do_accept()
60
    DEBUG Creating queue entry
61
    DEBUG Setting it to ACCEPTED
62
    DEBUG Building recipients list.
14168.3.6 by Jeroen Vermeulen
Changes after second round of tests.
63
    ...
13233.1.1 by Jeroen Vermeulen
Lint.
64
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
65
    DEBUG Sent a mail:
66
    ...
67
    DEBUG signer of the above package.
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
68
69
And all things worked.
70
13233.1.1 by Jeroen Vermeulen
Lint.
71
    >>> success
72
    True
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
73
13233.1.1 by Jeroen Vermeulen
Lint.
74
    >>> print upload.rejection_message
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
75
76
We need to commit the transaction to be able to use the librarian files.
3691.57.42 by Stuart Bishop
More post review feedback updates
77
XXX: flush_database_updates() shouldn't be needed. This seems to be
78
Bug 3989 -- StuarBishop 20060713
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
79
13233.1.1 by Jeroen Vermeulen
Lint.
80
    >>> flush_database_updates()
81
    >>> transaction.commit()
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
82
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
83
Let's check how queue tool handles dist_upgrader uploads:
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
84
13233.1.1 by Jeroen Vermeulen
Lint.
85
    >>> import subprocess
86
    >>> import os
87
    >>> import sys
88
    >>> from canonical.config import config
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
89
13233.1.1 by Jeroen Vermeulen
Lint.
90
    >>> script = os.path.join(
91
    ...     config.root, "scripts", "ftpmaster-tools", "queue")
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
92
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
93
94
Rejecting item from accepted queue (very unlikely, normally it would
3496.1.79 by Celso Providelo
apply review comments
95
be rejecting from unapproved or new, fix bug #54649):
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
96
13233.1.1 by Jeroen Vermeulen
Lint.
97
    >>> process = subprocess.Popen([
98
    ...     sys.executable, script,
99
    ...     "-Q", "accepted",
100
    ...     "-s", "breezy-autotest", "reject", "dist",
101
    ...     "-d", "ubuntutest", "-M"],
102
    ...     stderr=subprocess.PIPE,
103
    ...     stdout=subprocess.PIPE)
104
    >>> stdout, stderr = process.communicate()
105
    >>> process.returncode
106
    0
107
    >>> print stdout
108
    Initializing connection to queue accepted
109
    ...
110
    Rejecting dist-upgrader_20060302.0120_all.tar.gz
111
    ...
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
112
113
114
Accepting from rejected queue (ressurecting an reject upload is also
3496.1.79 by Celso Providelo
apply review comments
115
very unlikely, however it's only for testing purpose, fix #54649):
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
116
13233.1.1 by Jeroen Vermeulen
Lint.
117
    >>> process = subprocess.Popen([sys.executable, script, "-Q", "rejected",
118
    ...                             "-s", "breezy-autotest", "accept", "dist",
119
    ...                             "-d", "ubuntutest", "-M"],
120
    ...                            stderr=subprocess.PIPE,
121
    ...                            stdout=subprocess.PIPE)
122
    >>> stdout, stderr = process.communicate()
123
    >>> process.returncode
124
    0
125
    >>> print stdout
126
    Initializing connection to queue rejected
127
    ...
128
    Accepting dist-upgrader_20060302.0120_all.tar.gz
129
    ...
3496.1.77 by Celso Providelo
Fix #54649 (queue tool accept/reject for custom-only uploads).
130
131
132
Let's use the script to fetch the dist-upgrader upload:
133
13233.1.1 by Jeroen Vermeulen
Lint.
134
    >>> process = subprocess.Popen([sys.executable, script, "-Q", "accepted",
135
    ...                             "-s", "breezy-autotest", "fetch", "dist",
136
    ...                             "-d", "ubuntutest"],
137
    ...                            stdout=subprocess.PIPE)
138
    >>> stdout, stderr = process.communicate()
139
    >>> process.returncode
140
    0
141
    >>> print stdout
142
    Initializing connection to queue accepted
143
    Running: "fetch dist"
144
    Fetching ubuntutest/breezy-autotest (ACCEPTED) 1/1
145
    ---------------------------------------------------------------------------
146
    Constructing dist-upgrader_20060302.0120_all.changes
147
    Constructing dist-upgrader_20060302.0120_all.tar.gz
148
    ---------------------------------------------------------------------------
149
                                                                   1/1 total
150
    <BLANKLINE>
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
151
152
153
Check if the files were written:
154
13233.1.1 by Jeroen Vermeulen
Lint.
155
    >>> os.path.exists('dist-upgrader_20060302.0120_all.changes')
156
    True
157
    >>> os.path.exists('dist-upgrader_20060302.0120_all.tar.gz')
158
    True
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
159
160
Cleanup the mess:
161
13233.1.1 by Jeroen Vermeulen
Lint.
162
    >>> os.remove('dist-upgrader_20060302.0120_all.changes')
163
    >>> os.remove('dist-upgrader_20060302.0120_all.tar.gz')
3496.1.63 by Celso Providelo
Fix bug # 52595 (broken queue tool fetch of custom uploads), remove duplicated code of SPR/BPR_File content classes and fix # 51742 (queue tool fix reject announce email from non-LP valid address, replace empty To: by the Bcc:, always present)
164
165
3147.2.49 by Celso Providelo
Ensure custom are ACCEPTED, test fixes
166
Inspect the QUEUE looking for an ACCEPTED entry corresponding to the
3147.2.38 by Celso Providelo
CustomUpload goes to NEW and fix ordering on queue tables and multiplejoins.
167
previous upload:
168
13233.1.1 by Jeroen Vermeulen
Lint.
169
    >>> from lp.soyuz.enums import PackageUploadStatus
13233.2.7 by Jeroen Vermeulen
Kill getQueueItems.
170
    >>> queue_item = breezy_autotest.getPackageUploads(
13233.1.1 by Jeroen Vermeulen
Lint.
171
    ...      status=PackageUploadStatus.ACCEPTED)[0]
172
    >>> queue_item.customfiles[0].libraryfilealias.filename
173
    u'dist-upgrader_20060302.0120_all.tar.gz'
3147.2.38 by Celso Providelo
CustomUpload goes to NEW and fix ordering on queue tables and multiplejoins.
174
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
175
Do the publish, i.e process the CustomUpload writing the tarball in
4092.2.19 by Barry Warsaw
Because these tests also do custom uploads, they need to ensure the umask is
176
the archive.  The umask must be 022 in order to perform the upload.
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
177
13233.1.1 by Jeroen Vermeulen
Lint.
178
    >>> old_mask = os.umask(022)
179
    >>> pub_records = queue_item.realiseUpload()
180
    >>> print '%03o' % os.umask(old_mask)
181
    022
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
182
183
Check what was published in the target directory:
184
13233.1.1 by Jeroen Vermeulen
Lint.
185
    >>> import os
186
    >>> archive_dir = '/var/tmp/archive/'
187
    >>> upgrade_dir = (
188
    ...     'ubuntutest/dists/breezy-autotest/main/dist-upgrader-all')
189
    >>> target_dir = os.path.join(archive_dir, upgrade_dir)
190
    >>> content = sorted(os.listdir(target_dir))
191
    >>> content
192
    ['20060302.0120', 'current']
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
193
194
Check the content of the directories published and the integrity of
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
195
the 'current' symbolic link.
196
13233.1.1 by Jeroen Vermeulen
Lint.
197
    >>> real_path = os.path.join(target_dir, '20060302.0120')
198
    >>> current_path = os.path.join(target_dir, 'current')
199
200
    >>> os.path.islink(current_path)
201
    True
202
203
    >>> os.path.join(target_dir, os.readlink(current_path)) == real_path
204
    True
205
206
    >>> sorted(os.listdir(real_path))
207
    ['ReleaseAnouncement', 'dapper.tar.gz']
208
209
210
Pre-publication version checks
211
------------------------------
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
212
3838.1.10 by Celso Providelo
Improve documentation and tests.
213
Dist-Upgrader version is checked before installing any files in the
214
archive.
215
216
If any problem happen during the custom publication, the error will be
217
printed and the queue item will remain in ACCEPTED queue waiting for
218
manual intervention.
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
219
13233.1.1 by Jeroen Vermeulen
Lint.
220
    >>> insecure_policy = getPolicy(
221
    ...     name='insecure', distro='ubuntutest', distroseries=None)
222
223
    >>> upload = NascentUpload.from_changesfile_path(
224
    ...     datadir('dist-upgrader/dist-upgrader_20070219.1234_all.changes'),
225
    ...     insecure_policy, FakeLogger())
226
    DEBUG Verifying signature on dist-upgrader_20070219.1234_all.changes
227
228
    >>> upload.process()
229
    DEBUG Beginning processing.
230
    DEBUG Verifying the changes file.
231
    DEBUG Verifying files in upload.
232
    DEBUG Single Custom Upload detected.
233
    DEBUG Finished checking upload.
234
235
    >>> success = upload.do_accept()
236
    DEBUG Creating queue entry
237
    DEBUG Setting it to ACCEPTED
238
    DEBUG Building recipients list.
14168.3.6 by Jeroen Vermeulen
Changes after second round of tests.
239
    ...
13233.1.1 by Jeroen Vermeulen
Lint.
240
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
241
    DEBUG Sent a mail:
242
    ...
243
    DEBUG signer of the above package.
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
244
245
Make the just-uploaded librarian file visible:
246
13233.1.1 by Jeroen Vermeulen
Lint.
247
    >>> transaction.commit()
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
248
3838.1.10 by Celso Providelo
Improve documentation and tests.
249
Check current archive status:
250
13233.1.1 by Jeroen Vermeulen
Lint.
251
    >>> previous_content = sorted(os.listdir(target_dir))
252
    >>> previous_content
253
    ['20060302.0120', 'current']
3838.1.10 by Celso Providelo
Improve documentation and tests.
254
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
255
Publish the custom upload:
256
13233.1.1 by Jeroen Vermeulen
Lint.
257
    >>> pub_records = upload.queue_root.realiseUpload(FakeLogger())
258
    DEBUG Publishing custom dist-upgrader_20070219.1234_all.tar.gz to
259
    ubuntutest/breezy-autotest
260
    ERROR Queue item ignored: bad version found in
261
    '.../dist-upgrader_20070219.1234_all.tar.gz': Could not parse version: Bad
262
    upstream version format foobar
3838.1.10 by Celso Providelo
Improve documentation and tests.
263
264
Check if the queue item remained in ACCEPTED and not cruft was
265
inserted in the archive:
266
13233.1.1 by Jeroen Vermeulen
Lint.
267
    >>> upload.queue_root.status.name
268
    'ACCEPTED'
3838.2.1 by Celso Providelo
sanitize dist-upgrader test files before landing the bug fix.
269
13233.1.1 by Jeroen Vermeulen
Lint.
270
    >>> content = sorted(os.listdir(target_dir))
271
    >>> content == previous_content
272
    True
3147.2.37 by Celso Providelo
DistUpgraderUpload implementation and fixing some tests
273
274
Remove the directory to keep the test working.
275
13233.1.1 by Jeroen Vermeulen
Lint.
276
    >>> import shutil
277
    >>> shutil.rmtree(target_dir)
278
279
280
Dist Upgrader to PPA
281
--------------------
3691.443.33 by Celso Providelo
Fix custom upload publications for PPA.
282
3691.443.36 by Celso Providelo
missing comments
283
Custom uploads for PPAs should works as expected, i.e, publish its
284
files in the respective PPA location.
285
13233.1.1 by Jeroen Vermeulen
Lint.
286
    >>> from lp.registry.interfaces.person import IPersonSet
287
    >>> from lp.soyuz.enums import ArchivePurpose
288
    >>> from lp.soyuz.interfaces.archive import IArchiveSet
289
13479.3.3 by William Grant
Fix tests.
290
    >>> name16 = getUtility(IPersonSet).getByName("name16")
13233.1.1 by Jeroen Vermeulen
Lint.
291
    >>> foobar_archive = getUtility(IArchiveSet).new(
292
    ...     distribution=ubuntutest, purpose=ArchivePurpose.PPA,
293
    ...     owner=name16)
294
295
    >>> insecure_policy.archive = foobar_archive
296
297
    >>> ppa_upload = NascentUpload.from_changesfile_path(
298
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120_all.changes'),
299
    ...     insecure_policy, FakeLogger())
300
    DEBUG Verifying signature on dist-upgrader_20060302.0120_all.changes
301
302
    >>> ppa_upload.process()
303
    DEBUG Beginning processing.
304
    DEBUG Verifying the changes file.
305
    DEBUG Verifying files in upload.
306
    DEBUG Single Custom Upload detected.
307
    DEBUG Finished checking upload.
308
309
    >>> success = ppa_upload.do_accept()
310
    DEBUG Creating queue entry
311
    DEBUG Setting it to ACCEPTED
312
    DEBUG Building recipients list.
313
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
314
    DEBUG Sent a mail:
315
    ...
316
    DEBUG PPA package.
317
318
    >>> transaction.commit()
4414.2.1 by Barry Warsaw
Uploads are umask dependent. This fixes the realiseUpload() call to ensure
319
320
The upload task requires that the umask be 022, otherwise things will end up
321
with the wrong permission.
322
13233.1.1 by Jeroen Vermeulen
Lint.
323
    >>> old_mask = os.umask(022)
324
    >>> pub_records = ppa_upload.queue_root.realiseUpload(FakeLogger())
325
    DEBUG Publishing custom dist-upgrader_20060302.0120_all.tar.gz to
326
    ubuntutest/breezy-autotest
327
    >>> ignore = os.umask(old_mask)
3691.443.33 by Celso Providelo
Fix custom upload publications for PPA.
328
13233.1.1 by Jeroen Vermeulen
Lint.
329
    >>> ppa_root = config.personalpackagearchive.root
330
    >>> ppa_dir = os.path.join(ppa_root, 'name16', 'ppa')
331
    >>> target_dir = os.path.join(ppa_dir, upgrade_dir)
332
    >>> content = sorted(os.listdir(target_dir))
333
    >>> content
334
    ['20060302.0120', 'current']
3691.443.33 by Celso Providelo
Fix custom upload publications for PPA.
335
3691.443.38 by Celso Providelo
applying review comments
336
Remove the directory to keep the test working.
337
13233.1.1 by Jeroen Vermeulen
Lint.
338
    >>> import shutil
339
    >>> shutil.rmtree(target_dir)