~launchpad-pqm/launchpad/devel

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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
DIST-UPGRADE upload
===================

This test will check the upload of dist-upgrade tarballs

    >>> from lp.registry.interfaces.distribution import IDistributionSet

    >>> from lp.archiveuploader.nascentupload import NascentUpload
    >>> from lp.archiveuploader.tests import datadir, getPolicy

    >>> ubuntutest = getUtility(IDistributionSet)['ubuntutest']
    >>> breezy_autotest = ubuntutest['breezy-autotest']

    >>> from lp.testing.gpgkeys import import_public_test_keys
    >>> import_public_test_keys()

Login as an admin.

    >>> login('foo.bar@canonical.com')

First, test the rejection of a missapplied changesfile name:

    >>> sync_policy = getPolicy(
    ...     name='sync', distro='ubuntutest', distroseries=None)

    >>> from lp.services.log.logger import FakeLogger
    >>> upload = NascentUpload.from_changesfile_path(
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120.changes'),
    ...     sync_policy, FakeLogger())
    DEBUG dist-upgrader_20060302.0120.changes can be unsigned.
    >>> upload.process()
    Traceback (most recent call last):
    ...
    EarlyReturnUploadError: An error occurred that prevented further
    processing.

Now do a proper upload into the system.

    >>> insecure_policy = getPolicy(
    ...     name='insecure', distro='ubuntutest', distroseries=None)

    >>> upload = NascentUpload.from_changesfile_path(
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120_all.changes'),
    ...     insecure_policy, FakeLogger())
    DEBUG Verifying signature on dist-upgrader_20060302.0120_all.changes

    >>> upload.process()
    DEBUG Beginning processing.
    DEBUG Verifying the changes file.
    DEBUG Verifying files in upload.
    DEBUG Single Custom Upload detected.
    DEBUG Finished checking upload.

It was not rejected.

    >>> upload.is_rejected
    False

    >>> success = upload.do_accept()
    DEBUG Creating queue entry
    DEBUG Setting it to ACCEPTED
    DEBUG Building recipients list.
    ...
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
    DEBUG Sent a mail:
    ...
    DEBUG signer of the above package.

And all things worked.

    >>> success
    True

    >>> print upload.rejection_message

We need to commit the transaction to be able to use the librarian files.
XXX: flush_database_updates() shouldn't be needed. This seems to be
Bug 3989 -- StuarBishop 20060713

    >>> flush_database_updates()
    >>> transaction.commit()

Let's check how queue tool handles dist_upgrader uploads:

    >>> import subprocess
    >>> import os
    >>> import sys
    >>> from lp.services.config import config

    >>> script = os.path.join(
    ...     config.root, "scripts", "ftpmaster-tools", "queue")


