20
21
For further info about DDTP see:
21
22
https://wiki.ubuntu.com/TranslatedPackageDescriptionsSpec
23
>>> from lp.registry.interfaces.distribution import IDistributionSet
25
>>> ubuntutest = getUtility(IDistributionSet)['ubuntutest']
26
>>> breezy_autotest = ubuntutest['breezy-autotest']
28
>>> from lp.archiveuploader.nascentupload import NascentUpload
29
>>> from lp.archiveuploader.tests import datadir, getPolicy
31
>>> from canonical.launchpad.ftests import import_public_test_keys
32
>>> import_public_test_keys()
24
>>> from lp.registry.interfaces.distribution import IDistributionSet
26
>>> ubuntutest = getUtility(IDistributionSet)['ubuntutest']
27
>>> breezy_autotest = ubuntutest['breezy-autotest']
29
>>> from lp.archiveuploader.nascentupload import NascentUpload
30
>>> from lp.archiveuploader.tests import datadir, getPolicy
32
>>> from canonical.launchpad.ftests import import_public_test_keys
33
>>> import_public_test_keys()
34
35
Login as an admin (or ubuntutest.archive_admin if we have one), since
35
36
we need to access and modify PackageUpload records and other tables.
37
>>> login('foo.bar@canonical.com')
38
>>> login('foo.bar@canonical.com')
39
40
Set the email address for announcements:
41
>>> breezy_autotest.changeslist = 'test@example.com'
42
>>> breezy_autotest.changeslist = 'test@example.com'
43
44
First, test the rejection of a missapplied changesfile name, which
44
45
doesn't follow the accepted format, "<pkg>_<version>_<arch>.changes"
46
>>> sync_policy = getPolicy(
47
... name='sync', distro='ubuntutest', distroseries=None)
47
>>> sync_policy = getPolicy(
48
... name='sync', distro='ubuntutest', distroseries=None)
49
>>> from lp.services.log.logger import DevNullLogger
50
>>> upload = NascentUpload.from_changesfile_path(
51
... datadir('ddtp-tarball/translations-main_20060728.changes'),
52
... sync_policy, DevNullLogger())
54
Traceback (most recent call last):
56
EarlyReturnUploadError: An error occurred that prevented further processing.
50
>>> from lp.services.log.logger import DevNullLogger
51
>>> upload = NascentUpload.from_changesfile_path(
52
... datadir('ddtp-tarball/translations-main_20060728.changes'),
53
... sync_policy, DevNullLogger())
55
Traceback (most recent call last):
57
EarlyReturnUploadError: An error occurred that prevented further
58
60
Now do a proper upload into the system.
60
>>> insecure_policy = getPolicy(
61
... name='insecure', distro='ubuntutest', distroseries=None)
63
>>> from lp.services.log.logger import FakeLogger
64
>>> upload = NascentUpload.from_changesfile_path(
65
... datadir('ddtp-tarball/translations-main_20060728_all.changes'),
66
... insecure_policy, FakeLogger())
67
DEBUG Verifying signature on translations-main_20060728_all.changes
70
DEBUG Beginning processing.
71
DEBUG Verifying the changes file.
72
DEBUG Verifying files in upload.
73
DEBUG Single Custom Upload detected.
74
DEBUG Finished checking upload.
62
>>> insecure_policy = getPolicy(
63
... name='insecure', distro='ubuntutest', distroseries=None)
65
>>> from lp.services.log.logger import FakeLogger
66
>>> upload = NascentUpload.from_changesfile_path(
67
... datadir('ddtp-tarball/translations-main_20060728_all.changes'),
68
... insecure_policy, FakeLogger())
69
DEBUG Verifying signature on translations-main_20060728_all.changes
72
DEBUG Beginning processing.
73
DEBUG Verifying the changes file.
74
DEBUG Verifying files in upload.
75
DEBUG Single Custom Upload detected.
76
DEBUG Finished checking upload.
76
78
It was not rejected.
78
>>> upload.is_rejected
80
>>> upload.is_rejected
81
>>> success = upload.do_accept()
82
DEBUG Creating queue entry
85
DEBUG Subject: [ubuntutest/breezy-autotest] translations_main_20060728.tar.gz - (Accepted)
86
DEBUG Sender: Root <root@localhost>
87
DEBUG Recipients: Foo Bar <foo.bar@canonical.com>
88
DEBUG Bcc: Root <root@localhost>
94
DEBUG Date: Thu, 01 Aug 2006 14:20:25 +0300
95
DEBUG Changed-By: Foo Bar <foo.bar@canonical.com>
96
DEBUG Origin: Ubuntu/warty
101
DEBUG Announcing to test@example.com
103
DEBUG Thank you for your contribution to Ubuntu Test.
106
DEBUG You are receiving this email because you are the uploader, maintainer or
107
DEBUG signer of the above package.
109
DEBUG Subject: [ubuntutest/breezy-autotest] translations_main_20060728.tar.gz - (Accepted)
110
DEBUG Sender: Foo Bar <foo.bar@canonical.com>
111
DEBUG Recipients: test@example.com
112
DEBUG Bcc: Root <root@localhost>
118
DEBUG Date: Thu, 01 Aug 2006 14:20:25 +0300
119
DEBUG Changed-By: Foo Bar <foo.bar@canonical.com>
120
DEBUG Origin: Ubuntu/warty
83
>>> success = upload.do_accept()
84
DEBUG Creating queue entry
87
DEBUG Subject: [ubuntutest/breezy-autotest]
88
translations_main_20060728.tar.gz - (Accepted)
89
DEBUG Sender: Root <root@localhost>
90
DEBUG Recipients: Foo Bar <foo.bar@canonical.com>
91
DEBUG Bcc: Root <root@localhost>
97
DEBUG Date: Thu, 01 Aug 2006 14:20:25 +0300
98
DEBUG Changed-By: Foo Bar <foo.bar@canonical.com>
99
DEBUG Origin: Ubuntu/warty
104
DEBUG Announcing to test@example.com
106
DEBUG Thank you for your contribution to Ubuntu Test.
109
DEBUG You are receiving this email because you are the uploader,
111
DEBUG signer of the above package.
113
DEBUG Subject: [ubuntutest/breezy-autotest]
114
translations_main_20060728.tar.gz - (Accepted)
115
DEBUG Sender: Foo Bar <foo.bar@canonical.com>
116
DEBUG Recipients: test@example.com
117
DEBUG Bcc: Root <root@localhost>
123
DEBUG Date: Thu, 01 Aug 2006 14:20:25 +0300
124
DEBUG Changed-By: Foo Bar <foo.bar@canonical.com>
125
DEBUG Origin: Ubuntu/warty
123
128
And all things worked.
128
>>> not upload.rejection_message
133
>>> not upload.rejection_message
131
136
We need to commit the transaction to be able to use the librarian files.
133
>>> flush_database_updates()
134
>>> transaction.commit()
138
>>> flush_database_updates()
139
>>> transaction.commit()
136
141
Let's use the script to fetch the ddtp-tarball upload:
138
>>> import subprocess
141
>>> from canonical.config import config
143
>>> script = os.path.join(
144
... config.root, "scripts", "ftpmaster-tools", "queue")
146
>>> process = subprocess.Popen([sys.executable, script, "-Q", "accepted",
147
... "-s", "breezy-autotest", "fetch", "trans",
148
... "-d", "ubuntutest"],
149
... stdout=subprocess.PIPE)
150
>>> stdout, stderr = process.communicate()
151
>>> process.returncode
154
Initializing connection to queue accepted
155
Running: "fetch trans"
156
Fetching ubuntutest/breezy-autotest (ACCEPTED) 1/1
157
---------------------------------------------------------------------------
158
Constructing translations-main_20060728_all.changes
159
Constructing translations_main_20060728.tar.gz
160
---------------------------------------------------------------------------
143
>>> import subprocess
146
>>> from canonical.config import config
148
>>> script = os.path.join(
149
... config.root, "scripts", "ftpmaster-tools", "queue")
151
>>> process = subprocess.Popen([sys.executable, script, "-Q", "accepted",
152
... "-s", "breezy-autotest", "fetch", "trans",
153
... "-d", "ubuntutest"],
154
... stdout=subprocess.PIPE)
155
>>> stdout, stderr = process.communicate()
156
>>> process.returncode
159
Initializing connection to queue accepted
160
Running: "fetch trans"
161
Fetching ubuntutest/breezy-autotest (ACCEPTED) 1/1
162
---------------------------------------------------------------------------
163
Constructing translations-main_20060728_all.changes
164
Constructing translations_main_20060728.tar.gz
165
---------------------------------------------------------------------------
164
169
Check if the files were written:
166
>>> os.path.exists('translations-main_20060728_all.changes')
168
>>> os.path.exists('translations_main_20060728.tar.gz')
171
>>> os.path.exists('translations-main_20060728_all.changes')
173
>>> os.path.exists('translations_main_20060728.tar.gz')
171
176
Cleanup the mess:
173
>>> os.remove('translations-main_20060728_all.changes')
174
>>> os.remove('translations_main_20060728.tar.gz')
178
>>> os.remove('translations-main_20060728_all.changes')
179
>>> os.remove('translations_main_20060728.tar.gz')
177
182
Inspect the QUEUE looking for an ACCEPTED entry corresponding to the
180
>>> from lp.soyuz.enums import PackageUploadStatus
181
>>> queue_item = breezy_autotest.getQueueItems(
182
... status=PackageUploadStatus.ACCEPTED)[0]
183
>>> queue_item.customfiles[0].libraryfilealias.filename
184
u'translations_main_20060728.tar.gz'
185
>>> from lp.soyuz.enums import PackageUploadStatus
186
>>> queue_item = breezy_autotest.getQueueItems(
187
... status=PackageUploadStatus.ACCEPTED)[0]
188
>>> queue_item.customfiles[0].libraryfilealias.filename
189
u'translations_main_20060728.tar.gz'
186
191
Do the publish, i.e process the CustomUpload decompressing and writing
187
192
the tarball contents in the archive, collect and check debug message:
189
194
The umask must be 022 in order to perform the upload.
191
>>> old_mask = os.umask(022)
192
>>> pub_records = queue_item.realiseUpload(FakeLogger())
193
DEBUG Publishing custom translations_main_20060728.tar.gz to ubuntutest/breezy-autotest
194
>>> print '%03o' % os.umask(old_mask)
196
>>> old_mask = os.umask(022)
197
>>> pub_records = queue_item.realiseUpload(FakeLogger())
198
DEBUG Publishing custom translations_main_20060728.tar.gz to
199
ubuntutest/breezy-autotest
200
>>> print '%03o' % os.umask(old_mask)
197
203
Check what was published in the target directory:
200
>>> archive_dir = '/var/tmp/archive/'
206
>>> archive_dir = '/var/tmp/archive/'
202
208
DDTP indexes are published in the "i18n" directory inside archive dists:
204
>>> upgrade_dir = 'ubuntutest/dists/breezy-autotest/main/i18n'
205
>>> target_dir = os.path.join(archive_dir, upgrade_dir)
210
>>> upgrade_dir = 'ubuntutest/dists/breezy-autotest/main/i18n'
211
>>> target_dir = os.path.join(archive_dir, upgrade_dir)
207
213
We simply decompress the contents of the tarball, the files follow
255
261
Create a hard link to "bn" package file.
257
>>> src = os.path.join(target_dir, 'Translation-ca')
258
>>> dest = os.path.join(target_dir, 'Translation-bn')
260
>>> os.link(src, dest)
263
>>> src = os.path.join(target_dir, 'Translation-ca')
264
>>> dest = os.path.join(target_dir, 'Translation-bn')
266
>>> os.link(src, dest)
262
>>> os.path.exists(dest)
264
>>> os.stat(dest).st_nlink
266
>>> os.stat(src).st_nlink
268
>>> os.path.exists(dest)
270
>>> os.stat(dest).st_nlink
272
>>> os.stat(src).st_nlink
270
276
Retrieve and publish new custom upload:
272
>>> queue_item = breezy_autotest.getQueueItems(
273
... status=PackageUploadStatus.ACCEPTED)[0]
278
>>> queue_item = breezy_autotest.getQueueItems(
279
... status=PackageUploadStatus.ACCEPTED)[0]
275
>>> pub_records = queue_item.realiseUpload()
281
>>> pub_records = queue_item.realiseUpload()
278
284
Check if there is new content for "bn" index:
280
>>> dir_list = os.listdir(target_dir)
281
>>> for filename in sorted(dir_list):
282
... content = open(os.path.join(target_dir, filename), 'rb').read()
283
... print filename, len(content)
286
>>> dir_list = os.listdir(target_dir)
287
>>> for filename in sorted(dir_list):
288
... content = open(os.path.join(target_dir, filename), 'rb').read()
289
... print filename, len(content)
290
296
Check if the contents of "ca" were not affected by the "bn" contents
291
297
(this would happen if "bn" was not removed, left as hard link):
293
>>> open(os.path.join(target_dir, 'Translation-bn')).read()
294
'hardlinks are bad !!!\n'
299
>>> open(os.path.join(target_dir, 'Translation-bn')).read()
300
'hardlinks are bad !!!\n'
296
>>> open(os.path.join(target_dir, 'Translation-ca')).read()
302
>>> open(os.path.join(target_dir, 'Translation-ca')).read()
299
305
Remove the directory to keep the test working.
302
>>> shutil.rmtree(target_dir)
308
>>> shutil.rmtree(target_dir)