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
|
= Manage-Chroot Tool =
This tool is used to add or update chroots for suites (distroseries)
and DistroArchSeries.
Chroots are compressed files which contains a pristine ubuntu
work-tree and are used to build packages. When Launchpad is requested
to build "foo in dapper/i386", it needs to use the respective chroot on
the builder.
This script is based on the IDistroArchSeries.addOrUpdateChroot
method, which is better tested in doc/pocketchroot.txt.
It allows the user to add, update, remove and get chroot files.
Setup the script runner:
>>> import subprocess
>>> import os
>>> import sys
>>> from lp.services.config import config
>>> script = os.path.join(config.root, "scripts", "ftpmaster-tools",
... "manage-chroot.py")
Create and populate a temporary file and pretend it is a chroot:
>>> import tempfile
>>> filepath = tempfile.mktemp()
>>> temp_fd = open(filepath, 'w')
>>> temp_fd.write('fooooooooooo baaaaaaaaaar')
>>> temp_fd.close()
Setup a function to return a ManageChrootScript object given some
parameters.
>>> from lp.services.log.logger import FakeLogger
>>> from lp.soyuz.scripts.ftpmaster import ManageChrootScript
>>> def getScriptObject(command, distribution='ubuntu', suite='hoary',
... arch='i386', filepath=filepath):
... test_args = ['-s', suite,
... '-d', distribution,
... '-a', arch,
... '-f', filepath,
... '-v',
... command]
...
... manage_chroot = ManageChrootScript(
... name='manage-chroot', test_args=test_args)
... manage_chroot.logger = FakeLogger()
... manage_chroot.setupLocation()
... return manage_chroot
We will execute the real script once using Popen to show that it exists
and is executable. After this first run, we'll call the script object
directly for speed (Popen is slow).
We can add a new chroot for ubuntu/hoary/i386 with the "add" command:
>>> process = subprocess.Popen([sys.executable, script, "-v", "add",
... "-d", "ubuntu",
... "-s", "hoary",
... "-a", "i386",
... "-f", filepath],
... stdout=subprocess.PIPE,
... stderr=subprocess.PIPE,)
>>> stdout, stderr = process.communicate()
>>> process.returncode
0
>>> print stderr
INFO Creating lockfile: /var/lock/launchpad-mangage-chroot.lock
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
DEBUG LibraryFileAlias: ..., 25 bytes, 04a60337a417012f7c51fb56d59d2d0d
DEBUG PocketChroot for 'The Hoary Hedgehog Release for i386 (x86)' (1) added.
INFO Transaction committed.
INFO Success.
DEBUG Removing lock file...
<BLANKLINE>
Using an invalid command results in an error.
>>> from lp.soyuz.scripts.ftpmasterbase import (
... SoyuzScriptError)
>>> manage_chroot = getScriptObject("bogus")
>>> try:
... manage_chroot.mainTask()
... except SoyuzScriptError, info:
... print info
... else:
... print "Did not get expected exception"
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
ERROR Allowed actions: ['add', 'update', 'remove', 'get']
Unknown action: bogus
Specifiying a bad architecture results in an error.
>>> manage_chroot = getScriptObject("add", arch="bogus")
>>> try:
... manage_chroot.mainTask()
... except SoyuzScriptError, info:
... print info
... else:
... print "Did not get expected exception"
Architecture not found: u'Unknown architecture bogus for ubuntu hoary'
We can update the previous chroot with the "update" command:
(we'll use the same file, it doesn't matter for our purposes):
>>> manage_chroot = getScriptObject("update")
>>> manage_chroot.mainTask()
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
DEBUG LibraryFileAlias: ..., 25 bytes, 04a60337a417012f7c51fb56d59d2d0d
DEBUG PocketChroot for 'The Hoary Hedgehog Release for i386 (x86)' (1) updated.
Remove the temporary file created by this script
>>> os.remove(filepath)
Adding a chroot using a non-existent path will result in an error.
>>> filepath = os.path.join(config.root, "no-such-file")
>>> manage_chroot = getScriptObject("add", filepath=filepath)
>>> try:
... manage_chroot.mainTask()
... except SoyuzScriptError, info:
... print info
... else:
... print "Did not get expected exception"
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
Could not open: ...no-such-file
Commit the work done so far so the librarian has the uploaded file.
>>> from lp.testing.layers import LaunchpadZopelessLayer
>>> LaunchpadZopelessLayer.txn.commit()
Using the "get" command will retrieve a specified chroot to a given
filename.
>>> filepath = os.path.join(config.root, "foo")
>>> manage_chroot = getScriptObject("get", filepath=filepath)
>>> manage_chroot.mainTask()
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
DEBUG PocketChroot for 'The Hoary Hedgehog Release for i386 (x86)' (1) retrieved.
DEBUG Writing to '...foo'.
The downloaded chroot file now exists in the filepath specified.
>>> os.path.exists(filepath)
True
Remove it to avoid noise in test tree:
>>> os.remove(filepath)
Using the "remove" command will remove a previously uploaded chroot.
>>> manage_chroot = getScriptObject("remove")
>>> manage_chroot.mainTask()
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
DEBUG PocketChroot for 'The Hoary Hedgehog Release for i386 (x86)' (1) retrieved.
DEBUG PocketChroot for 'The Hoary Hedgehog Release for i386 (x86)' (1) removed.
Trying to retrieve a removed chroot will fail.
>>> filepath = os.path.join(config.root, "duuh")
>>> manage_chroot = getScriptObject("get", filepath=filepath)
>>> try:
... manage_chroot.mainTask()
... except SoyuzScriptError, info:
... print info
... else:
... print "Did not get expected exception"
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
Chroot was deleted.
>>> os.remove(filepath)
When the librarian is not running, attempting to upload a chroot file
results in an appropriate error.
>>> from lp.testing.layers import LibrarianLayer
>>> LibrarianLayer.hide()
>>> filepath = os.path.join(config.root, "COPYING")
>>> manage_chroot = getScriptObject("add", filepath=filepath)
>>> try:
... manage_chroot.mainTask()
... except SoyuzScriptError, info:
... print info
... else:
... print "Did not get expected exception"
DEBUG Initializing ChrootManager for 'The Hoary Hedgehog Release for i386 (x86)'
Librarian upload failed: ...Connection refused...
>>> LibrarianLayer.reveal()
|