Rejecting item from accepted queue (very unlikely, normally it would
be rejecting from unapproved or new, fix bug #54649):

    >>> process = subprocess.Popen([
    ...     sys.executable, script,
    ...     "-Q", "accepted",
    ...     "-s", "breezy-autotest", "reject", "dist",
    ...     "-d", "ubuntutest", "-M"],
    ...     stderr=subprocess.PIPE,
    ...     stdout=subprocess.PIPE)
    >>> stdout, stderr = process.communicate()
    >>> process.returncode
    0
    >>> print stdout
    Initializing connection to queue accepted
    ...
    Rejecting dist-upgrader_20060302.0120_all.tar.gz
    ...


Accepting from rejected queue (ressurecting an reject upload is also
very unlikely, however it's only for testing purpose, fix #54649):

    >>> process = subprocess.Popen([sys.executable, script, "-Q", "rejected",
    ...                             "-s", "breezy-autotest", "accept", "dist",
    ...                             "-d", "ubuntutest", "-M"],
    ...                            stderr=subprocess.PIPE,
    ...                            stdout=subprocess.PIPE)
    >>> stdout, stderr = process.communicate()
    >>> process.returncode
    0
    >>> print stdout
    Initializing connection to queue rejected
    ...
    Accepting dist-upgrader_20060302.0120_all.tar.gz
    ...


Let's use the script to fetch the dist-upgrader upload:

    >>> process = subprocess.Popen([sys.executable, script, "-Q", "accepted",
    ...                             "-s", "breezy-autotest", "fetch", "dist",
    ...                             "-d", "ubuntutest"],
    ...                            stdout=subprocess.PIPE)
    >>> stdout, stderr = process.communicate()
    >>> process.returncode
    0
    >>> print stdout
    Initializing connection to queue accepted
    Running: "fetch dist"
    Fetching ubuntutest/breezy-autotest (ACCEPTED) 1/1
    ---------------------------------------------------------------------------
    Constructing dist-upgrader_20060302.0120_all.changes
    Constructing dist-upgrader_20060302.0120_all.tar.gz
    ---------------------------------------------------------------------------
                                                                   1/1 total
    <BLANKLINE>


Check if the files were written:

    >>> os.path.exists('dist-upgrader_20060302.0120_all.changes')
    True
    >>> os.path.exists('dist-upgrader_20060302.0120_all.tar.gz')
    True

Cleanup the mess:

    >>> os.remove('dist-upgrader_20060302.0120_all.changes')
    >>> os.remove('dist-upgrader_20060302.0120_all.tar.gz')


Inspect the QUEUE looking for an ACCEPTED entry corresponding to the
previous upload:

    >>> from lp.soyuz.enums import PackageUploadStatus
    >>> queue_item = breezy_autotest.getPackageUploads(
    ...      status=PackageUploadStatus.ACCEPTED)[0]
    >>> queue_item.customfiles[0].libraryfilealias.filename
    u'dist-upgrader_20060302.0120_all.tar.gz'

Do the publish, i.e process the CustomUpload writing the tarball in
the archive.  The umask must be 022 in order to perform the upload.

    >>> old_mask = os.umask(022)
    >>> pub_records = queue_item.realiseUpload()
    >>> print '%03o' % os.umask(old_mask)
    022

Check what was published in the target directory:

    >>> import os
    >>> archive_dir = '/var/tmp/archive/'
    >>> upgrade_dir = (
    ...     'ubuntutest/dists/breezy-autotest/main/dist-upgrader-all')
    >>> target_dir = os.path.join(archive_dir, upgrade_dir)
    >>> content = sorted(os.listdir(target_dir))
    >>> content
    ['20060302.0120', 'current']

Check the content of the directories published and the integrity of
the 'current' symbolic link.

    >>> real_path = os.path.join(target_dir, '20060302.0120')
    >>> current_path = os.path.join(target_dir, 'current')

    >>> os.path.islink(current_path)
    True

    >>> os.path.join(target_dir, os.readlink(current_path)) == real_path
    True

    >>> sorted(os.listdir(real_path))
    ['ReleaseAnouncement', 'dapper.tar.gz']


Pre-publication version checks
------------------------------

Dist-Upgrader version is checked before installing any files in the
archive.

If any problem happen during the custom publication, the error will be
printed and the queue item will remain in ACCEPTED queue waiting for
manual intervention.

    >>> insecure_policy = getPolicy(
    ...     name='insecure', distro='ubuntutest', distroseries=None)

    >>> upload = NascentUpload.from_changesfile_path(
    ...     datadir('dist-upgrader/dist-upgrader_20070219.1234_all.changes'),
    ...     insecure_policy, FakeLogger())
    DEBUG Verifying signature on dist-upgrader_20070219.1234_all.changes

    >>> upload.process()
    DEBUG Beginning processing.
    DEBUG Verifying the changes file.
    DEBUG Verifying files in upload.
    DEBUG Single Custom Upload detected.
    DEBUG Finished checking upload.

    >>> success = upload.do_accept()
    DEBUG Creating queue entry
    DEBUG Setting it to ACCEPTED
    DEBUG Building recipients list.
    ...
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
    DEBUG Sent a mail:
    ...
    DEBUG signer of the above package.

Make the just-uploaded librarian file visible:

    >>> transaction.commit()

Check current archive status:

    >>> previous_content = sorted(os.listdir(target_dir))
    >>> previous_content
    ['20060302.0120', 'current']

Publish the custom upload:

    >>> pub_records = upload.queue_root.realiseUpload(FakeLogger())
    DEBUG Publishing custom dist-upgrader_20070219.1234_all.tar.gz to
    ubuntutest/breezy-autotest
    ERROR Queue item ignored: bad version found in
    '.../dist-upgrader_20070219.1234_all.tar.gz': Could not parse version: Bad
    upstream version format foobar

Check if the queue item remained in ACCEPTED and not cruft was
inserted in the archive:

    >>> upload.queue_root.status.name
    'ACCEPTED'

    >>> content = sorted(os.listdir(target_dir))
    >>> content == previous_content
    True

Remove the directory to keep the test working.

    >>> import shutil
    >>> shutil.rmtree(target_dir)


Dist Upgrader to PPA
--------------------

Custom uploads for PPAs should works as expected, i.e, publish its
files in the respective PPA location.

    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.soyuz.enums import ArchivePurpose
    >>> from lp.soyuz.interfaces.archive import IArchiveSet

    >>> name16 = getUtility(IPersonSet).getByName("name16")
    >>> foobar_archive = getUtility(IArchiveSet).new(
    ...     distribution=ubuntutest, purpose=ArchivePurpose.PPA,
    ...     owner=name16)

    >>> insecure_policy.archive = foobar_archive

    >>> ppa_upload = NascentUpload.from_changesfile_path(
    ...     datadir('dist-upgrader/dist-upgrader_20060302.0120_all.changes'),
    ...     insecure_policy, FakeLogger())
    DEBUG Verifying signature on dist-upgrader_20060302.0120_all.changes

    >>> ppa_upload.process()
    DEBUG Beginning processing.
    DEBUG Verifying the changes file.
    DEBUG Verifying files in upload.
    DEBUG Single Custom Upload detected.
    DEBUG Finished checking upload.

    >>> success = ppa_upload.do_accept()
    DEBUG Creating queue entry
    DEBUG Setting it to ACCEPTED
    DEBUG Building recipients list.
    DEBUG Adding recipient: 'Foo Bar <foo.bar@canonical.com>'
    DEBUG Sent a mail:
    ...
    DEBUG PPA package.

    >>> transaction.commit()

The upload task requires that the umask be 022, otherwise things will end up
with the wrong permission.

    >>> old_mask = os.umask(022)
    >>> pub_records = ppa_upload.queue_root.realiseUpload(FakeLogger())
    DEBUG Publishing custom dist-upgrader_20060302.0120_all.tar.gz to
    ubuntutest/breezy-autotest
    >>> ignore = os.umask(old_mask)

    >>> ppa_root = config.personalpackagearchive.root
    >>> ppa_dir = os.path.join(ppa_root, 'name16', 'ppa')
    >>> target_dir = os.path.join(ppa_dir, upgrade_dir)
    >>> content = sorted(os.listdir(target_dir))
    >>> content
    ['20060302.0120', 'current']

Remove the directory to keep the test working.

    >>> import shutil
    >>> shutil.rmtree(target_dir)