Merge lp:~elopio/u1-test-utils/setup-vm into lp:u1-test-utils
- setup-vm
- Merge into trunk
Proposed by
Leo Arias
Status: | Merged |
---|---|
Approved by: | Vincent Ladeuil |
Approved revision: | 54 |
Merged at revision: | 51 |
Proposed branch: | lp:~elopio/u1-test-utils/setup-vm |
Merge into: | lp:u1-test-utils |
Diff against target: |
3691 lines (+3544/-0) 28 files modified
setup_vm/ISSUES (+9/-0) setup_vm/NOTES (+259/-0) setup_vm/README (+241/-0) setup_vm/TODO (+129/-0) setup_vm/bin/setup_vm.py (+1203/-0) setup_vm/bin/ubuntu_admin.sh (+2/-0) setup_vm/pay/install (+40/-0) setup_vm/pay/run (+9/-0) setup_vm/pay/run-for-u1 (+57/-0) setup_vm/pay/test (+5/-0) setup_vm/selftest.py (+24/-0) setup_vm/sso/install (+45/-0) setup_vm/sso/run (+16/-0) setup_vm/sso/run-for-pay (+14/-0) setup_vm/sso/run-for-u1 (+43/-0) setup_vm/sso/test (+11/-0) setup_vm/tests/__init__.py (+75/-0) setup_vm/tests/test_setup_vm.py (+1074/-0) setup_vm/tests/test_test.py (+58/-0) setup_vm/u1/install (+71/-0) setup_vm/u1/run (+4/-0) setup_vm/u1/test (+15/-0) setup_vm/unity/install-sources (+19/-0) setup_vm/unity/run-sso-client (+11/-0) setup_vm/unity/run-syncdaemon (+4/-0) setup_vm/unity/run-unity-lens-music (+6/-0) setup_vm/unity/transient-dist-upgrade (+4/-0) setup_vm/vms.conf (+96/-0) |
To merge this branch: | bzr merge lp:~elopio/u1-test-utils/setup-vm |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vincent Ladeuil (community) | Approve | ||
Review via email: mp+158828@code.launchpad.net |
Commit message
Merged the setup_vm project into u1testutils.
Description of the change
To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote : | # |
Revision history for this message
Leo Arias (elopio) wrote : | # |
Ready for review!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'setup_vm' | |||
2 | === added file 'setup_vm/ISSUES' | |||
3 | --- setup_vm/ISSUES 1970-01-01 00:00:00 +0000 | |||
4 | +++ setup_vm/ISSUES 2013-04-17 01:29:27 +0000 | |||
5 | @@ -0,0 +1,9 @@ | |||
6 | 1 | * while setting up sso.local .env/db/postgresql.log ends up with: | ||
7 | 2 | |||
8 | 3 | FATAL: role "postgres" does not exist | ||
9 | 4 | |||
10 | 5 | => This may be "expected" according to mfoord | ||
11 | 6 | |||
12 | 7 | |||
13 | 8 | * bzr+ssh://bazaar.launchpad.net/~canonical-isd-hackers/isd-configs/sso-config/ is missing in the sso config and local.cfg should also be generated to refer to that. | ||
14 | 9 | |||
15 | 0 | 10 | ||
16 | === added file 'setup_vm/NOTES' | |||
17 | --- setup_vm/NOTES 1970-01-01 00:00:00 +0000 | |||
18 | +++ setup_vm/NOTES 2013-04-17 01:29:27 +0000 | |||
19 | @@ -0,0 +1,259 @@ | |||
20 | 1 | Here we keep notes about the tests we will run on these vms. Once finished all | ||
21 | 2 | the TODOs, this will be probably moved to moztrap, or immediately and | ||
22 | 3 | magically automated. | ||
23 | 4 | |||
24 | 5 | == On the host == | ||
25 | 6 | 1. Install the requirements: | ||
26 | 7 | $ sudo apt-get install libvirt-bin qemu virtinst virt-manager | ||
27 | 8 | |||
28 | 9 | 2. Install the apt cache: | ||
29 | 10 | $ sudo apt-get install squid-deb-proxy | ||
30 | 11 | |||
31 | 12 | 3. Enable the cache for launchpad's private ppas: | ||
32 | 13 | See point 9 of the README. | ||
33 | 14 | |||
34 | 15 | 4. Configure the vms: | ||
35 | 16 | |||
36 | 17 | # This directory will be used as download cache for the Ubuntu images. | ||
37 | 18 | $ mkdir ~/installers/ubuntu | ||
38 | 19 | # This directory will store the disk images for the virtual machines. | ||
39 | 20 | $ mkdir ~/images | ||
40 | 21 | $ editor ~/vms.conf | ||
41 | 22 | |||
42 | 23 | vm.ram_size=2048 | ||
43 | 24 | vm.cpus=2 | ||
44 | 25 | # Tweak the cpu model according to your needs | ||
45 | 26 | vm.cpu_model=amd64 | ||
46 | 27 | vm.download_cache=~/installers/ubuntu | ||
47 | 28 | vm.images_dir=~/images | ||
48 | 29 | # Tweak according to your squid-deb-proxy setup, 8000 is the default port. | ||
49 | 30 | # Use {your-ip} or any address reachable by the vms (keeping in mind that | ||
50 | 31 | # avahi's .local domain may not be up in the early stages of the install | ||
51 | 32 | vm.apt_proxy = http://{your-ip}:800 | ||
52 | 33 | vm.launchpad_id=your-launchpad-id | ||
53 | 34 | # This is the ssh key of your host machine. Make sure that you have | ||
54 | 35 | uploaded it to https://launchpad.net/~/+editsshkeys | ||
55 | 36 | vm.ssh_authorized_keys = ~/.ssh/id_rsa.pub | ||
56 | 37 | # This is the ssh key for your VMs. It might be safer if it's different from | ||
57 | 38 | # your machine's key. Make sure that you have uploaded it to launchpad too. | ||
58 | 39 | vm.ssh_keys=~/.ssh/rsa-vms | ||
59 | 40 | # A default user (ubuntu) is created, here is its password | ||
60 | 41 | vm.password = you-re-on-you-own-use-a-simple-or-complex-password | ||
61 | 42 | # Go to https://launchpad.net/~/+archivesubscriptions to get the password for | ||
62 | 43 | # the Ubuntu One hackers PPA. Click the View link on the PPA row, and on the | ||
63 | 44 | # sources list entries you will see something like | ||
64 | 45 | # https://your-launchpad-id:the-password@... | ||
65 | 46 | ppa.ubuntuone_hackers.password=the-password | ||
66 | 47 | |||
67 | 48 | sso.address=sso.local | ||
68 | 49 | pay.address=pay.local | ||
69 | 50 | u1.address=u1.local | ||
70 | 51 | |||
71 | 52 | 5. Get the branch: | ||
72 | 53 | |||
73 | 54 | $ bzr branch lp:~online-services-qa/u1-test-utils/setup_vm | ||
74 | 55 | $ cd setup_vm | ||
75 | 56 | |||
76 | 57 | 6. Download the image for the server (do so every time you want to use a | ||
77 | 58 | fresh image): | ||
78 | 59 | |||
79 | 60 | $ ./bin/setup_vm.py precise-server-pristine --download | ||
80 | 61 | |||
81 | 62 | # TODO use LXCs insteal of virtual machines for the servers. | ||
82 | 63 | 7. Install the pristine server vm: | ||
83 | 64 | |||
84 | 65 | $ ./bin/setup_vm.py raring-pristine --install | ||
85 | 66 | |||
86 | 67 | 8. Download the image for the desktop (do so every time you want to use a | ||
87 | 68 | fresh image):: | ||
88 | 69 | |||
89 | 70 | $ ./bin/setup_vm.py raring-desktop-pristine --download | ||
90 | 71 | |||
91 | 72 | 8. Install the pristine desktop vm: | ||
92 | 73 | |||
93 | 74 | $ ./bin/setup_vm.py raring-pristine --install | ||
94 | 75 | |||
95 | 76 | # TODO now it might be better to start all the servers on the same VM. | ||
96 | 77 | 9. Set the SSO server (Only needed for in-dash payments tests): | ||
97 | 78 | |||
98 | 79 | $ ./bin/setup_vm.py sso --install | ||
99 | 80 | $ virsh start sso | ||
100 | 81 | $ ssh ubuntu@sso.local ~/bin/run-for-u1 | ||
101 | 82 | |||
102 | 83 | 10. Set up the Pay server (Only needed for in-dash payments tests): | ||
103 | 84 | |||
104 | 85 | $ ./bin/setup_vm.py pay --install | ||
105 | 86 | $ virsh start pay | ||
106 | 87 | $ ssh ubuntu@pay.local ~/bin/run-for-u1 | ||
107 | 88 | |||
108 | 89 | 11. Set up the U1 server (Only needed for in-dash payments tests): | ||
109 | 90 | |||
110 | 91 | $ ./bin/setup_vm.py u1 --install | ||
111 | 92 | $ virsh start u1 | ||
112 | 93 | $ ssh ubuntu@u1.local ~/bin/run | ||
113 | 94 | |||
114 | 95 | 12. Set up the Filesync server (Only needed for in-dash payments tests): | ||
115 | 96 | |||
116 | 97 | TODO. See below the notes to set it up on the same u1 server. | ||
117 | 98 | TODO. Explore how to set it up in a different server. | ||
118 | 99 | |||
119 | 100 | 13. Set up the Music Search server: | ||
120 | 101 | |||
121 | 102 | TODO. Do we need it? | ||
122 | 103 | |||
123 | 104 | 13. Install the CurucĂș server (Only needed for Smart Scopes tests): | ||
124 | 105 | |||
125 | 106 | TODO. | ||
126 | 107 | |||
127 | 108 | 17. Install the desktop machine that will run the tests: | ||
128 | 109 | |||
129 | 110 | $ ./bin/setup_vm.py unity-prevalidation --install | ||
130 | 111 | |||
131 | 112 | |||
132 | 113 | Set up the in-dash payments tests against the local servers | ||
133 | 114 | =========================================================== | ||
134 | 115 | |||
135 | 116 | This is for the happy path. | ||
136 | 117 | |||
137 | 118 | 1. Sign in to the unity-prevalidation machine using virt-manager. | ||
138 | 119 | |||
139 | 120 | 2. Kill syncdaemon if it is running. (As this is a pristine machine, this is not necessary) | ||
140 | 121 | |||
141 | 122 | 3. Open seahorse and delete the Ubuntu One credentials, if present. (As this is a pristine machine, this is not necessary) | ||
142 | 123 | |||
143 | 124 | 3. Log in with Staging Ubuntu SSO: | ||
144 | 125 | |||
145 | 126 | # TODO: Currently we can just connect to production. This is a regression, | ||
146 | 127 | # see bug http://pad.lv/1161067 | ||
147 | 128 | $ ~/bin/run-sso-client | ||
148 | 129 | |||
149 | 130 | Click the "Log-in with my existing account." link. | ||
150 | 131 | Fill the form with: | ||
151 | 132 | # TODO we need to create the user with the API helpers on u1-test-utils. | ||
152 | 133 | Email address: u1test+local-only@canonical.com | ||
153 | 134 | Password: Hola123* | ||
154 | 135 | Click the "Sign In" button. | ||
155 | 136 | |||
156 | 137 | Autopilot test: | ||
157 | 138 | http://bazaar.launchpad.net/~elopio/ubuntu-sso-client/autopilot/view/head:/ubuntu_sso/tests/acceptance/test_ubuntu_sso_client.py | ||
158 | 139 | |||
159 | 140 | 4. Start syncdaemon: | ||
160 | 141 | |||
161 | 142 | # TODO we currently don't have a filesync server. | ||
162 | 143 | $ ~/bin/run-syncdaemon | ||
163 | 144 | |||
164 | 145 | 5. Start the unity musicstore daemon: | ||
165 | 146 | |||
166 | 147 | $ ~/bin/run-unity-lens-music | ||
167 | 148 | |||
168 | 149 | 6. Start the control panel. | ||
169 | 150 | |||
170 | 151 | # TODO probably not neccessary. | ||
171 | 152 | |||
172 | 153 | 7. Add a credit card to the user. | ||
173 | 154 | |||
174 | 155 | # Use the API helpers on u1-test-utils. | ||
175 | 156 | # We still need to log in to the pay webiste first. See http://pad.lv/1144523 | ||
176 | 157 | |||
177 | 158 | 8. Enable the automatic payments for the user. | ||
178 | 159 | |||
179 | 160 | # TODO wait for http://ur1.ca/d6z4n to land and then extend the u1-test-utils | ||
180 | 161 | # API helpers to do this. | ||
181 | 162 | |||
182 | 163 | # For paypal payments, we would still need to do a lot of stuff on the website. | ||
183 | 164 | # TODO do we need to test paypal payments? | ||
184 | 165 | |||
185 | 166 | Run the in-dash payments tests against the local servers | ||
186 | 167 | =========================================================== | ||
187 | 168 | |||
188 | 169 | This is the happy path. | ||
189 | 170 | |||
190 | 171 | 1. Super+M. | ||
191 | 172 | 2. Search for 'hendrix'. | ||
192 | 173 | 3. Wait for the search to complete. | ||
193 | 174 | 4. Click the first album | ||
194 | 175 | 5. Click the Download button. | ||
195 | 176 | 6. Enter the password. | ||
196 | 177 | 7. Click the Purchase button. | ||
197 | 178 | |||
198 | 179 | All the tests are now documented in moztrap. | ||
199 | 180 | |||
200 | 181 | Set up the filesync server on the same machine as ubuntuone-servers | ||
201 | 182 | ==================================================================== | ||
202 | 183 | |||
203 | 184 | # On the host | ||
204 | 185 | $ ssh ubuntu@u1.local | ||
205 | 186 | # On the vm. | ||
206 | 187 | $ bzr branch lp:ubuntuone-filesync | ||
207 | 188 | $ cd ubuntuone-filesync | ||
208 | 189 | $ make link-sourcedeps | ||
209 | 190 | $ editor lib/u1backends/db/config.py | ||
210 | 191 | Change line 10 from: | ||
211 | 192 | db_dir = os.path.abspath(os.path.join(get_tmpdir(), 'db1')) | ||
212 | 193 | To: | ||
213 | 194 | db_dir = os.path.abspath( | ||
214 | 195 | os.path.join('/home/ubuntu/ubuntuone-servers/tmp', 'db1')) | ||
215 | 196 | $ make start | ||
216 | 197 | # Use ubuntuone-servers S4, statsd and AMQP. | ||
217 | 198 | $ ln -s ../../ubuntuone-servers/tmp/rabbitmq-ubuntuone.port tmp/rabbitmq-ubuntuone.port | ||
218 | 199 | $ ln -s ../../ubuntuone-servers/tmp/statsd.port tmp/statsd.port | ||
219 | 200 | $ ln -s ../../ubuntuone-servers/tmp/s4.port tmp/s4.port | ||
220 | 201 | $ make start-supervisor start-filesync-dummy-group | ||
221 | 202 | # TODO we can also start-filesync-oauth-group. Ask #u1-di. | ||
222 | 203 | |||
223 | 204 | Set up the curucu server | ||
224 | 205 | ======================== | ||
225 | 206 | |||
226 | 207 | # There is a dummy website that accesses the server: | ||
227 | 208 | # https://productsearch.ubuntu.com/smartscopes/v1/dashmock?geo_store=US | ||
228 | 209 | # On ~pedronis/curucu/canonistack-deploy, there's a README with the | ||
229 | 210 | # instructios to deploy curucu on a canonistack machine with Juju. | ||
230 | 211 | # TODO try to deploy it with juju on our vms. | ||
231 | 212 | # TODO we need an amazon key. | ||
232 | 213 | # On the host | ||
233 | 214 | $ ./bin/setup_vm.py precise-curucu-server --install | ||
234 | 215 | $ virsh start precise-curucu-server | ||
235 | 216 | $ ssh ubuntu@precise-curucu-server | ||
236 | 217 | # On the vm. | ||
237 | 218 | # TODO install the dependencies, what are the dependencies? | ||
238 | 219 | $ bzr branch lp:curucu | ||
239 | 220 | $ cd curucu | ||
240 | 221 | $ editor try.cfg | ||
241 | 222 | |||
242 | 223 | [amazon] | ||
243 | 224 | key = amazon key | ||
244 | 225 | secret = amazon secret | ||
245 | 226 | |||
246 | 227 | [u1ms] | ||
247 | 228 | service_url = http://musicsearch.ubuntu.com/v1/ | ||
248 | 229 | |||
249 | 230 | [feedback_store] | ||
250 | 231 | interval = 4 | ||
251 | 232 | # when set to empty storing feedback is disabled | ||
252 | 233 | store_directory = /tmp/feedback | ||
253 | 234 | |||
254 | 235 | $ CURUCU_CFG=try.cfg U1CONFIG=configs/development-lazr.conf PYTHONPATH=.:lib gunicorn -w 2 -k gevent_wsgi -b 0.0.0.0:8000 curucu.wsgi:app | ||
255 | 236 | |||
256 | 237 | Mounting guest disk images on the host | ||
257 | 238 | ====================================== | ||
258 | 239 | |||
259 | 240 | This requires root access (what did you expect ;-p) and the current | ||
260 | 241 | directory should contain the vm disk images. | ||
261 | 242 | |||
262 | 243 | apt-get install qemu-nbd | ||
263 | 244 | |||
264 | 245 | root@saw:/# modprobe nbd # once | ||
265 | 246 | root@saw:/# mkdir /mnt/disk1 | ||
266 | 247 | root@saw:/# mkdir /mnt/seed | ||
267 | 248 | |||
268 | 249 | root@saw:/# qemu-nbd -c /dev/nbd0 raring-pristine.qcow2 | ||
269 | 250 | root@saw:/# mount /dev/nbd0p1 /mnt/disk1 | ||
270 | 251 | root@saw:/# umount /mnt/disk1/ | ||
271 | 252 | root@saw:/# qemu-nbd -d /dev/nbd0 | ||
272 | 253 | |||
273 | 254 | root@saw:/# qemu-nbd -c /dev/nbd1 raring-test.seed | ||
274 | 255 | root@saw:/# mount /dev/nbd1 /mnt/seed | ||
275 | 256 | mount: warning: /mnt/seed seems to be mounted read-only. | ||
276 | 257 | root@saw:/# umount /mnt/seed | ||
277 | 258 | root@saw:/# qemu-nbd -d /dev/nbd1 | ||
278 | 259 | /dev/nbd1 disconnected | ||
279 | 0 | 260 | ||
280 | === added file 'setup_vm/README' | |||
281 | --- setup_vm/README 1970-01-01 00:00:00 +0000 | |||
282 | +++ setup_vm/README 2013-04-17 01:29:27 +0000 | |||
283 | @@ -0,0 +1,241 @@ | |||
284 | 1 | Getting started: | ||
285 | 2 | ================ | ||
286 | 3 | |||
287 | 4 | 1. Install the dependencies: | ||
288 | 5 | |||
289 | 6 | sudo apt-get install bzr python-testtools python-yaml | ||
290 | 7 | sudp apt-get install libvirt-bin qemu qemu-utils virtinst | ||
291 | 8 | sudo apt-get install qemu-kvm-spice python-spice-client-gtk | ||
292 | 9 | |||
293 | 10 | (Optional): | ||
294 | 11 | To use a gui manager to see the desktop: | ||
295 | 12 | sudo apt-get install virt-manager | ||
296 | 13 | |||
297 | 14 | To use Apt proxy to speed up multiple downloads of the same packages: | ||
298 | 15 | sudo apt-get install squid-deb-proxy | ||
299 | 16 | (See point 9 about configuring the apt cache.) | ||
300 | 17 | |||
301 | 18 | 2. Reboot to allow kvm to activate on the running kernel. | ||
302 | 19 | |||
303 | 20 | 3. Get the code: | ||
304 | 21 | |||
305 | 22 | bzr branch lp:~online-services-qa/u1-test-utils/setup_vm | ||
306 | 23 | |||
307 | 24 | 4. Run the tests: | ||
308 | 25 | |||
309 | 26 | cd setup_vm | ||
310 | 27 | ./selftest.py | ||
311 | 28 | |||
312 | 29 | (The test_install_from_seed will require you to enter your password | ||
313 | 30 | because it executes a command with sudo. Your user must be a sudoer.) | ||
314 | 31 | |||
315 | 32 | 5. Configure a virtual machine: | ||
316 | 33 | |||
317 | 34 | Write the file ~/vms.conf with something like this: | ||
318 | 35 | |||
319 | 36 | vm.ram_size=2048 | ||
320 | 37 | vm.cpus=2 | ||
321 | 38 | vm.cpu_model=amd64 | ||
322 | 39 | |||
323 | 40 | [raring-pristine] | ||
324 | 41 | vm.name = raring-pristine | ||
325 | 42 | vm.update = True | ||
326 | 43 | vm.packages = bzr, ubuntu-desktop, avahi-daemon | ||
327 | 44 | vm.release=raring | ||
328 | 45 | vm.ssh_authorized_keys = {your SSH public key path (~ is allowed, eg ~/.ssh/id_rsa.pub)} | ||
329 | 46 | |||
330 | 47 | Create the ~/.config/setup_vm directory where cloud-init configuration | ||
331 | 48 | files will be stored for each vm. Alternatively, you can create a | ||
332 | 49 | directory (~/vms) where you want and add the following line in ~/vms.conf: | ||
333 | 50 | |||
334 | 51 | vm.vms_dir=~/vms | ||
335 | 52 | |||
336 | 53 | Optionally, you can setup scripts to be executed as root or as the | ||
337 | 54 | ubuntu user just before the vm is powered off: | ||
338 | 55 | |||
339 | 56 | vm.root_script = {path to a script on the host} | ||
340 | 57 | vm.ubuntu_script = {path to a script on the host} | ||
341 | 58 | |||
342 | 59 | These scripts *must* specify a shebang line and can be written in any | ||
343 | 60 | language that can be run from a shebang line. | ||
344 | 61 | |||
345 | 62 | You can also ask for some local scripts to be uploaded with: | ||
346 | 63 | |||
347 | 64 | vm.uploaded_scripts = sso/run, sso/run-for-pay | ||
348 | 65 | |||
349 | 66 | The config options in these scripts will be expanded before the upload. | ||
350 | 67 | |||
351 | 68 | PPAS needs a bit of care to setup, as an example, the unity experimental | ||
352 | 69 | prevalidation PPA is configured by going to | ||
353 | 70 | https://launchpad.net/~ubuntu-unity/+archive/experimental-prevalidation | ||
354 | 71 | Click the "Technical details about this PPA" link. | ||
355 | 72 | Select the distribution from the combo box. | ||
356 | 73 | Copy the apt line below: | ||
357 | 74 | |||
358 | 75 | vm.apt_sources=deb http://ppa.launchpad.net/ubuntu-unity/experimental-prevalidation/ubuntu {vm.release} main|52D62F45 | ||
359 | 76 | |||
360 | 77 | The page displays Signing Key: 1024R/52D62F45. Please note that only | ||
361 | 78 | 52D62F45 should be specified, and that the url and the key are separated | ||
362 | 79 | by '|' with no intervening spaces. | ||
363 | 80 | |||
364 | 81 | For a private PPA, make sure to include your launchpad id and your | ||
365 | 82 | password for that PPA in the URL. It would look something like this: | ||
366 | 83 | |||
367 | 84 | vm.apt_sources = deb https://<lp id>:<ppa password>@private-ppa.launchpad.net/a-user/ppa-name/ubuntu {vm.release} main|<ppa key> | ||
368 | 85 | |||
369 | 86 | 6. (Optional) Create a system-wide vms.conf. | ||
370 | 87 | |||
371 | 88 | In some cases, some options are better defined in a system-wide config | ||
372 | 89 | file (/etc/libvirt/vms.conf). This file is queried if no definitions are | ||
373 | 90 | found in ~/vms.conf and can define a no-name section and vm sections. | ||
374 | 91 | |||
375 | 92 | 7. (Optional) You can configure the location where the image will be | ||
376 | 93 | downloaded with something like this in the vms.conf file: | ||
377 | 94 | |||
378 | 95 | vm.download_cache=~/installers/ubuntu | ||
379 | 96 | |||
380 | 97 | 8. (Optional) You can configure the location where the virtual machines will | ||
381 | 98 | be stored with something like this in the vms.conf file: | ||
382 | 99 | |||
383 | 100 | vm.images_dir=~/images | ||
384 | 101 | |||
385 | 102 | 9. (Optional) Set up an apt cache, so repeated virtual machine installs will | ||
386 | 103 | be faster, downloading the packages from the cache instead of an Ubuntu | ||
387 | 104 | archive mirror: | ||
388 | 105 | |||
389 | 106 | Add this to the vms.conf file: | ||
390 | 107 | |||
391 | 108 | vm.apt_proxy = http://{your-squid-deb-proxy-ip}:8000 | ||
392 | 109 | |||
393 | 110 | If you need to install packages from non official Ubuntu repositories, you | ||
394 | 111 | will need to configure the proxy. For example, common tasks would require | ||
395 | 112 | to access Launchpad public and private PPAs. For that, write the file | ||
396 | 113 | /etc/squid-deb-proxy/mirror-dstdomain.acl.d/20-local-vms with: | ||
397 | 114 | |||
398 | 115 | # /etc/squid-deb-proxy/mirror-dstdomain.acl.d/20-local-vms | ||
399 | 116 | |||
400 | 117 | # network destinations that are allowed by this cache targeted at | ||
401 | 118 | # locally installed vms | ||
402 | 119 | |||
403 | 120 | # launchpad personal package archives | ||
404 | 121 | ppa.launchpad.net | ||
405 | 122 | # launchpad private personal package archives | ||
406 | 123 | private-ppa.launchpad.net | ||
407 | 124 | |||
408 | 125 | After that, restart the proxy: | ||
409 | 126 | |||
410 | 127 | sudo restart squid-deb-proxy | ||
411 | 128 | |||
412 | 129 | Each time you modify some file under /etc/squid-deb-proxy, don't forget to | ||
413 | 130 | restart the service. | ||
414 | 131 | |||
415 | 132 | 10. Download the image: | ||
416 | 133 | |||
417 | 134 | ./bin/setup_vm.py --download raring-pristine | ||
418 | 135 | |||
419 | 136 | (This command will require you to enter your password because the | ||
420 | 137 | directory where the image will be downloaded might be under control of | ||
421 | 138 | the root user. Your user must be a sudoer. A pending task is to ask for | ||
422 | 139 | the password just when needed.) | ||
423 | 140 | |||
424 | 141 | 11. Install the virtual machine: | ||
425 | 142 | |||
426 | 143 | ./bin/setup_vm.py --install raring-pristine | ||
427 | 144 | |||
428 | 145 | (This command will require you to enter your password because some of the | ||
429 | 146 | operations it executes require root access. Your user must be a sudoer.) | ||
430 | 147 | |||
431 | 148 | 12. You can ssh into the virtual machine: | ||
432 | 149 | |||
433 | 150 | virsh start raring-pristine | ||
434 | 151 | ssh ubuntu@raring-pristine.local | ||
435 | 152 | |||
436 | 153 | No password is needed because your SSH public key is authorized. | ||
437 | 154 | |||
438 | 155 | 13. You can run the virtual machine from virt-manager to get a graphical user | ||
439 | 156 | interface: | ||
440 | 157 | |||
441 | 158 | Open virt-manager. | ||
442 | 159 | Right-click on the machine and select Run. | ||
443 | 160 | You will be presented with the display manager greeter. | ||
444 | 161 | Log in with the user ubuntu, password ubuntu. | ||
445 | 162 | |||
446 | 163 | (You may need to do the following if virt-manager says it can't connect, | ||
447 | 164 | sudo usermod -a -G libvirtd $USER (replace $USER with your username) | ||
448 | 165 | and reboot the system) | ||
449 | 166 | |||
450 | 167 | 14. (Optional) You can set up a "throw away" virtual machine on top of | ||
451 | 168 | another. We call it "throw away" because all modifications happening there | ||
452 | 169 | won't affect the disk image of the backing on virtual machine. | ||
453 | 170 | |||
454 | 171 | In the vms.conf described above add: | ||
455 | 172 | |||
456 | 173 | [raring-test] | ||
457 | 174 | vm.name = raring-test | ||
458 | 175 | vm.update = False | ||
459 | 176 | vm.release = raring | ||
460 | 177 | vm.ssh_authorized_keys = {your SSH public key} | ||
461 | 178 | # The name of the disk image used as a base | ||
462 | 179 | vm.backing = raring-pristine.qcow2 | ||
463 | 180 | |||
464 | 181 | Create the new vm with: | ||
465 | 182 | |||
466 | 183 | ./bin/setup_vm.py --install raring-test | ||
467 | 184 | |||
468 | 185 | The vm creation and boot should be faster. | ||
469 | 186 | |||
470 | 187 | 15. (Very optional) A few commands for virsh that may be of use: | ||
471 | 188 | virsh list (shows what is running) | ||
472 | 189 | virsh start x (start a vm with the name x) | ||
473 | 190 | virsh destroy x (force shutdowns a vm with the name x) | ||
474 | 191 | virsh undefine x [--remove-all-storage] (Deletes a vm with the name x) | ||
475 | 192 | |||
476 | 193 | 16. (Optional) Raise sudo timeout. | ||
477 | 194 | |||
478 | 195 | If you run into vm installs taking too long and waiting for your | ||
479 | 196 | password to fisnish, you can change the default value (15 minutes) by | ||
480 | 197 | adding a file in /etc/sudoers.d containing: | ||
481 | 198 | |||
482 | 199 | Defaults:<your login here> timestamp_timeout=60 | ||
483 | 200 | |||
484 | 201 | This will setup the timeout to 60 minutes. | ||
485 | 202 | |||
486 | 203 | 17. (Optional) Setup launchpad access for the guests | ||
487 | 204 | |||
488 | 205 | If you need to access launchpad private branches from the guests, you'll | ||
489 | 206 | need to setup ssh launchpad access (if you only need access to public | ||
490 | 207 | branches, http is good enough and you don't even need to 'bzr | ||
491 | 208 | launchpad-login'): | ||
492 | 209 | |||
493 | 210 | - You need to create an ssh key dedicated to the guests, it has to be | ||
494 | 211 | passwordless and the public part uploaded to your launchpad profile. | ||
495 | 212 | You can generate a new key pair (replacing <user> with your launchpad | ||
496 | 213 | id) with: | ||
497 | 214 | |||
498 | 215 | $ (cd ~/.ssh ; ssh-keygen -f <user>@setup_vm -N '' -C '<user>@setup_vm') | ||
499 | 216 | |||
500 | 217 | This will create two files: '<user>@setup_vm' and | ||
501 | 218 | '<user>@setup_vm.pub' in your ~/.ssh directory. | ||
502 | 219 | |||
503 | 220 | Upload the later at https://launchpad.net/~/+editsshkeys | ||
504 | 221 | |||
505 | 222 | The keys are created in your .ssh directory so you can test that they | ||
506 | 223 | work against launchpad without involving a vm. | ||
507 | 224 | |||
508 | 225 | Note that if you create vms from different hosts, you'll need to either | ||
509 | 226 | copy the same keys on all the hosts or create a pair on each of them | ||
510 | 227 | (or any combination as long as the public keys are uploaded to | ||
511 | 228 | launchpad ;). | ||
512 | 229 | |||
513 | 230 | - You need to set vm.launchpad_id to <user>. This will trigger running | ||
514 | 231 | 'bzr launchpad-login <user>' in the guest and copy | ||
515 | 232 | ~/.ssh/<user>@setup_vm (the private key) from your host to the guest. | ||
516 | 233 | |||
517 | 234 | - The bazaar.launchpad.net host ssh key needs to be known or you'll get | ||
518 | 235 | prompted to add it (which is not nice for scripts). This can be fixed | ||
519 | 236 | by issuing the following command from the {vm.ubuntu_script}: | ||
520 | 237 | |||
521 | 238 | $ ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts | ||
522 | 239 | |||
523 | 240 | This will probably be automated at some point in the future. | ||
524 | 241 | |||
525 | 0 | 242 | ||
526 | === added file 'setup_vm/TODO' | |||
527 | --- setup_vm/TODO 1970-01-01 00:00:00 +0000 | |||
528 | +++ setup_vm/TODO 2013-04-17 01:29:27 +0000 | |||
529 | @@ -0,0 +1,129 @@ | |||
530 | 1 | * running setup_vm --install I-dont-exist raises an obscure error. Checking | ||
531 | 2 | that the config section exist for the vm would allow reporting a better | ||
532 | 3 | error. | ||
533 | 4 | |||
534 | 5 | * Too many tests become too hard to write because their execution requires a | ||
535 | 6 | real vm. This can be addressed in much the same way than | ||
536 | 7 | requires_known_reference_image(), i.e. setup a real vm once (outside of | ||
537 | 8 | selftest execution for now) and then use throw-away vms. But even that | ||
538 | 9 | may be too costly and may need to wait for lxc/chroot support. | ||
539 | 10 | |||
540 | 11 | * running --ssh-keygen twice gives an awful error message. | ||
541 | 12 | |||
542 | 13 | * Find whether or not we should really support chroots or if lxcs are good | ||
543 | 14 | enough (roughly: if they can be set up as fast as chroots but provide | ||
544 | 15 | more features, just optimize the backing-on scenario). | ||
545 | 16 | |||
546 | 17 | * Investigate btrfs support to use snapshots for nested backing. | ||
547 | 18 | This may not be appropriate with kvms but will surely shine for | ||
548 | 19 | lxc/chroot. | ||
549 | 20 | |||
550 | 21 | * copying a file (with expanded options or not) from the host to the guest | ||
551 | 22 | is hard (even internally). There should be a way to more simply describe | ||
552 | 23 | a list of file/directories to install (with user:group and chmod bits). | ||
553 | 24 | |||
554 | 25 | * Alternatively, we can allow the guest to access the host via ssh (after | ||
555 | 26 | all, we're installing a private key in the guest so we trust it enough | ||
556 | 27 | for that already). | ||
557 | 28 | |||
558 | 29 | * As a first step, we can define vm.scripts as a list of relative paths on | ||
559 | 30 | the host, that will be option expanded into vm.config_dir and uploaded | ||
560 | 31 | from there into ~ubuntu/bin. | ||
561 | 32 | |||
562 | 33 | * Provide the guest with config file containing the values used to build | ||
563 | 34 | this vm. From there, the guest itself would be able to expanded options | ||
564 | 35 | in files acquired from the host (including files modified after the vm | ||
565 | 36 | has been built/started which will help during dev/debug). | ||
566 | 37 | |||
567 | 38 | * vm.ubuntu_script is kind of an implementation leak from cloud-init, that's | ||
568 | 39 | the default user there and comes with some nice properties but strictly | ||
569 | 40 | speaking setup_vm cares about having *a* user, no matter how it is named | ||
570 | 41 | so the option could be named vm.user_script. In any case, the features we | ||
571 | 42 | rely on from using ubuntu should be tested if only to document them. | ||
572 | 43 | |||
573 | 44 | * we need a way to run scripts on the host while expanding the config option | ||
574 | 45 | for a given vm (see sso/test that needs at least the sso.url). | ||
575 | 46 | |||
576 | 47 | * launchpad interaction requires the launchpad host key. | ||
577 | 48 | |||
578 | 49 | => ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts does the | ||
579 | 50 | trick but it would be nice to automate it. | ||
580 | 51 | |||
581 | 52 | * document the /etc/avahi/ fix required to use avahi with vms | ||
582 | 53 | |||
583 | 54 | * lag times between significant hosts should be collected (not specific to | ||
584 | 55 | setup_vm but related to the use of the vms). | ||
585 | 56 | |||
586 | 57 | * Add a way to display a vm configuration Ă la 'bzr config' | ||
587 | 58 | |||
588 | 59 | * from the addresses below, find a way to test if some fixed subspace can be | ||
589 | 60 | safely used (de:ad:be:ef or something...) or just steal some unused MAC | ||
590 | 61 | prefix (vbox's one ? or vmware's one ? or... the sky is the limit ;) | ||
591 | 62 | |||
592 | 63 | |||
593 | 64 | $ sudo grep -n 'mac address' /etc/libvirt/qemu/*.xml | ||
594 | 65 | /etc/libvirt/qemu/essex-precise.xml:45: <mac address='52:54:00:26:3c:20'/> | ||
595 | 66 | /etc/libvirt/qemu/freebsd8.xml:39: <mac address='08:00:27:5f:9f:06'/> | ||
596 | 67 | /etc/libvirt/qemu/gentoo.xml:39: <mac address='08:00:27:da:65:cd'/> | ||
597 | 68 | /etc/libvirt/qemu/indicator-sync.xml:45: <mac address='52:54:00:43:15:9c'/> | ||
598 | 69 | /etc/libvirt/qemu/pkgimporter-lucid.xml:45: <mac address='52:54:00:95:4e:dc'/> | ||
599 | 70 | /etc/libvirt/qemu/precise-cloud.xml:48: <mac address='52:54:00:68:aa:af'/> | ||
600 | 71 | /etc/libvirt/qemu/precise-pristine.xml:48: <mac address='52:54:00:d5:52:06'/> | ||
601 | 72 | /etc/libvirt/qemu/precise-pristine.xml:48: <mac address='52:54:00:70:a3:64'/> | ||
602 | 73 | /etc/libvirt/qemu/precise-server-pristine.xml:51: <mac address='52:54:00:14:d5:be'/> | ||
603 | 74 | /etc/libvirt/qemu/precise-test.xml:48: <mac address='52:54:00:25:8b:56'/> | ||
604 | 75 | /etc/libvirt/qemu/quantal-cloud.xml:48: <mac address='52:54:00:e6:6a:df'/> | ||
605 | 76 | /etc/libvirt/qemu/quantal-pristine.xml:48: <mac address='52:54:00:f5:95:0e'/> | ||
606 | 77 | /etc/libvirt/qemu/quantal-pristine.xml:48: <mac address='52:54:00:b9:68:11'/> | ||
607 | 78 | /etc/libvirt/qemu/quantal-test.xml:48: <mac address='52:54:00:21:3b:7b'/> | ||
608 | 79 | /etc/libvirt/qemu/raring-current.xml <mac address='52:54:00:d9:ca:70'/> | ||
609 | 80 | /etc/libvirt/qemu/raring-in-dash-pristine.xml:51: <mac address='52:54:00:c7:f9:ee'/> | ||
610 | 81 | /etc/libvirt/qemu/raring-in-dash-test.xml:51: <mac address='52:54:00:a5:83:b9'/> | ||
611 | 82 | /etc/libvirt/qemu/raring-pristine.xml:48: <mac address='52:54:00:07:09:cb'/> | ||
612 | 83 | /etc/libvirt/qemu/raring-pristine.xml:48: <mac address='52:54:00:34:7f:62'/> | ||
613 | 84 | /etc/libvirt/qemu/raring-scope-base.xml:42: <mac address='52:54:00:9c:0d:1c'/> | ||
614 | 85 | /etc/libvirt/qemu/raring-scope-test.xml:42: <mac address='52:54:00:8a:b1:d6'/> | ||
615 | 86 | /etc/libvirt/qemu/raring-test.xml:48: <mac address='52:54:00:23:b6:8d'/> | ||
616 | 87 | /etc/libvirt/qemu/raring-test.xml:51: <mac address='52:54:00:e3:05:db'/> | ||
617 | 88 | /etc/libvirt/qemu/sso.xml:51: <mac address='52:54:00:f1:88:84'/> | ||
618 | 89 | /etc/libvirt/qemu/u1test-quantal.xml:48: <mac address='52:54:00:04:7b:45'/> | ||
619 | 90 | /etc/libvirt/qemu/u1test-quantal.xml:48: <mac address='52:54:00:04:7b:45'/> | ||
620 | 91 | /etc/libvirt/qemu/u1test2-quantal.xml:45: <mac address='52:54:00:df:35:6c'/> | ||
621 | 92 | /etc/libvirt/qemu/u1test2-quantal.xml:45: <mac address='52:54:00:df:35:6c'/> | ||
622 | 93 | /etc/libvirt/qemu/xp-32bits.xml:58: <mac address='52:54:00:86:aa:99'/> | ||
623 | 94 | /etc/libvirt/qemu/xp64bits.xml:46: <mac address='52:54:00:0a:5e:7c'/> | ||
624 | 95 | |||
625 | 96 | * while using fixed IP addresses is one way to address known_hosts | ||
626 | 97 | stability, another way is to rely on `ssh-keygen -R` when installing the | ||
627 | 98 | host (to remove the previous mapping between the key and the ip) and then | ||
628 | 99 | add the new key with ssh-keyscan (or something else that doesn't require | ||
629 | 100 | the guest to be up and running). | ||
630 | 101 | |||
631 | 102 | * make actions verbose and obey -q (at least for tests) so we get some | ||
632 | 103 | feeback about what is executed. | ||
633 | 104 | |||
634 | 105 | * add a --delete action to make sure we clean up the config_dir | ||
635 | 106 | |||
636 | 107 | * rework FileMonitor, ConsoleMonitor design, the actual result smells (pass | ||
637 | 108 | in _wait_for_install_with_seed, really ?). | ||
638 | 109 | |||
639 | 110 | * investigate using an upstart job like MAAS: | ||
640 | 111 | |||
641 | 112 | write_poweroff_job() { | ||
642 | 113 | cat >/etc/init/maas-poweroff.conf <<EOF | ||
643 | 114 | description "poweroff when maas task is done" | ||
644 | 115 | start on stopped cloud-final | ||
645 | 116 | console output | ||
646 | 117 | task | ||
647 | 118 | script | ||
648 | 119 | [ ! -e /tmp/block-poweroff ] || exit 0 | ||
649 | 120 | poweroff | ||
650 | 121 | end script | ||
651 | 122 | EOF | ||
652 | 123 | # reload required due to lack of inotify in overlayfs (LP: #882147) | ||
653 | 124 | initctl reload-configuration | ||
654 | 125 | } | ||
655 | 126 | |||
656 | 127 | * look at PXE, interesting read may include: | ||
657 | 128 | |||
658 | 129 | http://ubuntuforums.org/archive/index.php/t-1713845.html | ||
659 | 0 | 130 | ||
660 | === added directory 'setup_vm/bin' | |||
661 | === added file 'setup_vm/bin/__init__.py' | |||
662 | === added file 'setup_vm/bin/setup_vm.py' | |||
663 | --- setup_vm/bin/setup_vm.py 1970-01-01 00:00:00 +0000 | |||
664 | +++ setup_vm/bin/setup_vm.py 2013-04-17 01:29:27 +0000 | |||
665 | @@ -0,0 +1,1203 @@ | |||
666 | 1 | #!/usr/bin/env python | ||
667 | 2 | """ | ||
668 | 3 | Setup a virtual machine from a config file. | ||
669 | 4 | |||
670 | 5 | Note: Most of the operations requires root access and this script uses ``sudo`` | ||
671 | 6 | to get them. | ||
672 | 7 | |||
673 | 8 | """ | ||
674 | 9 | import argparse | ||
675 | 10 | import base64 | ||
676 | 11 | from cStringIO import StringIO | ||
677 | 12 | import errno | ||
678 | 13 | import os | ||
679 | 14 | import subprocess | ||
680 | 15 | import sys | ||
681 | 16 | import tempfile | ||
682 | 17 | import time | ||
683 | 18 | |||
684 | 19 | |||
685 | 20 | from bzrlib import ( | ||
686 | 21 | config, | ||
687 | 22 | osutils, | ||
688 | 23 | transport, | ||
689 | 24 | urlutils, | ||
690 | 25 | ) | ||
691 | 26 | import yaml | ||
692 | 27 | |||
693 | 28 | # Work around a bug in bzrlib.config forbidding some constructs in templates. | ||
694 | 29 | # Namely, spaces are invalid as an identifier and therefore should not match | ||
695 | 30 | # below. | ||
696 | 31 | config._option_ref_re = config.lazy_regex.lazy_compile('({[^ {},\n]+})') | ||
697 | 32 | |||
698 | 33 | |||
699 | 34 | class VmMatcher(config.NameMatcher): | ||
700 | 35 | |||
701 | 36 | def match(self, section): | ||
702 | 37 | if section.id is None: | ||
703 | 38 | # The no name section contains default values | ||
704 | 39 | return True | ||
705 | 40 | return super(VmMatcher, self).match(section) | ||
706 | 41 | |||
707 | 42 | def get_sections(self): | ||
708 | 43 | matching_sections = super(VmMatcher, self).get_sections() | ||
709 | 44 | return reversed(list(matching_sections)) | ||
710 | 45 | |||
711 | 46 | |||
712 | 47 | class VmStore(config.LockableIniFileStore): | ||
713 | 48 | """A config store for options specific to a directory.""" | ||
714 | 49 | |||
715 | 50 | def __init__(self, directory, file_name, possible_transports=None): | ||
716 | 51 | t = transport.get_transport_from_path( | ||
717 | 52 | directory, possible_transports=possible_transports) | ||
718 | 53 | super(VmStore, self).__init__(t, file_name) | ||
719 | 54 | self.id = 'vm' | ||
720 | 55 | |||
721 | 56 | |||
722 | 57 | def system_config_dir(): | ||
723 | 58 | return '/etc/libvirt' | ||
724 | 59 | |||
725 | 60 | |||
726 | 61 | class VmStack(config.Stack): | ||
727 | 62 | """Per-directory options.""" | ||
728 | 63 | |||
729 | 64 | def __init__(self, name): | ||
730 | 65 | """Make a new stack for a given vm. | ||
731 | 66 | |||
732 | 67 | The following sections are queried: | ||
733 | 68 | |||
734 | 69 | * the ``name`` section in ./vms.conf, | ||
735 | 70 | * the no-name section in ./vms.conf | ||
736 | 71 | * the ``name`` section in ~/vms.conf, | ||
737 | 72 | * the no-name section in ~/vms.conf | ||
738 | 73 | * the ``name`` section in /etc/libvirt/vms.conf, | ||
739 | 74 | * the no-name section in /etc/libvirt/vms.conf | ||
740 | 75 | |||
741 | 76 | :param name: The name of a virtual machine. | ||
742 | 77 | """ | ||
743 | 78 | self.local_store = VmStore('.', 'vms.conf') | ||
744 | 79 | user_store = VmStore(os.environ['HOME'], 'vms.conf') | ||
745 | 80 | self.system_store = VmStore(system_config_dir(), 'vms.conf') | ||
746 | 81 | # FIXME: Only available in bzr-2.6b3 :-/ -- vila 2012-01-31 | ||
747 | 82 | # dstore = self.get_shared_store() | ||
748 | 83 | super(VmStack, self).__init__( | ||
749 | 84 | [VmMatcher(self.local_store, name).get_sections, | ||
750 | 85 | VmMatcher(user_store, name).get_sections, | ||
751 | 86 | VmMatcher(self.system_store, name).get_sections, | ||
752 | 87 | ], | ||
753 | 88 | user_store, mutable_section_id=name) | ||
754 | 89 | |||
755 | 90 | |||
756 | 91 | def path_from_unicode(path_string): | ||
757 | 92 | if not isinstance(path_string, basestring): | ||
758 | 93 | raise TypeError | ||
759 | 94 | return os.path.expanduser(path_string) | ||
760 | 95 | |||
761 | 96 | |||
762 | 97 | class PathOption(config.Option): | ||
763 | 98 | |||
764 | 99 | def __init__(self, *args, **kwargs): | ||
765 | 100 | """A path option definition. | ||
766 | 101 | |||
767 | 102 | This possibly expands the user home directory. | ||
768 | 103 | """ | ||
769 | 104 | super(PathOption, self).__init__( | ||
770 | 105 | *args, from_unicode=path_from_unicode, **kwargs) | ||
771 | 106 | |||
772 | 107 | |||
773 | 108 | def register(option): | ||
774 | 109 | config.option_registry.register(option) | ||
775 | 110 | |||
776 | 111 | |||
777 | 112 | register(config.Option( | ||
778 | 113 | 'vm', default=None, | ||
779 | 114 | help='''The name space defining a virtual machine. | ||
780 | 115 | |||
781 | 116 | This option is a place holder to document the options that defines a virtual | ||
782 | 117 | machine and the options defining the infrastructure used to manage them all. | ||
783 | 118 | |||
784 | 119 | For qemu based vms, the definition of a vm is stored in an xml file under | ||
785 | 120 | '/etc/libvirt/qemu/{vm.name}.xml'. This is under the libvirt package control | ||
786 | 121 | and is out of scope for setup_vm.py. | ||
787 | 122 | |||
788 | 123 | There are 3 other significant files used for a given vm: | ||
789 | 124 | |||
790 | 125 | - a disk image mounted at '/' from '/dev/sda1': | ||
791 | 126 | '{vm.images_dir}/{vm.name}.qcow2' | ||
792 | 127 | |||
793 | 128 | - a iso image available from '/dev/sdb' labeled 'cidata': | ||
794 | 129 | {vm.images_dir}/{vm.name}.seed which contains the cloud-init data used to | ||
795 | 130 | configure/install/update the vm. | ||
796 | 131 | |||
797 | 132 | - a console: {vm.images_dir}/{vm.name}.console which can be 'tail -f'ed from | ||
798 | 133 | the host. | ||
799 | 134 | |||
800 | 135 | The data used to create the seed above are stored in a vm specific | ||
801 | 136 | configuration directory for easier debug and reference: | ||
802 | 137 | - {vm.config_dir}/user-data | ||
803 | 138 | - {vm.config_dir}/meta-data | ||
804 | 139 | - {vm.config_dir}/ecdsa | ||
805 | 140 | - {vm.config_dir}/ecdsa.pub | ||
806 | 141 | ''')) | ||
807 | 142 | |||
808 | 143 | # The directory where we store vm files related to their configuration with | ||
809 | 144 | # cloud-init (user-data, meta-data, ssh keys). | ||
810 | 145 | register(config.Option( | ||
811 | 146 | 'vm.vms_dir', default='~/.config/setup_vm', | ||
812 | 147 | help='''Where vm related config files are stored. | ||
813 | 148 | |||
814 | 149 | This includes user-data and meta-data for cloud-init and ssh server keys. | ||
815 | 150 | |||
816 | 151 | This directory must exist. | ||
817 | 152 | |||
818 | 153 | Each vm get a specific directory (automatically created) there based on its | ||
819 | 154 | name. | ||
820 | 155 | ''')) | ||
821 | 156 | # The base directories where vms are stored for kvm | ||
822 | 157 | register(PathOption( | ||
823 | 158 | 'vm.images_dir', default='/var/lib/libvirt/images', | ||
824 | 159 | help="Where vm disk images are stored.", | ||
825 | 160 | )) | ||
826 | 161 | register(config.Option( | ||
827 | 162 | 'vm.qemu_etc_dir', | ||
828 | 163 | default='/etc/libvirt/qemu', | ||
829 | 164 | help="Where libvirt (qemu) stores the vms config files." | ||
830 | 165 | )) | ||
831 | 166 | |||
832 | 167 | # Isos and images download handling | ||
833 | 168 | register(config.Option( | ||
834 | 169 | 'vm.iso_url', | ||
835 | 170 | default='http://cdimage.ubuntu.com/daily-live/current/' , | ||
836 | 171 | help="Where an iso can be downloaded from." | ||
837 | 172 | )) | ||
838 | 173 | register(config.Option( | ||
839 | 174 | 'vm.iso_name', | ||
840 | 175 | default='{vm.release}-desktop-{vm.cpu_model}.iso', | ||
841 | 176 | help="The name of the iso." | ||
842 | 177 | )) | ||
843 | 178 | register(config.Option( | ||
844 | 179 | 'vm.cloud_image_url', | ||
845 | 180 | default='http://cloud-images.ubuntu.com/{vm.release}/current/', | ||
846 | 181 | help="Where a cloud image can be downloaded from." | ||
847 | 182 | )) | ||
848 | 183 | register(config.Option( | ||
849 | 184 | 'vm.cloud_image_name', | ||
850 | 185 | default='{vm.release}-server-cloudimg-{vm.cpu_model}-disk1.img', | ||
851 | 186 | help="The name of the cloud image." | ||
852 | 187 | )) | ||
853 | 188 | register(PathOption( | ||
854 | 189 | 'vm.download_cache', | ||
855 | 190 | default='{vm.images_dir}', | ||
856 | 191 | help="Where downloads end up.", | ||
857 | 192 | )) | ||
858 | 193 | |||
859 | 194 | # The ubiquitous vm name | ||
860 | 195 | register(config.Option( | ||
861 | 196 | 'vm.name', default=None, invalid='error', | ||
862 | 197 | help="The vm name, used as a prefix for related files." | ||
863 | 198 | )) | ||
864 | 199 | # The second most important bit to define a vm: which ubuntu release ? | ||
865 | 200 | register(config.Option( | ||
866 | 201 | 'vm.release', default=None, invalid='error', | ||
867 | 202 | help="The ubuntu release name." | ||
868 | 203 | )) | ||
869 | 204 | # The third important piece to define a vm: where to store files like the | ||
870 | 205 | # console, the user-data and meta-data files, the ssh server keys, etc. | ||
871 | 206 | register(config.Option( | ||
872 | 207 | 'vm.config_dir', default='{vm.vms_dir}/{vm.name}', | ||
873 | 208 | invalid='error', | ||
874 | 209 | help='''The directory where files specific to a vm are stored. | ||
875 | 210 | |||
876 | 211 | This includes the user-data and meta-data files used at install time (for | ||
877 | 212 | reference and easier debug) as well as the optional ssh server keys. | ||
878 | 213 | |||
879 | 214 | By default this is {vm.vms_dir}/{vm.name}. You can put it somewhere else by | ||
880 | 215 | redifining it as long as it ends up being unique for the vm. | ||
881 | 216 | |||
882 | 217 | {vm.vms_dir}/{vm.release}/{vm.name} may better suit your taste for example. | ||
883 | 218 | ''' | ||
884 | 219 | )) | ||
885 | 220 | # The options defining the vm physical characteristics | ||
886 | 221 | register(config.Option( | ||
887 | 222 | 'vm.ram_size', default='1024', | ||
888 | 223 | help="The ram size in megabytes." | ||
889 | 224 | )) | ||
890 | 225 | register(config.Option( | ||
891 | 226 | 'vm.disk_size', default='8G', | ||
892 | 227 | help='''The disk image size in bytes. | ||
893 | 228 | |||
894 | 229 | Optional suffixes "k" or "K" (kilobyte, 1024) "M" (megabyte, 1024k) "G" | ||
895 | 230 | (gigabyte, 1024M) and T (terabyte, 1024G) are supported. | ||
896 | 231 | ''')) | ||
897 | 232 | register(config.Option( | ||
898 | 233 | 'vm.cpus', default='1', | ||
899 | 234 | help="The number of cpus." | ||
900 | 235 | )) | ||
901 | 236 | register(config.Option( | ||
902 | 237 | 'vm.cpu_model', default=None, invalid='error', | ||
903 | 238 | help="The number of cpus.")) | ||
904 | 239 | register(config.Option( | ||
905 | 240 | 'vm.network', default='network=default', invalid='error', | ||
906 | 241 | help="""The --network parameter for virt-install. | ||
907 | 242 | |||
908 | 243 | This can be specialized for each machine but the default should work in most | ||
909 | 244 | setups. Watch for your DHCP server exhausting its address space if you create a | ||
910 | 245 | lot of vms with random MAC addresses. | ||
911 | 246 | """)) | ||
912 | 247 | |||
913 | 248 | register(config.Option( | ||
914 | 249 | 'vm.meta_data', default='''\ | ||
915 | 250 | instance-id: {vm.name} | ||
916 | 251 | local-hostname: {vm.name} | ||
917 | 252 | ''', | ||
918 | 253 | invalid='error', | ||
919 | 254 | help="The meta data for cloud-init to put in the seed." | ||
920 | 255 | )) | ||
921 | 256 | |||
922 | 257 | # Some bits that may added to user-data but are optional | ||
923 | 258 | |||
924 | 259 | register(config.ListOption( | ||
925 | 260 | 'vm.packages', default=None, | ||
926 | 261 | help='''A list of package names to be installed. | ||
927 | 262 | ''')) | ||
928 | 263 | register(config.Option( | ||
929 | 264 | 'vm.apt_proxy', default=None, invalid='error', | ||
930 | 265 | help='''A local proxy for apt to avoid repeated .deb downloads. | ||
931 | 266 | |||
932 | 267 | Example: | ||
933 | 268 | |||
934 | 269 | vm.apt_proxy = http://192.168.0.42:8000 | ||
935 | 270 | |||
936 | 271 | ''')) | ||
937 | 272 | register(config.ListOption( | ||
938 | 273 | 'vm.apt_sources', default=None, | ||
939 | 274 | help='''A list of apt sources entries to be added to the default ones. | ||
940 | 275 | |||
941 | 276 | Cloud-init already setup /etc/apt/sources.list with appropriate entries. Only | ||
942 | 277 | additional entries need to be specified here. | ||
943 | 278 | ''')) | ||
944 | 279 | register(config.ListOption( | ||
945 | 280 | 'vm.ssh_authorized_keys', default=None, | ||
946 | 281 | help='A list of paths to public ssh keys to be authorized for' | ||
947 | 282 | ' the default user.')) | ||
948 | 283 | register(config.ListOption( | ||
949 | 284 | 'vm.ssh_keys', default=None, | ||
950 | 285 | help='''A list of paths to server ssh keys. | ||
951 | 286 | |||
952 | 287 | Both public and private keys can be provided. Accepted ssh key types are rsa, | ||
953 | 288 | dsa and ecdsa. The file names should match <type>.*[.pub]. | ||
954 | 289 | ''')) | ||
955 | 290 | register(config.Option( | ||
956 | 291 | 'vm.update', default=False, | ||
957 | 292 | from_unicode=config.bool_from_store, | ||
958 | 293 | help='''Whether or not the vm should be updated. | ||
959 | 294 | Both apt-get update and apt-get upgrade are called if this option is set. | ||
960 | 295 | ''')) | ||
961 | 296 | register(config.Option( | ||
962 | 297 | 'vm.password', default='ubuntu', invalid='error', | ||
963 | 298 | help="The ubuntu user password." | ||
964 | 299 | )) | ||
965 | 300 | register(config.Option( | ||
966 | 301 | 'vm.launchpad_id', | ||
967 | 302 | help="The launchpad login used for launchpad ssh access from the guest." | ||
968 | 303 | )) | ||
969 | 304 | # The scripts that are executed before powering off | ||
970 | 305 | register(PathOption( | ||
971 | 306 | 'vm.root_script', default=None, | ||
972 | 307 | help='''The path to a script executed as root before powering off. | ||
973 | 308 | |||
974 | 309 | This script is executed before {vm.ubuntu_script}. | ||
975 | 310 | ''' | ||
976 | 311 | )) | ||
977 | 312 | register(PathOption( | ||
978 | 313 | 'vm.ubuntu_script', default=None, | ||
979 | 314 | help='''The path to a script executed as ubuntu before powering off. | ||
980 | 315 | |||
981 | 316 | This script is excuted after {vm.root_script}. | ||
982 | 317 | ''')) | ||
983 | 318 | register(config.ListOption( | ||
984 | 319 | 'vm.uploaded_scripts', default=None, | ||
985 | 320 | help='''A list of scripts to be uploaded to the guest. | ||
986 | 321 | |||
987 | 322 | Scripts can use config options from their vm, they will be expanded before | ||
988 | 323 | upload. All scripts are uploaded into {vm.uploaded_scripts.guest_dir} under | ||
989 | 324 | their base name. | ||
990 | 325 | ''')) | ||
991 | 326 | register(config.Option( | ||
992 | 327 | 'vm.uploaded_scripts.guest_dir', default='~ubuntu/bin', | ||
993 | 328 | help='''Where {vm.uploaded_scripts} are uploaded on the guest.''' | ||
994 | 329 | )) | ||
995 | 330 | |||
996 | 331 | |||
997 | 332 | class SetupVmError(Exception): | ||
998 | 333 | |||
999 | 334 | msg = 'setup_vm Generic Error: %r' | ||
1000 | 335 | |||
1001 | 336 | def __init__(self, msg=None, **kwds): | ||
1002 | 337 | if msg is not None: | ||
1003 | 338 | self.msg = msg | ||
1004 | 339 | for key, value in kwds.items(): | ||
1005 | 340 | setattr(self, key, value) | ||
1006 | 341 | |||
1007 | 342 | def __str__(self): | ||
1008 | 343 | return self.msg.format((), **self.__dict__) | ||
1009 | 344 | |||
1010 | 345 | __repr__ = __str__ | ||
1011 | 346 | |||
1012 | 347 | |||
1013 | 348 | class CommandError(SetupVmError): | ||
1014 | 349 | |||
1015 | 350 | msg = ''' | ||
1016 | 351 | command: {joined_cmd} | ||
1017 | 352 | retcode: {retcode} | ||
1018 | 353 | output: {out} | ||
1019 | 354 | error: {err} | ||
1020 | 355 | ''' | ||
1021 | 356 | |||
1022 | 357 | def __init__(self, cmd, retcode, out, err): | ||
1023 | 358 | super(CommandError, self).__init__(joined_cmd=' '.join(cmd), | ||
1024 | 359 | retcode=retcode, err=err, out=out) | ||
1025 | 360 | |||
1026 | 361 | class ConfigValueError(SetupVmError): | ||
1027 | 362 | |||
1028 | 363 | msg = 'Bad value "{value}" for option "{name}".' | ||
1029 | 364 | |||
1030 | 365 | def __init__(self, name, value): | ||
1031 | 366 | super(ConfigValueError, self).__init__(name=name, value=value) | ||
1032 | 367 | |||
1033 | 368 | |||
1034 | 369 | class ConfigPathNotFound(SetupVmError): | ||
1035 | 370 | |||
1036 | 371 | msg = 'No such file: {path} from {name}' | ||
1037 | 372 | |||
1038 | 373 | def __init__(self, path, name): | ||
1039 | 374 | super(ConfigPathNotFound, self).__init__(path=path, name=name) | ||
1040 | 375 | |||
1041 | 376 | |||
1042 | 377 | def run_subprocess(args): | ||
1043 | 378 | proc = subprocess.Popen(args, | ||
1044 | 379 | stdout=subprocess.PIPE, | ||
1045 | 380 | stderr=subprocess.PIPE, | ||
1046 | 381 | stdin=subprocess.PIPE) | ||
1047 | 382 | out, err = proc.communicate() | ||
1048 | 383 | if proc.returncode: | ||
1049 | 384 | raise CommandError(args, proc.returncode, out, err) | ||
1050 | 385 | return proc.returncode, out, err | ||
1051 | 386 | |||
1052 | 387 | |||
1053 | 388 | def pipe_subprocess(args): | ||
1054 | 389 | proc = subprocess.Popen(args, | ||
1055 | 390 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
1056 | 391 | return proc | ||
1057 | 392 | |||
1058 | 393 | def ssh_infos_from_path(key_path): | ||
1059 | 394 | """Analyze path to find ssh key type and kind. | ||
1060 | 395 | |||
1061 | 396 | The basename should begin with ssh type used to create the key. and end | ||
1062 | 397 | with '.pub' for a public key. | ||
1063 | 398 | |||
1064 | 399 | If the type is neither of rds, dsa or ecdsa, None if returned. | ||
1065 | 400 | |||
1066 | 401 | :param key_path: A path to an ssh key. | ||
1067 | 402 | |||
1068 | 403 | :return: (type, kind) 'type' is the ssh key type or None if neither of rds, | ||
1069 | 404 | dsa or ecdsa. 'kind' is 'public' if the path ends with '.pub', | ||
1070 | 405 | 'private' otherwise. | ||
1071 | 406 | """ | ||
1072 | 407 | base = os.path.basename(key_path) | ||
1073 | 408 | for p in ('rsa', 'dsa', 'ecdsa'): | ||
1074 | 409 | if base.startswith(p): | ||
1075 | 410 | ssh_type = p | ||
1076 | 411 | break | ||
1077 | 412 | else: | ||
1078 | 413 | ssh_type = None | ||
1079 | 414 | if base.endswith('.pub'): | ||
1080 | 415 | kind = 'public' | ||
1081 | 416 | else: | ||
1082 | 417 | kind = 'private' | ||
1083 | 418 | return ssh_type, kind | ||
1084 | 419 | |||
1085 | 420 | |||
1086 | 421 | class ConsoleEOFError(SetupVmError): | ||
1087 | 422 | |||
1088 | 423 | msg = 'Encountered EOF on console, something went wrong' | ||
1089 | 424 | |||
1090 | 425 | |||
1091 | 426 | class CloudInitError(SetupVmError): | ||
1092 | 427 | |||
1093 | 428 | msg = 'cloud-init reported: {line} check your config' | ||
1094 | 429 | |||
1095 | 430 | def __init__(self, line): | ||
1096 | 431 | super(CloudInitError, self).__init__(line=line) | ||
1097 | 432 | |||
1098 | 433 | |||
1099 | 434 | class ConsoleMonitor(object): | ||
1100 | 435 | """Monitor a console to identify known events.""" | ||
1101 | 436 | |||
1102 | 437 | def __init__(self, stream): | ||
1103 | 438 | super(ConsoleMonitor, self).__init__() | ||
1104 | 439 | self.stream = stream | ||
1105 | 440 | |||
1106 | 441 | |||
1107 | 442 | def parse(self): | ||
1108 | 443 | while True: | ||
1109 | 444 | line = self.stream.readline() | ||
1110 | 445 | yield line | ||
1111 | 446 | if not line: | ||
1112 | 447 | raise ConsoleEOFError() | ||
1113 | 448 | elif line.startswith(' * Will now halt'): | ||
1114 | 449 | # That's our final_message, we're done | ||
1115 | 450 | return | ||
1116 | 451 | elif ('Failed loading yaml blob' in line | ||
1117 | 452 | or 'Unhandled non-multipart userdata starting' in line | ||
1118 | 453 | or 'failed to render string to stdout:' in line | ||
1119 | 454 | or 'Failed loading of cloud config' in line): | ||
1120 | 455 | raise CloudInitError(line) | ||
1121 | 456 | |||
1122 | 457 | |||
1123 | 458 | class FileMonitor(ConsoleMonitor): | ||
1124 | 459 | |||
1125 | 460 | def __init__(self, path): | ||
1126 | 461 | cmd = ['tail', '-f', path] | ||
1127 | 462 | proc = pipe_subprocess(cmd) | ||
1128 | 463 | super(FileMonitor, self).__init__(proc.stdout) | ||
1129 | 464 | self.path = path | ||
1130 | 465 | self.cmd = cmd | ||
1131 | 466 | self.proc = proc | ||
1132 | 467 | self.lines = [] | ||
1133 | 468 | |||
1134 | 469 | def parse(self): | ||
1135 | 470 | try: | ||
1136 | 471 | for line in super(FileMonitor, self).parse(): | ||
1137 | 472 | self.lines.append(line) | ||
1138 | 473 | yield line | ||
1139 | 474 | finally: | ||
1140 | 475 | self.proc.terminate() | ||
1141 | 476 | |||
1142 | 477 | |||
1143 | 478 | class CIUserData(object): | ||
1144 | 479 | """Maps configuration data into cloud-init user-data. | ||
1145 | 480 | |||
1146 | 481 | This is a container for the data that will ultimately be encoded into a | ||
1147 | 482 | cloud-config-archive user-data file. | ||
1148 | 483 | """ | ||
1149 | 484 | |||
1150 | 485 | def __init__(self, conf): | ||
1151 | 486 | super(CIUserData, self).__init__() | ||
1152 | 487 | self.conf = conf | ||
1153 | 488 | # The objects we will populate before creating a yaml encoding as a | ||
1154 | 489 | # cloud-config-archive file | ||
1155 | 490 | self.cloud_config = {} | ||
1156 | 491 | self.root_hook = None | ||
1157 | 492 | self.ubuntu_hook = None | ||
1158 | 493 | self.launchpad_hook = None | ||
1159 | 494 | self.uploaded_scripts_hook = None | ||
1160 | 495 | |||
1161 | 496 | def set(self, ud_name, conf_name=None, value=None): | ||
1162 | 497 | """Set a user-data option from it's corresponding configuration one. | ||
1163 | 498 | |||
1164 | 499 | :param ud_name: user-data key. | ||
1165 | 500 | |||
1166 | 501 | :param conf_name: configuration key, If set to None, `value` should be | ||
1167 | 502 | provided. | ||
1168 | 503 | |||
1169 | 504 | :param value: value to use if `conf_name` is None. | ||
1170 | 505 | """ | ||
1171 | 506 | if value is None and conf_name is not None: | ||
1172 | 507 | value = self.conf.get(conf_name) | ||
1173 | 508 | if value is not None: | ||
1174 | 509 | self.cloud_config[ud_name] = value | ||
1175 | 510 | |||
1176 | 511 | def _file_content(self, path, option_name): | ||
1177 | 512 | full_path = os.path.expanduser(path) | ||
1178 | 513 | try: | ||
1179 | 514 | with open(full_path) as f: | ||
1180 | 515 | content = f.read() | ||
1181 | 516 | except IOError, e: | ||
1182 | 517 | if e.args[0] == errno.ENOENT: | ||
1183 | 518 | raise ConfigPathNotFound(path, option_name) | ||
1184 | 519 | else: | ||
1185 | 520 | raise | ||
1186 | 521 | return content | ||
1187 | 522 | |||
1188 | 523 | def set_list_of_paths(self, ud_name, conf_name): | ||
1189 | 524 | """Set a user-data option from its corresponding configuration one. | ||
1190 | 525 | |||
1191 | 526 | The configuration option is a list of paths and the user-data option | ||
1192 | 527 | will be a list of each file content. | ||
1193 | 528 | |||
1194 | 529 | :param ud_name: user-data key. | ||
1195 | 530 | |||
1196 | 531 | :param conf_name: configuration key. | ||
1197 | 532 | """ | ||
1198 | 533 | paths = self.conf.get(conf_name) | ||
1199 | 534 | if paths: | ||
1200 | 535 | contents = [] | ||
1201 | 536 | for p in paths: | ||
1202 | 537 | contents.append(self._file_content(p, conf_name)) | ||
1203 | 538 | self.set(ud_name, None, contents) | ||
1204 | 539 | |||
1205 | 540 | def _key_from_path(self, path, option_name): | ||
1206 | 541 | """Infer user-data key from file name.""" | ||
1207 | 542 | ssh_type, kind = ssh_infos_from_path(path) | ||
1208 | 543 | if ssh_type is None: | ||
1209 | 544 | raise ConfigValueError(option_name, path) | ||
1210 | 545 | return '%s_%s' % (ssh_type, kind) | ||
1211 | 546 | |||
1212 | 547 | def set_ssh_keys(self): | ||
1213 | 548 | """Set the server ssh keys from a list of paths. | ||
1214 | 549 | |||
1215 | 550 | Provided paths should respect some coding: | ||
1216 | 551 | |||
1217 | 552 | - the base name should start with the ssh type of their key (rsa, dsa, | ||
1218 | 553 | ecdsa), | ||
1219 | 554 | |||
1220 | 555 | - base names ending with '.pub' are for public keys, the others are for | ||
1221 | 556 | private keys. | ||
1222 | 557 | """ | ||
1223 | 558 | key_paths = self.conf.get('vm.ssh_keys') | ||
1224 | 559 | if key_paths: | ||
1225 | 560 | ssh_keys = {} | ||
1226 | 561 | for p in key_paths: | ||
1227 | 562 | key = self._key_from_path(p, 'vm.ssh_keys') | ||
1228 | 563 | ssh_keys[key] = self._file_content(p, 'vm.ssh_keys') | ||
1229 | 564 | self.set('ssh_keys', None, ssh_keys) | ||
1230 | 565 | |||
1231 | 566 | def set_apt_sources(self): | ||
1232 | 567 | sources = self.conf.get('vm.apt_sources') | ||
1233 | 568 | if sources: | ||
1234 | 569 | apt_sources = [] | ||
1235 | 570 | for src in sources: | ||
1236 | 571 | # '|' should not appear in urls nor keys so it should be safe | ||
1237 | 572 | # to use it as a separator. | ||
1238 | 573 | parts = src.split('|') | ||
1239 | 574 | if len(parts) == 1: | ||
1240 | 575 | apt_sources.append({'source': parts[0]}) | ||
1241 | 576 | else: | ||
1242 | 577 | # For PPAs, an additional GPG key should be imported in the | ||
1243 | 578 | # guest. | ||
1244 | 579 | apt_sources.append({'source': parts[0], 'keyid': parts[1]}) | ||
1245 | 580 | self.cloud_config['apt_sources'] = apt_sources | ||
1246 | 581 | |||
1247 | 582 | def append_cmd(self, cmd): | ||
1248 | 583 | cmds = self.cloud_config.get('runcmd', []) | ||
1249 | 584 | cmds.append(cmd) | ||
1250 | 585 | self.cloud_config['runcmd'] = cmds | ||
1251 | 586 | |||
1252 | 587 | def _hook_script_path(self, user): | ||
1253 | 588 | return '~%s/setup_vm_post_install' % (user,) | ||
1254 | 589 | |||
1255 | 590 | def _hook_content(self, option_name, user, hook_path, mode='0700'): | ||
1256 | 591 | # FIXME: Add more tests towards properly creating a tree on the guest | ||
1257 | 592 | # from a tree on the host. There seems to be three kind of items worth | ||
1258 | 593 | # caring about here: file content (output path, owner, chmod), file | ||
1259 | 594 | # (input and output paths, owner, chmod) and directory (path, owner, | ||
1260 | 595 | # chmod). There are also some subtle traps involved about when files | ||
1261 | 596 | # are created across various vm generations (one vm creates a dir, a mv | ||
1262 | 597 | # on top of that one doesn't, but still creates a file in this dir, | ||
1263 | 598 | # without realizing it can fail in a fresh vm). -- vila 2013-03-10 | ||
1264 | 599 | host_path = self.conf.get(option_name) | ||
1265 | 600 | if host_path is None: | ||
1266 | 601 | return None | ||
1267 | 602 | fcontent = self._file_content(host_path, option_name) | ||
1268 | 603 | # Expand options in the provided content so we report better errors | ||
1269 | 604 | expanded_content = self.conf.expand_options(fcontent) | ||
1270 | 605 | # The following will generate an additional newline at the end of the | ||
1271 | 606 | # script. I can't think of a case where it matters and it makes this | ||
1272 | 607 | # code more robust (and/or simpler) if the script/file *doesn't* end up | ||
1273 | 608 | # with a proper newline. | ||
1274 | 609 | # FIXME: This may be worth fixing if we provide a more generic way to | ||
1275 | 610 | # create a remote tree. -- vila 2013-03-10 | ||
1276 | 611 | hook_content = '''#!/bin/sh | ||
1277 | 612 | cat >{__guest_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
1278 | 613 | {__fcontent} | ||
1279 | 614 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
1280 | 615 | chown {__user}:{__user} {__guest_path} | ||
1281 | 616 | chmod {__mode} {__guest_path} | ||
1282 | 617 | ''' | ||
1283 | 618 | return hook_content.format(__user=user, __fcontent=expanded_content, | ||
1284 | 619 | __mode=mode, | ||
1285 | 620 | __guest_path=hook_path) | ||
1286 | 621 | |||
1287 | 622 | def set_boot_hook(self): | ||
1288 | 623 | # FIXME: Needs a test ensuring we execute as root -- vila 2013-03-07 | ||
1289 | 624 | hook_path = self._hook_script_path('root') | ||
1290 | 625 | content = self._hook_content('vm.root_script', 'root', hook_path) | ||
1291 | 626 | if content is not None: | ||
1292 | 627 | self.root_hook = content | ||
1293 | 628 | self.append_cmd(hook_path) | ||
1294 | 629 | |||
1295 | 630 | def set_ubuntu_hook(self): | ||
1296 | 631 | # FIXME: Needs a test ensuring we execute as ubuntu -- vila 2013-03-07 | ||
1297 | 632 | hook_path = self._hook_script_path('ubuntu') | ||
1298 | 633 | content = self._hook_content('vm.ubuntu_script', 'ubuntu', hook_path) | ||
1299 | 634 | if content is not None: | ||
1300 | 635 | self.ubuntu_hook = content | ||
1301 | 636 | self.append_cmd(['su', '-l', '-c', hook_path, 'ubuntu']) | ||
1302 | 637 | |||
1303 | 638 | def set_launchpad_access(self): | ||
1304 | 639 | # FIXME: Needs a test that we can really access launchpad properly via | ||
1305 | 640 | # ssh. Can only be done as a real launchpad user and as such requires | ||
1306 | 641 | # cooperation :) I.e. Some configuration option set by the user will | ||
1307 | 642 | # trigger the test -- vila 2013-03-14 | ||
1308 | 643 | lp_id = self.conf.get('vm.launchpad_id') | ||
1309 | 644 | if lp_id is None: | ||
1310 | 645 | return | ||
1311 | 646 | # Use the specified ssh key found in ~/.ssh as the private key. The | ||
1312 | 647 | # user is supposed to have uploaded the public one. | ||
1313 | 648 | local_path = os.path.join('~', '.ssh', '%s@setup_vm' % (lp_id,)) | ||
1314 | 649 | # Force id_rsa or we'll need a .ssh/config to point to user@setup_vm | ||
1315 | 650 | # for .lauchpad.net. | ||
1316 | 651 | hook_path = '/home/ubuntu/.ssh/id_rsa' | ||
1317 | 652 | dir_path = os.path.dirname(hook_path) | ||
1318 | 653 | try: | ||
1319 | 654 | fcontent = self._file_content(local_path, 'vm.launchpad_id') | ||
1320 | 655 | except ConfigPathNotFound, e: | ||
1321 | 656 | e.msg = ('You need to create the {p} keypair and upload {p}.pub to' | ||
1322 | 657 | ' launchpad.\n' | ||
1323 | 658 | 'See vm.launchpad_id in README.'.format(p=local_path)) | ||
1324 | 659 | raise e | ||
1325 | 660 | # FIXME: ~Duplicated from _hook_content. -- vila 2013-03-10 | ||
1326 | 661 | |||
1327 | 662 | # FIXME: If this hook is executed before the ubuntu user is created we | ||
1328 | 663 | # need to chown/chmod ~ubuntu which is bad. This happens when a | ||
1329 | 664 | # -pristine vm is created and lead to GUI login failing because it | ||
1330 | 665 | # can't create any dir/file there. The fix is to only create a script | ||
1331 | 666 | # that will be executed via runcmd so it will run later and avoid the | ||
1332 | 667 | # issue. -- vila 2013-03-21 | ||
1333 | 668 | hook_content = '''#!/bin/sh | ||
1334 | 669 | mkdir -p {dir_path} | ||
1335 | 670 | chown {user}:{user} ~ubuntu | ||
1336 | 671 | chmod {dir_mode} ~ubuntu | ||
1337 | 672 | chown {user}:{user} {dir_path} | ||
1338 | 673 | chmod {dir_mode} {dir_path} | ||
1339 | 674 | cat >{guest_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
1340 | 675 | {fcontent} | ||
1341 | 676 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
1342 | 677 | chown {user}:{user} {guest_path} | ||
1343 | 678 | chmod {file_mode} {guest_path} | ||
1344 | 679 | ''' | ||
1345 | 680 | self.launchpad_hook = self.conf.expand_options( | ||
1346 | 681 | hook_content, | ||
1347 | 682 | env=dict(user='ubuntu', fcontent=fcontent, | ||
1348 | 683 | file_mode='0400', guest_path=hook_path, | ||
1349 | 684 | dir_mode='0700', dir_path=dir_path)) | ||
1350 | 685 | self.append_cmd(['sudo', '-u', 'ubuntu', | ||
1351 | 686 | 'bzr', 'launchpad-login', lp_id]) | ||
1352 | 687 | |||
1353 | 688 | def set_uploaded_scripts(self): | ||
1354 | 689 | script_paths = self.conf.get('vm.uploaded_scripts') | ||
1355 | 690 | if not script_paths: | ||
1356 | 691 | return | ||
1357 | 692 | hook_path = '~ubuntu/setup_vm_uploads' | ||
1358 | 693 | bindir = self.conf.get('vm.uploaded_scripts.guest_dir') | ||
1359 | 694 | out = StringIO() | ||
1360 | 695 | out.write('''#!/bin/sh | ||
1361 | 696 | cat >{hook_path} <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
1362 | 697 | mkdir -p {bindir} | ||
1363 | 698 | cd {bindir} | ||
1364 | 699 | '''.format(**locals())) | ||
1365 | 700 | for path in script_paths: | ||
1366 | 701 | fcontent = self._file_content(path, 'vm.uploaded_scripts') | ||
1367 | 702 | expanded = self.conf.expand_options(fcontent) | ||
1368 | 703 | base = os.path.basename(path) | ||
1369 | 704 | # FIXME: ~Duplicated from _hook_content. -- vila 2012-03-15 | ||
1370 | 705 | out.write('''cat >{base} <<'EOF{base}' | ||
1371 | 706 | {expanded} | ||
1372 | 707 | EOF{base} | ||
1373 | 708 | chmod 0755 {base} | ||
1374 | 709 | '''.format(**locals())) | ||
1375 | 710 | |||
1376 | 711 | out.write('''EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
1377 | 712 | chown {user}:{user} {hook_path} | ||
1378 | 713 | chmod 0700 {hook_path} | ||
1379 | 714 | '''.format(user='ubuntu',**locals())) | ||
1380 | 715 | self.uploaded_scripts_hook = out.getvalue() | ||
1381 | 716 | self.append_cmd(['su', '-l', '-c', hook_path, 'ubuntu']) | ||
1382 | 717 | |||
1383 | 718 | def set_poweroff(self): | ||
1384 | 719 | # We want to shutdown properly after installing. This is safe to set | ||
1385 | 720 | # here as subsequent boots will ignore this setting, letting us use the | ||
1386 | 721 | # vm ;) | ||
1387 | 722 | if self.conf.get('vm.release') in ('precise', 'quantal'): | ||
1388 | 723 | # Curse cloud-init lack of compatibility | ||
1389 | 724 | self.append_cmd('halt') | ||
1390 | 725 | else: | ||
1391 | 726 | self.set('power_state', None, {'mode': 'poweroff'}) | ||
1392 | 727 | |||
1393 | 728 | def populate(self): | ||
1394 | 729 | # Common and non-configurable options | ||
1395 | 730 | if self.conf.get('vm.release') == 'precise': | ||
1396 | 731 | # Curse cloud-init lack of compatibility | ||
1397 | 732 | msg = 'setup_vm finished installing in $UPTIME seconds.' | ||
1398 | 733 | else: | ||
1399 | 734 | msg = 'setup_vm finished installing in ${uptime} seconds.' | ||
1400 | 735 | self.set('final_message', None, msg) | ||
1401 | 736 | self.set('manage_etc_hosts', None, True) | ||
1402 | 737 | self.set('chpasswd', None, dict(expire=False)) | ||
1403 | 738 | # Configurable options | ||
1404 | 739 | self.set('password', 'vm.password') | ||
1405 | 740 | self.set_list_of_paths('ssh_authorized_keys', 'vm.ssh_authorized_keys') | ||
1406 | 741 | self.set_ssh_keys() | ||
1407 | 742 | self.set('apt_proxy', 'vm.apt_proxy') | ||
1408 | 743 | # Both user-data keys are set from the same config key, we don't | ||
1409 | 744 | # provide a finer access. | ||
1410 | 745 | self.set('apt_update', 'vm.update') | ||
1411 | 746 | self.set('apt_upgrade', 'vm.update') | ||
1412 | 747 | self.set_apt_sources() | ||
1413 | 748 | self.set('packages', 'vm.packages') | ||
1414 | 749 | self.set_launchpad_access() | ||
1415 | 750 | # uploaded scripts | ||
1416 | 751 | self.set_uploaded_scripts() | ||
1417 | 752 | # The commands executed before powering off | ||
1418 | 753 | self.set_boot_hook() | ||
1419 | 754 | self.set_ubuntu_hook() | ||
1420 | 755 | # This must be called last so previous commands (for precise and | ||
1421 | 756 | # quantal) can be executed before powering off | ||
1422 | 757 | self.set_poweroff() | ||
1423 | 758 | |||
1424 | 759 | def add_boot_hook(self, parts, hook): | ||
1425 | 760 | if hook is not None: | ||
1426 | 761 | parts.append({'content': '#cloud-boothook\n' + hook}) | ||
1427 | 762 | |||
1428 | 763 | def dump(self): | ||
1429 | 764 | parts = [{'content': '#cloud-config\n' | ||
1430 | 765 | + yaml.safe_dump(self.cloud_config)}] | ||
1431 | 766 | self.add_boot_hook(parts, self.root_hook) | ||
1432 | 767 | self.add_boot_hook(parts, self.ubuntu_hook) | ||
1433 | 768 | self.add_boot_hook(parts, self.launchpad_hook) | ||
1434 | 769 | self.add_boot_hook(parts, self.uploaded_scripts_hook) | ||
1435 | 770 | # Wrap the lot into a cloud config archive | ||
1436 | 771 | return '#cloud-config-archive\n' + yaml.safe_dump(parts) | ||
1437 | 772 | |||
1438 | 773 | |||
1439 | 774 | def vm_states(source=None): | ||
1440 | 775 | """A dict of states for vms indexed by name. | ||
1441 | 776 | |||
1442 | 777 | :param source: A list of lines as produced by virsh list --all without | ||
1443 | 778 | decorations (header/footer). | ||
1444 | 779 | """ | ||
1445 | 780 | if source is None: | ||
1446 | 781 | retcode, out, err = run_subprocess(['virsh', 'list', '--all']) | ||
1447 | 782 | # Get rid of header/footer | ||
1448 | 783 | source = out.splitlines()[2:-1] | ||
1449 | 784 | states = {} | ||
1450 | 785 | for line in source: | ||
1451 | 786 | caret_or_id, name, state = line.split(None, 2) | ||
1452 | 787 | states[name] = state | ||
1453 | 788 | return states | ||
1454 | 789 | |||
1455 | 790 | |||
1456 | 791 | class VM(object): | ||
1457 | 792 | |||
1458 | 793 | def __init__(self, conf): | ||
1459 | 794 | self.conf = conf | ||
1460 | 795 | self._config_dir = None | ||
1461 | 796 | |||
1462 | 797 | def ensure_dir(self, path): | ||
1463 | 798 | try: | ||
1464 | 799 | os.mkdir(path) | ||
1465 | 800 | except OSError, e: | ||
1466 | 801 | # FIXME: Try to create the parent dir ? | ||
1467 | 802 | if e.errno == errno.EEXIST: | ||
1468 | 803 | pass | ||
1469 | 804 | else: | ||
1470 | 805 | raise | ||
1471 | 806 | |||
1472 | 807 | def ensure_config_dir(self): | ||
1473 | 808 | if self._config_dir is None: | ||
1474 | 809 | # FIXME: expanduser is not tested | ||
1475 | 810 | self._config_dir = os.path.expanduser( | ||
1476 | 811 | self.conf.get('vm.config_dir')) | ||
1477 | 812 | self.ensure_dir(self._config_dir) | ||
1478 | 813 | |||
1479 | 814 | def _ssh_keygen(self, key_path): | ||
1480 | 815 | ssh_type, kind = ssh_infos_from_path(key_path) | ||
1481 | 816 | path = os.path.expanduser(key_path) # Just in case | ||
1482 | 817 | if kind == 'private': # public will be generated at the same time | ||
1483 | 818 | run_subprocess( | ||
1484 | 819 | ['ssh-keygen', '-f', path, '-N', '', '-t', ssh_type, | ||
1485 | 820 | '-C', self.conf.get('vm.name')]) | ||
1486 | 821 | |||
1487 | 822 | def ssh_keygen(self): | ||
1488 | 823 | self.ensure_config_dir() | ||
1489 | 824 | keys = self.conf.get('vm.ssh_keys') | ||
1490 | 825 | for key in keys: | ||
1491 | 826 | self._ssh_keygen(key) | ||
1492 | 827 | |||
1493 | 828 | |||
1494 | 829 | class Kvm(VM): | ||
1495 | 830 | |||
1496 | 831 | def __init__(self, conf): | ||
1497 | 832 | super(Kvm, self).__init__(conf) | ||
1498 | 833 | # Seed files | ||
1499 | 834 | self._meta_data_path = None | ||
1500 | 835 | self._user_data_path = None | ||
1501 | 836 | # Disk paths | ||
1502 | 837 | self._seed_path = None | ||
1503 | 838 | self._disk_image_path = None | ||
1504 | 839 | |||
1505 | 840 | self._console_path = None | ||
1506 | 841 | |||
1507 | 842 | def _download_in_cache(self, source_url, name, force=False): | ||
1508 | 843 | """Download ``name`` from ``source_url`` in ``vm.download_cache``. | ||
1509 | 844 | |||
1510 | 845 | :param source_url: The url where the file to download is located | ||
1511 | 846 | |||
1512 | 847 | :param name: The name of the file to download (also used as the name | ||
1513 | 848 | for the downloaded file). | ||
1514 | 849 | |||
1515 | 850 | :param force: Remove the file from the cache if present. | ||
1516 | 851 | |||
1517 | 852 | :return: False if the file is in the download cache, True if a download | ||
1518 | 853 | occurred. | ||
1519 | 854 | """ | ||
1520 | 855 | source = urlutils.join(source_url, name) | ||
1521 | 856 | download_dir = self.conf.get('vm.download_cache') | ||
1522 | 857 | if not os.path.exists(download_dir): | ||
1523 | 858 | raise ConfigValueError('vm.download_cache', download_dir) | ||
1524 | 859 | target = os.path.join(download_dir, name) | ||
1525 | 860 | # FIXME: By default the download dir may be under root control, but if | ||
1526 | 861 | # a user chose to use a different one under his own control, it would | ||
1527 | 862 | # be nice to not require sudo usage. -- vila 2013-02-06 | ||
1528 | 863 | if force: | ||
1529 | 864 | run_subprocess(['sudo', 'rm', '-f', target]) | ||
1530 | 865 | if not os.path.exists(target): | ||
1531 | 866 | # FIXME: We do ask for a progress bar but it's not displayed | ||
1532 | 867 | # (run_subprocess capture both stdout and stderr) ! At least while | ||
1533 | 868 | # used interactively, it should. -- vila 2013-02-06 | ||
1534 | 869 | run_subprocess(['sudo', 'wget', '--progress=dot:mega','-O', | ||
1535 | 870 | target, source]) | ||
1536 | 871 | return True | ||
1537 | 872 | else: | ||
1538 | 873 | return False | ||
1539 | 874 | |||
1540 | 875 | def download_iso(self, force=False): | ||
1541 | 876 | """Download the iso to install the vm. | ||
1542 | 877 | |||
1543 | 878 | :return: False if the iso is in the download cache, True if a download | ||
1544 | 879 | occurred. | ||
1545 | 880 | """ | ||
1546 | 881 | return self._download_in_cache(self.conf.get('vm.iso_url'), | ||
1547 | 882 | self.conf.get('vm.iso_name'), | ||
1548 | 883 | force=force) | ||
1549 | 884 | |||
1550 | 885 | def download_cloud_image(self, force=False): | ||
1551 | 886 | """Download the cloud image to install the vm. | ||
1552 | 887 | |||
1553 | 888 | :return: False if the image is in the download cache, True if a | ||
1554 | 889 | download occurred. | ||
1555 | 890 | """ | ||
1556 | 891 | return self._download_in_cache(self.conf.get('vm.cloud_image_url'), | ||
1557 | 892 | self.conf.get('vm.cloud_image_name'), | ||
1558 | 893 | force=force) | ||
1559 | 894 | |||
1560 | 895 | def create_meta_data(self): | ||
1561 | 896 | self.ensure_config_dir() | ||
1562 | 897 | self._meta_data_path = os.path.join(self._config_dir, 'meta-data') | ||
1563 | 898 | with open(self._meta_data_path, 'w') as f: | ||
1564 | 899 | f.write(self.conf.get('vm.meta_data')) | ||
1565 | 900 | |||
1566 | 901 | def create_user_data(self): | ||
1567 | 902 | ci_user_data = CIUserData(self.conf) | ||
1568 | 903 | ci_user_data.populate() | ||
1569 | 904 | self.ensure_config_dir() | ||
1570 | 905 | self._user_data_path = os.path.join(self._config_dir, 'user-data') | ||
1571 | 906 | with open(self._user_data_path, 'w') as f: | ||
1572 | 907 | f.write(ci_user_data.dump()) | ||
1573 | 908 | |||
1574 | 909 | def create_seed(self): | ||
1575 | 910 | if self._meta_data_path is None: | ||
1576 | 911 | self.create_meta_data() | ||
1577 | 912 | if self._user_data_path is None: | ||
1578 | 913 | self.create_user_data() | ||
1579 | 914 | images_dir = self.conf.get('vm.images_dir') | ||
1580 | 915 | seed_path = os.path.join( | ||
1581 | 916 | images_dir, self.conf.expand_options('{vm.name}.seed')) | ||
1582 | 917 | run_subprocess( | ||
1583 | 918 | # We create the seed in the ``vm.images_dir`` directory, so | ||
1584 | 919 | # ``sudo`` is required | ||
1585 | 920 | ['sudo', | ||
1586 | 921 | 'genisoimage', '-output', seed_path, '-volid', 'cidata', | ||
1587 | 922 | '-joliet', '-rock', '-input-charset', 'default', | ||
1588 | 923 | '-graft-points', | ||
1589 | 924 | 'user-data=%s' % (self._user_data_path,), | ||
1590 | 925 | 'meta-data=%s' % (self._meta_data_path,), | ||
1591 | 926 | ]) | ||
1592 | 927 | self._seed_path = seed_path | ||
1593 | 928 | |||
1594 | 929 | def create_disk_image(self): | ||
1595 | 930 | raise NotImplementedError(self.create_disk_image) | ||
1596 | 931 | |||
1597 | 932 | def _wait_for_install_with_seed(self): | ||
1598 | 933 | # The console is created by virt-install which requires sudo but creates | ||
1599 | 934 | # the file 0600 for libvirt-qemu. We give read access to all otherwise | ||
1600 | 935 | # 'tail -f' requires sudo and can't be killed anymore. | ||
1601 | 936 | run_subprocess(['sudo', 'chmod', '0644', self._console_path]) | ||
1602 | 937 | # While `virt-install` is running, let's connect to the console | ||
1603 | 938 | console = FileMonitor(self._console_path) | ||
1604 | 939 | try: | ||
1605 | 940 | for line in console.parse(): | ||
1606 | 941 | # FIXME: We need some way to activate this dynamically (conf var defaulting to | ||
1607 | 942 | # env var OR cmdline parameter ? -- vila 2013-02-11 | ||
1608 | 943 | # print "read: [%s]" % (line,) # so useful for debug... | ||
1609 | 944 | pass | ||
1610 | 945 | except (ConsoleEOFError, CloudInitError), e: | ||
1611 | 946 | # FIXME: No test covers this path -- vila 2013-02-15 | ||
1612 | 947 | err_lines = ['Suspicious line from cloud-init.\n', | ||
1613 | 948 | '\t' + console.lines[-1], | ||
1614 | 949 | 'Check the configuration:\n'] | ||
1615 | 950 | with open(self._meta_data_path) as f: | ||
1616 | 951 | err_lines.append('meta-data content:\n') | ||
1617 | 952 | err_lines.extend(f.readlines()) | ||
1618 | 953 | with open(self._user_data_path) as f: | ||
1619 | 954 | err_lines.append('user-data content:\n') | ||
1620 | 955 | err_lines.extend(f.readlines()) | ||
1621 | 956 | raise CommandError(console.cmd, console.proc.returncode, | ||
1622 | 957 | '\n'.join(console.lines), | ||
1623 | 958 | ''.join(err_lines)) | ||
1624 | 959 | |||
1625 | 960 | def install(self): | ||
1626 | 961 | # Create a kvm, relying on cloud-init to customize the base image. | ||
1627 | 962 | # | ||
1628 | 963 | # There are two processes involvded here: | ||
1629 | 964 | # - virt-install creates the vm and boots it. | ||
1630 | 965 | # - progress is monitored via the console to detect cloud-final. | ||
1631 | 966 | # | ||
1632 | 967 | # Once cloud-init has finished, the vm can be powered off. | ||
1633 | 968 | |||
1634 | 969 | # FIXME: If the install doesn't finish after $time, emit a warning and | ||
1635 | 970 | # terminate self.install_proc. | ||
1636 | 971 | # FIXME: If we can't connect to the console, emit a warning and | ||
1637 | 972 | # terminate console and self.install_proc. | ||
1638 | 973 | # FIXME: If we don't receive anything on the console after $time2, emit | ||
1639 | 974 | # a warning and terminate console and self.install_proc. | ||
1640 | 975 | # -- vila 2013-02-07 | ||
1641 | 976 | if self._seed_path is None: | ||
1642 | 977 | self.create_seed() | ||
1643 | 978 | if self._disk_image_path is None: | ||
1644 | 979 | self.create_disk_image() | ||
1645 | 980 | # FIXME: Install time is probably a good time to delete the | ||
1646 | 981 | # console. While it makes sense to accumulate for all runs for a given | ||
1647 | 982 | # install, keeping them without any limit nor roration is likely to | ||
1648 | 983 | # cause issues at some point... -- vila 2013-02-20 | ||
1649 | 984 | self._console_path = os.path.join( | ||
1650 | 985 | self.conf.get('vm.images_dir'), | ||
1651 | 986 | '%s.console' % (self.conf.get('vm.name'),)) | ||
1652 | 987 | run_subprocess( | ||
1653 | 988 | ['sudo', 'virt-install', | ||
1654 | 989 | # To ensure we're not bitten again by http://pad.lv/1157272 where | ||
1655 | 990 | # virt-install wrongly detect virtualbox. -- vila 2013-03-20 | ||
1656 | 991 | '--connect', 'qemu:///system', | ||
1657 | 992 | # Without --noautoconsole, virt-install will relay the console, | ||
1658 | 993 | # that's not appropriate for our needs so we'll connect later | ||
1659 | 994 | # ourselves | ||
1660 | 995 | '--noautoconsole', | ||
1661 | 996 | # We define the console as a file so we can monitor the install | ||
1662 | 997 | # via 'tail -f' | ||
1663 | 998 | '--serial', 'file,path=%s' % (self._console_path,), | ||
1664 | 999 | '--network', self.conf.get('vm.network'), | ||
1665 | 1000 | # Anticipate that we'll need a graphic card defined | ||
1666 | 1001 | '--graphics', 'spice', | ||
1667 | 1002 | '--name', self.conf.get('vm.name'), | ||
1668 | 1003 | '--ram', self.conf.get('vm.ram_size'), | ||
1669 | 1004 | '--vcpus', self.conf.get('vm.cpus'), | ||
1670 | 1005 | '--disk', 'path=%s,format=qcow2' % (self._disk_image_path,), | ||
1671 | 1006 | '--disk', 'path=%s' % (self._seed_path,), | ||
1672 | 1007 | # We just boot, cloud-init will handle the installs we need | ||
1673 | 1008 | '--boot', 'hd', '--hvm', | ||
1674 | 1009 | ]) | ||
1675 | 1010 | self._wait_for_install_with_seed() | ||
1676 | 1011 | # We've seen the console signaling halt, but the vm will need a bit | ||
1677 | 1012 | # more time to get there so we help it a bit. | ||
1678 | 1013 | if self.conf.get('vm.release') in ('precise', 'quantal'): | ||
1679 | 1014 | # cloud-init doesn't implement power_state until raring and need a | ||
1680 | 1015 | # gentle nudge. | ||
1681 | 1016 | self.poweroff() | ||
1682 | 1017 | vm_name = self.conf.get('vm.name') | ||
1683 | 1018 | while True: | ||
1684 | 1019 | state = vm_states()[vm_name] | ||
1685 | 1020 | # We expect the vm's state to be 'in shutdown' but in some rare | ||
1686 | 1021 | # occasions we may catch 'running' before getting 'in shutdown'. | ||
1687 | 1022 | if state in ('in shutdown', 'running'): | ||
1688 | 1023 | # Ok, querying the state takes time, this regulates the polling | ||
1689 | 1024 | # enough that we don't need to sleep. | ||
1690 | 1025 | continue | ||
1691 | 1026 | elif state == 'shut off': | ||
1692 | 1027 | # Good, we're done | ||
1693 | 1028 | break | ||
1694 | 1029 | # FIXME: No idea on how to test the following. Manually tested by | ||
1695 | 1030 | # altering the expected state above and running 'selftest.py -v' | ||
1696 | 1031 | # which errors out for test_install_with_seed and | ||
1697 | 1032 | # test_install_backing. Also reproduced when 'running' wasn't | ||
1698 | 1033 | # expected before 'in shutdown' -- vila 2013-02-19 | ||
1699 | 1034 | # Unexpected state reached, bad. | ||
1700 | 1035 | raise SetupVmError('Something went wrong during {name} install\n' | ||
1701 | 1036 | 'The vm ended in state: {state}\n' | ||
1702 | 1037 | 'Check the console at {path}', | ||
1703 | 1038 | name=vm_name, state=state, | ||
1704 | 1039 | path=self._console_path) | ||
1705 | 1040 | |||
1706 | 1041 | def poweroff(self): | ||
1707 | 1042 | return run_subprocess( | ||
1708 | 1043 | ['sudo', 'virsh', 'destroy', self.conf.get('vm.name')]) | ||
1709 | 1044 | |||
1710 | 1045 | def undefine(self): | ||
1711 | 1046 | return run_subprocess( | ||
1712 | 1047 | ['sudo', 'virsh', 'undefine', self.conf.get('vm.name'), | ||
1713 | 1048 | '--remove-all-storage']) | ||
1714 | 1049 | |||
1715 | 1050 | |||
1716 | 1051 | class KvmFromCloudImage(Kvm): | ||
1717 | 1052 | |||
1718 | 1053 | def create_disk_image(self, src_name=None, dst_name=None): | ||
1719 | 1054 | """Create a disk image from a cloud one.""" | ||
1720 | 1055 | if src_name is None: | ||
1721 | 1056 | src_name = self.conf.get('vm.cloud_image_name') | ||
1722 | 1057 | if dst_name is None: | ||
1723 | 1058 | dst_name = self.conf.expand_options('{vm.name}.qcow2') | ||
1724 | 1059 | cloud_image_path = os.path.join( | ||
1725 | 1060 | self.conf.get('vm.download_cache'), src_name) | ||
1726 | 1061 | disk_image_path = os.path.join( | ||
1727 | 1062 | self.conf.get('vm.images_dir'), dst_name) | ||
1728 | 1063 | run_subprocess( | ||
1729 | 1064 | ['sudo', 'qemu-img', 'convert', | ||
1730 | 1065 | '-O', 'qcow2', cloud_image_path, disk_image_path]) | ||
1731 | 1066 | run_subprocess( | ||
1732 | 1067 | ['sudo', 'qemu-img', 'resize', | ||
1733 | 1068 | disk_image_path, self.conf.get('vm.disk_size')]) | ||
1734 | 1069 | self._disk_image_path = disk_image_path | ||
1735 | 1070 | |||
1736 | 1071 | |||
1737 | 1072 | class KvmFromBacking(Kvm): | ||
1738 | 1073 | |||
1739 | 1074 | def create_disk_image(self, src_name=None, dst_name=None): | ||
1740 | 1075 | """Create a disk image backed by an existing one.""" | ||
1741 | 1076 | backing_image_path = os.path.join( | ||
1742 | 1077 | self.conf.get('vm.images_dir'), | ||
1743 | 1078 | self.conf.expand_options('{vm.backing}')) | ||
1744 | 1079 | disk_image_path = os.path.join( | ||
1745 | 1080 | self.conf.get('vm.images_dir'), | ||
1746 | 1081 | self.conf.expand_options('{vm.name}.qcow2')) | ||
1747 | 1082 | run_subprocess( | ||
1748 | 1083 | ['sudo', 'qemu-img', 'create', '-f', 'qcow2', | ||
1749 | 1084 | '-b', backing_image_path, disk_image_path]) | ||
1750 | 1085 | run_subprocess( | ||
1751 | 1086 | ['sudo', 'qemu-img', 'resize', | ||
1752 | 1087 | disk_image_path, self.conf.get('vm.disk_size')]) | ||
1753 | 1088 | self._disk_image_path = disk_image_path | ||
1754 | 1089 | |||
1755 | 1090 | |||
1756 | 1091 | class ArgParser(argparse.ArgumentParser): | ||
1757 | 1092 | """A parser for the setup_vm script.""" | ||
1758 | 1093 | |||
1759 | 1094 | def __init__(self): | ||
1760 | 1095 | description = 'Set up virtual machines from a configuration file.' | ||
1761 | 1096 | super(ArgParser, self).__init__( | ||
1762 | 1097 | prog='setup_vm.py', description=description) | ||
1763 | 1098 | self.add_argument( | ||
1764 | 1099 | 'name', help='Virtual machine section in the configuration file.') | ||
1765 | 1100 | self.add_argument('--download', '-d', action="store_true", | ||
1766 | 1101 | help='Force download of the required image.') | ||
1767 | 1102 | self.add_argument('--ssh-keygen', '-k', action="store_true", | ||
1768 | 1103 | help='Generate the ssh server keys (if any).') | ||
1769 | 1104 | self.add_argument('--install', '-i', action="store_true", | ||
1770 | 1105 | help='Install the virtual machine.') | ||
1771 | 1106 | |||
1772 | 1107 | def parse_args(self, args=None, out=None, err=None): | ||
1773 | 1108 | """Parse arguments, overridding stdout/stderr if provided. | ||
1774 | 1109 | |||
1775 | 1110 | Overridding stdout/stderr is provided for tests. | ||
1776 | 1111 | |||
1777 | 1112 | :params args: Defaults to sys.argv[1:]. | ||
1778 | 1113 | |||
1779 | 1114 | :param out: Defaults to sys.stdout. | ||
1780 | 1115 | |||
1781 | 1116 | :param err: Defaults to sys.stderr. | ||
1782 | 1117 | """ | ||
1783 | 1118 | out_orig = sys.stdout | ||
1784 | 1119 | err_orig = sys.stderr | ||
1785 | 1120 | try: | ||
1786 | 1121 | if out is not None: | ||
1787 | 1122 | sys.stdout = out | ||
1788 | 1123 | if err is not None: | ||
1789 | 1124 | sys.stderr = err | ||
1790 | 1125 | return super(ArgParser, self).parse_args(args) | ||
1791 | 1126 | finally: | ||
1792 | 1127 | sys.stdout = out_orig | ||
1793 | 1128 | sys.stderr = err_orig | ||
1794 | 1129 | |||
1795 | 1130 | |||
1796 | 1131 | |||
1797 | 1132 | arg_parser = ArgParser() | ||
1798 | 1133 | |||
1799 | 1134 | class Command(object): | ||
1800 | 1135 | |||
1801 | 1136 | def __init__(self, vm): | ||
1802 | 1137 | self.vm = vm | ||
1803 | 1138 | |||
1804 | 1139 | |||
1805 | 1140 | class Download(Command): | ||
1806 | 1141 | |||
1807 | 1142 | def run(self): | ||
1808 | 1143 | # FIXME: what needs to be downloaded should depend on the type of the | ||
1809 | 1144 | # vm (possibly errors if there is nothing to download). -- vila | ||
1810 | 1145 | # 2013-02-06 | ||
1811 | 1146 | self.vm.download_cloud_image(force=True) | ||
1812 | 1147 | |||
1813 | 1148 | |||
1814 | 1149 | class SshKeyGen(Command): | ||
1815 | 1150 | |||
1816 | 1151 | def run(self): | ||
1817 | 1152 | self.vm.ssh_keygen() | ||
1818 | 1153 | |||
1819 | 1154 | |||
1820 | 1155 | class Install(Command): | ||
1821 | 1156 | |||
1822 | 1157 | def run(self): | ||
1823 | 1158 | vm_name = self.vm.conf.get('vm.name') | ||
1824 | 1159 | state = vm_states().get(vm_name, None) | ||
1825 | 1160 | if state == 'shut off': | ||
1826 | 1161 | self.vm.undefine() | ||
1827 | 1162 | elif state == 'running': | ||
1828 | 1163 | raise SetupVmError('{name} is running', name=vm_name) | ||
1829 | 1164 | # FIXME: The installation method may vary depending on the vm type. | ||
1830 | 1165 | # -- vila 2013-02-06 | ||
1831 | 1166 | self.vm.install() | ||
1832 | 1167 | |||
1833 | 1168 | |||
1834 | 1169 | def build_commands(args=None, out=None, err=None): | ||
1835 | 1170 | cmds = [] | ||
1836 | 1171 | if args is None: | ||
1837 | 1172 | args = sys.argv[1:] | ||
1838 | 1173 | |||
1839 | 1174 | ns = arg_parser.parse_args(args, out=out, err=err) | ||
1840 | 1175 | |||
1841 | 1176 | conf = VmStack(ns.name) | ||
1842 | 1177 | with_backing = conf.get('vm.backing') | ||
1843 | 1178 | if with_backing is None: | ||
1844 | 1179 | vm = KvmFromCloudImage(conf) | ||
1845 | 1180 | else: | ||
1846 | 1181 | vm = KvmFromBacking(conf) | ||
1847 | 1182 | if ns.download: | ||
1848 | 1183 | cmds.append(Download(vm)) | ||
1849 | 1184 | if ns.ssh_keygen: | ||
1850 | 1185 | cmds.append(SshKeyGen(vm)) | ||
1851 | 1186 | if ns.install: | ||
1852 | 1187 | cmds.append(Install(vm)) | ||
1853 | 1188 | return cmds | ||
1854 | 1189 | |||
1855 | 1190 | |||
1856 | 1191 | def run(args=None): | ||
1857 | 1192 | cmds = build_commands(args) | ||
1858 | 1193 | for cmd in cmds: | ||
1859 | 1194 | try: | ||
1860 | 1195 | cmd.run() | ||
1861 | 1196 | except SetupVmError, e: | ||
1862 | 1197 | # Stop on first error | ||
1863 | 1198 | print 'ERROR: %s' % e | ||
1864 | 1199 | exit(-1) | ||
1865 | 1200 | |||
1866 | 1201 | |||
1867 | 1202 | if __name__ == "__main__": | ||
1868 | 1203 | run() | ||
1869 | 0 | 1204 | ||
1870 | === added file 'setup_vm/bin/ubuntu_admin.sh' | |||
1871 | --- setup_vm/bin/ubuntu_admin.sh 1970-01-01 00:00:00 +0000 | |||
1872 | +++ setup_vm/bin/ubuntu_admin.sh 2013-04-17 01:29:27 +0000 | |||
1873 | @@ -0,0 +1,2 @@ | |||
1874 | 1 | #!/bin/sh | ||
1875 | 2 | adduser ubuntu admin | ||
1876 | 0 | 3 | ||
1877 | === added directory 'setup_vm/pay' | |||
1878 | === added file 'setup_vm/pay/install' | |||
1879 | --- setup_vm/pay/install 1970-01-01 00:00:00 +0000 | |||
1880 | +++ setup_vm/pay/install 2013-04-17 01:29:27 +0000 | |||
1881 | @@ -0,0 +1,40 @@ | |||
1882 | 1 | #!/bin/sh -ex | ||
1883 | 2 | |||
1884 | 3 | # Allow ssh access to launchpad. | ||
1885 | 4 | # This should probably be provided by setup_vm. -- vila 2013-03-10 | ||
1886 | 5 | ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts | ||
1887 | 6 | # Get the branch. | ||
1888 | 7 | bzr branch lp:canonical-payment-service {pay.src_dir} | ||
1889 | 8 | # Get the download cache. | ||
1890 | 9 | bzr branch lp:~canonical-isd-hackers/+junk/download-cache | ||
1891 | 10 | # Setup the environment. | ||
1892 | 11 | cd {pay.src_dir} | ||
1893 | 12 | # Get the version controlled configs. | ||
1894 | 13 | bzr branch lp:~canonical-isd-hackers/isd-configs/payments-config branches/project | ||
1895 | 14 | # Bootstrap the dependencies | ||
1896 | 15 | fab bootstrap:download_cache_path=~/download-cache | ||
1897 | 16 | # Set up the correct Django configuration. | ||
1898 | 17 | cat <<EOF >django_project/local.cfg | ||
1899 | 18 | [__noschema__] | ||
1900 | 19 | db_host = /home/ubuntu/{pay.src_dir}/.env/db | ||
1901 | 20 | hostname = {pay.address}:{pay.port} | ||
1902 | 21 | |||
1903 | 22 | [__main__] | ||
1904 | 23 | includes = | ||
1905 | 24 | config/devel.cfg | ||
1906 | 25 | ../branches/project/config/acceptance.cfg | ||
1907 | 26 | |||
1908 | 27 | [django] | ||
1909 | 28 | debug = false | ||
1910 | 29 | internal_ips = | ||
1911 | 30 | |||
1912 | 31 | [testing] | ||
1913 | 32 | imap_server = {sso.address} | ||
1914 | 33 | imap_port = {sso.imap_port} | ||
1915 | 34 | imap_use_ssl = False | ||
1916 | 35 | |||
1917 | 36 | [openid] | ||
1918 | 37 | openid_sso_server_url = {sso.url} | ||
1919 | 38 | openid_trust_root = {pay.url} | ||
1920 | 39 | |||
1921 | 40 | EOF | ||
1922 | 0 | 41 | ||
1923 | === added file 'setup_vm/pay/run' | |||
1924 | --- setup_vm/pay/run 1970-01-01 00:00:00 +0000 | |||
1925 | +++ setup_vm/pay/run 2013-04-17 01:29:27 +0000 | |||
1926 | @@ -0,0 +1,9 @@ | |||
1927 | 1 | #!/bin/sh | ||
1928 | 2 | |||
1929 | 3 | cd {pay.src_dir} | ||
1930 | 4 | |||
1931 | 5 | # Setup the database. | ||
1932 | 6 | fab setup_postgresql_server | ||
1933 | 7 | fab manage:loaddata,test | ||
1934 | 8 | # Start the PAY server, accessible from the local network. | ||
1935 | 9 | fab run:0.0.0.0:{pay.port} | ||
1936 | 0 | 10 | ||
1937 | === added file 'setup_vm/pay/run-for-u1' | |||
1938 | --- setup_vm/pay/run-for-u1 1970-01-01 00:00:00 +0000 | |||
1939 | +++ setup_vm/pay/run-for-u1 2013-04-17 01:29:27 +0000 | |||
1940 | @@ -0,0 +1,57 @@ | |||
1941 | 1 | #!/bin/sh | ||
1942 | 2 | |||
1943 | 3 | cd {pay.src_dir} | ||
1944 | 4 | |||
1945 | 5 | # Setup the database. | ||
1946 | 6 | fab setup_postgresql_server | ||
1947 | 7 | # Add the U1 consumer. | ||
1948 | 8 | cat <<EOF >src/paymentservice/fixtures/consumer.json | ||
1949 | 9 | [ | ||
1950 | 10 | { | ||
1951 | 11 | "pk": "U1", | ||
1952 | 12 | "model": "paymentservice.consumer", | ||
1953 | 13 | "fields": { | ||
1954 | 14 | "notification_url": "{u1.url}/notifications/", | ||
1955 | 15 | "ip_address": "{u1.address}", | ||
1956 | 16 | "name": "Ubuntu One", | ||
1957 | 17 | "default_business_unit": "Online Services", | ||
1958 | 18 | "email_footer": "Test footer.", | ||
1959 | 19 | "theme": "ubuntuone" | ||
1960 | 20 | } | ||
1961 | 21 | } | ||
1962 | 22 | ] | ||
1963 | 23 | EOF | ||
1964 | 24 | fab manage:loaddata,consumer | ||
1965 | 25 | # Add the API user for U1. | ||
1966 | 26 | # We generated this json file with: | ||
1967 | 27 | # Go to {pay.url}/admin | ||
1968 | 28 | # Sign in with the admin/admin. | ||
1969 | 29 | # Click the more link next to the Model Admin heading. | ||
1970 | 30 | # On the Paymentservice section, click the +Add link next to API Users. | ||
1971 | 31 | # Fill the form with: | ||
1972 | 32 | # username: u1qauser | ||
1973 | 33 | # password: u1qapassword | ||
1974 | 34 | # Click the Save button. | ||
1975 | 35 | # Select the Ubuntu One (U1) Consumer. | ||
1976 | 36 | # Click the Save button. | ||
1977 | 37 | # $ fab manage:dumpdata,paymentservice.APIUser | ||
1978 | 38 | cat <<EOF >src/paymentservice/fixtures/apiuser.json | ||
1979 | 39 | [ | ||
1980 | 40 | { | ||
1981 | 41 | "pk": 2, | ||
1982 | 42 | "model": "paymentservice.apiuser", | ||
1983 | 43 | "fields": { | ||
1984 | 44 | "username": "u1qauser", | ||
1985 | 45 | "created_at": "2013-04-15 00:09:48", | ||
1986 | 46 | "password": "sha1\$b2a8e\$0e06d9cb46583aa53d3bf144ae07018a7546f737", | ||
1987 | 47 | "consumer": "U1", | ||
1988 | 48 | "updated_at": "2013-04-15 00:09:54" | ||
1989 | 49 | } | ||
1990 | 50 | } | ||
1991 | 51 | ] | ||
1992 | 52 | EOF | ||
1993 | 53 | fab manage:loaddata,apiuser | ||
1994 | 54 | # Start the PAY server, accessible from the local network. | ||
1995 | 55 | # We don't call the run task because it loads a fixture that overwrites our | ||
1996 | 56 | # consumer. | ||
1997 | 57 | fab manage:runserver,0.0.0.0:{pay.port} | ||
1998 | 0 | 58 | ||
1999 | === added file 'setup_vm/pay/test' | |||
2000 | --- setup_vm/pay/test 1970-01-01 00:00:00 +0000 | |||
2001 | +++ setup_vm/pay/test 2013-04-17 01:29:27 +0000 | |||
2002 | @@ -0,0 +1,5 @@ | |||
2003 | 1 | #!/bin/sh | ||
2004 | 2 | |||
2005 | 3 | cd {pay.src_dir} | ||
2006 | 4 | |||
2007 | 5 | SST_BASE_URL={pay.url} fab acceptance:screenshot=true,report=xml,extended=true | ||
2008 | 0 | 6 | ||
2009 | === added file 'setup_vm/selftest.py' | |||
2010 | --- setup_vm/selftest.py 1970-01-01 00:00:00 +0000 | |||
2011 | +++ setup_vm/selftest.py 2013-04-17 01:29:27 +0000 | |||
2012 | @@ -0,0 +1,24 @@ | |||
2013 | 1 | #!/usr/bin/env python | ||
2014 | 2 | |||
2015 | 3 | import sys | ||
2016 | 4 | |||
2017 | 5 | import testtools.run | ||
2018 | 6 | import unittest | ||
2019 | 7 | |||
2020 | 8 | |||
2021 | 9 | class TestProgram(testtools.run.TestProgram): | ||
2022 | 10 | |||
2023 | 11 | def __init__(self, module, argv, stdout=None, testRunner=None, exit=True): | ||
2024 | 12 | if testRunner is None: | ||
2025 | 13 | testRunner = unittest.TextTestRunner | ||
2026 | 14 | super(TestProgram, self).__init__(module, argv=argv, stdout=stdout, | ||
2027 | 15 | testRunner=testRunner, exit=exit) | ||
2028 | 16 | |||
2029 | 17 | |||
2030 | 18 | # We discover tests under './tests', the python 'load_test' protocol can be | ||
2031 | 19 | # used in test modules for more fancy stuff. | ||
2032 | 20 | discover_args = ['discover', | ||
2033 | 21 | '--start-directory', './tests', | ||
2034 | 22 | '--top-level-directory', '.', | ||
2035 | 23 | ] | ||
2036 | 24 | TestProgram(__name__, argv=[sys.argv[0]] + discover_args + sys.argv[1:]) | ||
2037 | 0 | 25 | ||
2038 | === added directory 'setup_vm/sso' | |||
2039 | === added file 'setup_vm/sso/install' | |||
2040 | --- setup_vm/sso/install 1970-01-01 00:00:00 +0000 | |||
2041 | +++ setup_vm/sso/install 2013-04-17 01:29:27 +0000 | |||
2042 | @@ -0,0 +1,45 @@ | |||
2043 | 1 | #!/bin/sh -ex | ||
2044 | 2 | |||
2045 | 3 | # Allow ssh access to launchpad. | ||
2046 | 4 | # This should probably be provided by setup_vm. -- vila 2013-03-10 | ||
2047 | 5 | ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts | ||
2048 | 6 | # Get the branch. | ||
2049 | 7 | bzr branch lp:canonical-identity-provider {sso.src_dir} | ||
2050 | 8 | # Get the download cache. | ||
2051 | 9 | bzr branch lp:~canonical-isd-hackers/+junk/download-cache | ||
2052 | 10 | # Setup the environment. | ||
2053 | 11 | cd {sso.src_dir} | ||
2054 | 12 | # Get the version controlled configs. | ||
2055 | 13 | bzr branch lp:~canonical-isd-hackers/isd-configs/sso-config branches/project | ||
2056 | 14 | # Bootstrap the dependencies | ||
2057 | 15 | fab bootstrap:download_cache_path=~/download-cache | ||
2058 | 16 | # Set up the correct Django configuration. | ||
2059 | 17 | # In order to set the db_host to a directory in .env, we need to use the full | ||
2060 | 18 | # path. Otherwise, fab setup_postgresql_server will fail. | ||
2061 | 19 | # TODO we can either configure the postgresql authentication and pass db_host | ||
2062 | 20 | # as empty, or use cat just to append to the end of the default local.cfg | ||
2063 | 21 | # that will contain the full path we need, or pass the user name in a config | ||
2064 | 22 | # variable. | ||
2065 | 23 | cat <<EOF >django_project/local.cfg | ||
2066 | 24 | [__noschema__] | ||
2067 | 25 | basedir = . | ||
2068 | 26 | db_host = /home/ubuntu/{sso.src_dir}/.env/db | ||
2069 | 27 | hostname = {sso.address}:{sso.port} | ||
2070 | 28 | |||
2071 | 29 | [__main__] | ||
2072 | 30 | includes = | ||
2073 | 31 | config/devel.cfg | ||
2074 | 32 | ../branches/project/config/acceptance-dev.cfg | ||
2075 | 33 | |||
2076 | 34 | [django] | ||
2077 | 35 | debug = false | ||
2078 | 36 | email_port = {sso.smtp_port} | ||
2079 | 37 | |||
2080 | 38 | [testing] | ||
2081 | 39 | imap_server = {sso.address} | ||
2082 | 40 | imap_port = {sso.imap_port} | ||
2083 | 41 | # needs to be a full email | ||
2084 | 42 | imap_username = whatever@we.dont.care | ||
2085 | 43 | imap_use_ssl = False | ||
2086 | 44 | |||
2087 | 45 | EOF | ||
2088 | 0 | 46 | ||
2089 | === added file 'setup_vm/sso/run' | |||
2090 | --- setup_vm/sso/run 1970-01-01 00:00:00 +0000 | |||
2091 | +++ setup_vm/sso/run 2013-04-17 01:29:27 +0000 | |||
2092 | @@ -0,0 +1,16 @@ | |||
2093 | 1 | #!/bin/sh | ||
2094 | 2 | |||
2095 | 3 | cd ~/{sso.src_dir} | ||
2096 | 4 | # We need an SMTP server to send emails. | ||
2097 | 5 | .env/bin/twistd localmail --imap {sso.imap_port} --smtp {sso.smtp_port} | ||
2098 | 6 | |||
2099 | 7 | # Setup the database. | ||
2100 | 8 | fab setup_postgresql_server | ||
2101 | 9 | fab manage:loaddata,test | ||
2102 | 10 | fab manage:create_test_team | ||
2103 | 11 | # get gargoyle flags from their use in the code | ||
2104 | 12 | SST_FLAGS=`grep -rho --exclude 'test_*.py' "is_active([\"']\(.*\)[\"']" identityprovider/ webui/ | sed -E "s/is_active\(['\"](.*)['\"]/\1/" | awk '{print tolower($0)}' | sort | uniq | tr '\n' ','` | ||
2105 | 13 | # We need to remove the trailing ',' | ||
2106 | 14 | fab gargoyle_flags:${SST_FLAGS%,} | ||
2107 | 15 | # Start the SSO server, accessible from the local network. | ||
2108 | 16 | fab run:0.0.0.0:{sso.port} | ||
2109 | 0 | 17 | ||
2110 | === added file 'setup_vm/sso/run-for-pay' | |||
2111 | --- setup_vm/sso/run-for-pay 1970-01-01 00:00:00 +0000 | |||
2112 | +++ setup_vm/sso/run-for-pay 2013-04-17 01:29:27 +0000 | |||
2113 | @@ -0,0 +1,14 @@ | |||
2114 | 1 | #!/bin/sh | ||
2115 | 2 | |||
2116 | 3 | cd ~/{sso.src_dir} | ||
2117 | 4 | # We need an SMTP server to send emails. | ||
2118 | 5 | .env/bin/twistd localmail --imap {sso.imap_port} --smtp {sso.smtp_port} | ||
2119 | 6 | |||
2120 | 7 | # Setup the database. | ||
2121 | 8 | fab setup_postgresql_server | ||
2122 | 9 | fab manage:loaddata,isdtest | ||
2123 | 10 | fab manage:loaddata,allow_unverified | ||
2124 | 11 | # Set the allow-unverified config for Pay. | ||
2125 | 12 | fab manage:add_openid_rp_config,{pay.url},--allow-unverified,--allowed-sreg="fullname\,nickname\,email\,language" | ||
2126 | 13 | # Start the SSO server, accessible from the local network. | ||
2127 | 14 | fab run:0.0.0.0:{sso.port} | ||
2128 | 0 | 15 | ||
2129 | === added file 'setup_vm/sso/run-for-u1' | |||
2130 | --- setup_vm/sso/run-for-u1 1970-01-01 00:00:00 +0000 | |||
2131 | +++ setup_vm/sso/run-for-u1 2013-04-17 01:29:27 +0000 | |||
2132 | @@ -0,0 +1,43 @@ | |||
2133 | 1 | #!/bin/sh | ||
2134 | 2 | |||
2135 | 3 | cd ~/{sso.src_dir} | ||
2136 | 4 | # We need an SMTP server to send emails. | ||
2137 | 5 | .env/bin/twistd localmail --imap {sso.imap_port} --smtp {sso.smtp_port} | ||
2138 | 6 | |||
2139 | 7 | # Setup the database. | ||
2140 | 8 | fab setup_postgresql_server | ||
2141 | 9 | fab manage:loaddata,allow_unverified | ||
2142 | 10 | # Set the allow-unverified config for Pay. | ||
2143 | 11 | fab manage:add_openid_rp_config,{pay.url},--allow-unverified,--allowed-sreg="fullname\,nickname\,email\,language" | ||
2144 | 12 | # Set the allow-unverified config for U1. | ||
2145 | 13 | fab manage:add_openid_rp_config,{u1.url},--allow-unverified,--allowed-sreg="fullname\,nickname\,email\,language" | ||
2146 | 14 | # Add the API user for U1. | ||
2147 | 15 | # We generated this json file with: | ||
2148 | 16 | # $ fab manage:createsuperuser | ||
2149 | 17 | # Go to {sso.url}/admin | ||
2150 | 18 | # Sign in with the super user you have just created. | ||
2151 | 19 | # Click the more link next to the Model Admin heading. | ||
2152 | 20 | # On the Identityprovider section, click the +Add link next to API Users. | ||
2153 | 21 | # Fill the form with: | ||
2154 | 22 | # username: u1qauser | ||
2155 | 23 | # password: u1qapassword | ||
2156 | 24 | # Click the Save button. | ||
2157 | 25 | # $ fab manage:dumpdata,identityprovider.APIUser | ||
2158 | 26 | cat <<EOF >identityprovider/fixtures/apiuser.json | ||
2159 | 27 | [ | ||
2160 | 28 | { | ||
2161 | 29 | "pk": 1, | ||
2162 | 30 | "model": "identityprovider.apiuser", | ||
2163 | 31 | "fields": { | ||
2164 | 32 | "username": "u1qauser", | ||
2165 | 33 | "created_at": "2013-04-14 21:09:43", | ||
2166 | 34 | "password": "k1B7nUTaEsrqAPHF/bWsLlNIPUsH7mViraFQBZPgNRRuvsZlRq8CZg==", | ||
2167 | 35 | "updated_at": "2013-04-14 21:09:43" | ||
2168 | 36 | } | ||
2169 | 37 | } | ||
2170 | 38 | ] | ||
2171 | 39 | |||
2172 | 40 | EOF | ||
2173 | 41 | fab manage:loaddata,apiuser | ||
2174 | 42 | # Start the SSO server, accessible from the local network. | ||
2175 | 43 | fab run:0.0.0.0:{sso.port} | ||
2176 | 0 | 44 | ||
2177 | === added file 'setup_vm/sso/test' | |||
2178 | --- setup_vm/sso/test 1970-01-01 00:00:00 +0000 | |||
2179 | +++ setup_vm/sso/test 2013-04-17 01:29:27 +0000 | |||
2180 | @@ -0,0 +1,11 @@ | |||
2181 | 1 | #!/bin/sh | ||
2182 | 2 | |||
2183 | 3 | # FIXME: This should run on the host and get config options expanded | ||
2184 | 4 | # -- vila 2013-03-12 | ||
2185 | 5 | |||
2186 | 6 | cd {sso.src_dir} | ||
2187 | 7 | |||
2188 | 8 | # get gargoyle flags from their use in the code | ||
2189 | 9 | SST_FLAGS=`grep -rho --exclude 'test_*.py' "is_active([\"']\(.*\)[\"']" identityprovider/ webui/ | sed -E "s/is_active\(['\"](.*)['\"]/\1/" | awk '{print tolower($0)}' | sort | uniq | tr '\n' ';'` | ||
2190 | 10 | # run tests | ||
2191 | 11 | SST_BASE_URL={sso.url} fab acceptance:screenshot=true,report=xml,extended=true,flags=$SST_FLAGS | ||
2192 | 0 | 12 | ||
2193 | === added directory 'setup_vm/tests' | |||
2194 | === added file 'setup_vm/tests/__init__.py' | |||
2195 | --- setup_vm/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
2196 | +++ setup_vm/tests/__init__.py 2013-04-17 01:29:27 +0000 | |||
2197 | @@ -0,0 +1,75 @@ | |||
2198 | 1 | import os | ||
2199 | 2 | import shutil | ||
2200 | 3 | import tempfile | ||
2201 | 4 | |||
2202 | 5 | from bzrlib import osutils | ||
2203 | 6 | |||
2204 | 7 | def override_env_var(name, value): | ||
2205 | 8 | """Modify the environment, setting or removing the env_variable. | ||
2206 | 9 | |||
2207 | 10 | :param name: The environment variable to set. | ||
2208 | 11 | |||
2209 | 12 | :param value: The value to set the environment to. If None, then | ||
2210 | 13 | the variable will be removed. | ||
2211 | 14 | |||
2212 | 15 | :return: The original value of the environment variable. | ||
2213 | 16 | """ | ||
2214 | 17 | orig = os.environ.get(name) | ||
2215 | 18 | if value is None: | ||
2216 | 19 | if orig is not None: | ||
2217 | 20 | del os.environ[name] | ||
2218 | 21 | else: | ||
2219 | 22 | # FIXME: supporting unicode values requires a way to acquire the | ||
2220 | 23 | # user encoding, punting for now -- vila 2013-01-30 | ||
2221 | 24 | os.environ[name] = value | ||
2222 | 25 | return orig | ||
2223 | 26 | |||
2224 | 27 | |||
2225 | 28 | def override_env(test, name, new): | ||
2226 | 29 | """Set an environment variable, and reset it after the test. | ||
2227 | 30 | |||
2228 | 31 | :param name: The environment variable name. | ||
2229 | 32 | |||
2230 | 33 | :param new: The value to set the variable to. If None, the | ||
2231 | 34 | variable is deleted from the environment. | ||
2232 | 35 | |||
2233 | 36 | :returns: The actual variable value. | ||
2234 | 37 | """ | ||
2235 | 38 | value = override_env_var(name, new) | ||
2236 | 39 | test.addCleanup(override_env_var, name, value) | ||
2237 | 40 | return value | ||
2238 | 41 | |||
2239 | 42 | |||
2240 | 43 | isolated_environ = { | ||
2241 | 44 | 'HOME': None, | ||
2242 | 45 | } | ||
2243 | 46 | |||
2244 | 47 | |||
2245 | 48 | def isolate_env(test, env=None): | ||
2246 | 49 | """Isolate test from the environment variables. | ||
2247 | 50 | |||
2248 | 51 | This is usually called in setUp for tests that needs to modify the | ||
2249 | 52 | environment variables and restore them after the test is run. | ||
2250 | 53 | |||
2251 | 54 | :param test: A test instance | ||
2252 | 55 | |||
2253 | 56 | :param env: A dict containing variable definitions to be installed. Only | ||
2254 | 57 | the variables present there are protected. They are initialized with | ||
2255 | 58 | the provided values. | ||
2256 | 59 | """ | ||
2257 | 60 | if env is None: | ||
2258 | 61 | env = isolated_environ | ||
2259 | 62 | for name, value in env.items(): | ||
2260 | 63 | override_env(test, name, value) | ||
2261 | 64 | |||
2262 | 65 | |||
2263 | 66 | def set_cwd_to_tmp(test): | ||
2264 | 67 | """Create a temp dir an cd into it for the test duration. | ||
2265 | 68 | |||
2266 | 69 | This is generally called during a test setup. | ||
2267 | 70 | """ | ||
2268 | 71 | test.test_base_dir = tempfile.mkdtemp(prefix='mytests-', suffix='.tmp') | ||
2269 | 72 | test.addCleanup(shutil.rmtree, test.test_base_dir, True) | ||
2270 | 73 | current_dir = os.getcwdu() | ||
2271 | 74 | test.addCleanup(os.chdir, current_dir) | ||
2272 | 75 | os.chdir(test.test_base_dir) | ||
2273 | 0 | 76 | ||
2274 | === added file 'setup_vm/tests/test_setup_vm.py' | |||
2275 | --- setup_vm/tests/test_setup_vm.py 1970-01-01 00:00:00 +0000 | |||
2276 | +++ setup_vm/tests/test_setup_vm.py 2013-04-17 01:29:27 +0000 | |||
2277 | @@ -0,0 +1,1074 @@ | |||
2278 | 1 | from cStringIO import StringIO | ||
2279 | 2 | import os | ||
2280 | 3 | |||
2281 | 4 | from bzrlib import errors | ||
2282 | 5 | import testtools | ||
2283 | 6 | |||
2284 | 7 | import tests | ||
2285 | 8 | from bin import setup_vm | ||
2286 | 9 | |||
2287 | 10 | |||
2288 | 11 | def requires_known_reference_image(test): | ||
2289 | 12 | # We need a pre-seeded download cache from the user running the tests | ||
2290 | 13 | # as downloading the cloud image is too long. | ||
2291 | 14 | user_conf = setup_vm.VmStack(None) | ||
2292 | 15 | download_cache = user_conf.get('vm.download_cache') | ||
2293 | 16 | if download_cache is None: | ||
2294 | 17 | test.skip('vm.download_cache is not set') | ||
2295 | 18 | # We use some known reference | ||
2296 | 19 | reference_cloud_image_name = 'raring-server-cloudimg-amd64-disk1.img' | ||
2297 | 20 | cloud_image_path = os.path.join( | ||
2298 | 21 | download_cache, reference_cloud_image_name) | ||
2299 | 22 | if not os.path.exists(cloud_image_path): | ||
2300 | 23 | test.skip('%s is not available' % (cloud_image_path,)) | ||
2301 | 24 | return download_cache, reference_cloud_image_name | ||
2302 | 25 | |||
2303 | 26 | |||
2304 | 27 | class TestCaseWithHome(testtools.TestCase): | ||
2305 | 28 | """Provide an isolated disk-based environment. | ||
2306 | 29 | |||
2307 | 30 | A $HOME directory is setup as well as an /etc/ one so tests can setup | ||
2308 | 31 | config files. | ||
2309 | 32 | """ | ||
2310 | 33 | |||
2311 | 34 | def setUp(self): | ||
2312 | 35 | super(TestCaseWithHome, self).setUp() | ||
2313 | 36 | tests.set_cwd_to_tmp(self) | ||
2314 | 37 | tests.isolate_env(self) | ||
2315 | 38 | # Isolate tests from the user environment | ||
2316 | 39 | self.home_dir = os.path.join(self.test_base_dir, 'home') | ||
2317 | 40 | os.mkdir(self.home_dir) | ||
2318 | 41 | os.environ['HOME'] = self.home_dir | ||
2319 | 42 | # Also isolate from the system environment | ||
2320 | 43 | self.etc_dir = os.path.join(self.test_base_dir, 'etc') | ||
2321 | 44 | os.mkdir(self.etc_dir) | ||
2322 | 45 | self.patch(setup_vm, 'system_config_dir', lambda: self.etc_dir) | ||
2323 | 46 | |||
2324 | 47 | |||
2325 | 48 | class TestVmMatcher(TestCaseWithHome): | ||
2326 | 49 | |||
2327 | 50 | def setUp(self): | ||
2328 | 51 | super(TestVmMatcher, self).setUp() | ||
2329 | 52 | self.store = setup_vm.VmStore('.', 'foo.conf') | ||
2330 | 53 | self.matcher = setup_vm.VmMatcher(self.store, 'test') | ||
2331 | 54 | |||
2332 | 55 | def test_empty_section_always_matches(self): | ||
2333 | 56 | self.store._load_from_string('foo=bar') | ||
2334 | 57 | matching = list(self.matcher.get_sections()) | ||
2335 | 58 | self.assertEqual(1, len(matching)) | ||
2336 | 59 | |||
2337 | 60 | def test_specific_before_generic(self): | ||
2338 | 61 | self.store._load_from_string('foo=bar\n[test]\nfoo=baz') | ||
2339 | 62 | matching = list(self.matcher.get_sections()) | ||
2340 | 63 | self.assertEqual(2, len(matching)) | ||
2341 | 64 | # First matching section is for test | ||
2342 | 65 | self.assertEqual(self.store, matching[0][0]) | ||
2343 | 66 | base_section = matching[0][1] | ||
2344 | 67 | self.assertEqual('test', base_section.id) | ||
2345 | 68 | # Second matching section is the no-name one | ||
2346 | 69 | self.assertEqual(self.store, matching[0][0]) | ||
2347 | 70 | no_name_section = matching[1][1] | ||
2348 | 71 | self.assertIs(None, no_name_section.id) | ||
2349 | 72 | |||
2350 | 73 | |||
2351 | 74 | class TestVmStores(TestCaseWithHome): | ||
2352 | 75 | |||
2353 | 76 | def setUp(self): | ||
2354 | 77 | super(TestVmStores, self).setUp() | ||
2355 | 78 | self.conf = setup_vm.VmStack('foo') | ||
2356 | 79 | |||
2357 | 80 | |||
2358 | 81 | def test_default_in_empty_stack(self): | ||
2359 | 82 | self.assertEqual('1024', self.conf.get('vm.ram_size')) | ||
2360 | 83 | |||
2361 | 84 | |||
2362 | 85 | def test_system_overrides_internal(self): | ||
2363 | 86 | self.conf.system_store._load_from_string('vm.ram_size = 42') | ||
2364 | 87 | self.assertEqual('42', self.conf.get('vm.ram_size')) | ||
2365 | 88 | |||
2366 | 89 | def test_user_overrides_system(self): | ||
2367 | 90 | self.conf.system_store._load_from_string('vm.ram_size = 42') | ||
2368 | 91 | self.conf.store._load_from_string('vm.ram_size = 4201') | ||
2369 | 92 | self.assertEqual('4201', self.conf.get('vm.ram_size')) | ||
2370 | 93 | |||
2371 | 94 | def test_local_overrides_user(self): | ||
2372 | 95 | self.conf.system_store._load_from_string('vm.ram_size = 42') | ||
2373 | 96 | self.conf.store._load_from_string('vm.ram_size = 4201') | ||
2374 | 97 | self.conf.local_store._load_from_string('vm.ram_size = 8402') | ||
2375 | 98 | self.assertEqual('8402', self.conf.get('vm.ram_size')) | ||
2376 | 99 | |||
2377 | 100 | |||
2378 | 101 | class TestVmStack(TestCaseWithHome): | ||
2379 | 102 | |||
2380 | 103 | def setUp(self): | ||
2381 | 104 | super(TestVmStack, self).setUp() | ||
2382 | 105 | self.conf = setup_vm.VmStack('foo') | ||
2383 | 106 | self.conf.store._load_from_string(''' | ||
2384 | 107 | vm.release=raring | ||
2385 | 108 | vm.cpu_model=amd64 | ||
2386 | 109 | ''') | ||
2387 | 110 | |||
2388 | 111 | def assertValue(self, expected_value, option): | ||
2389 | 112 | self.assertEqual(expected_value, self.conf.get(option)) | ||
2390 | 113 | |||
2391 | 114 | def test_raring_iso_url(self): | ||
2392 | 115 | self.assertValue('http://cdimage.ubuntu.com/daily-live/current/', | ||
2393 | 116 | 'vm.iso_url' ) | ||
2394 | 117 | |||
2395 | 118 | def test_raring_iso_name(self): | ||
2396 | 119 | self.assertValue( 'raring-desktop-amd64.iso', 'vm.iso_name') | ||
2397 | 120 | |||
2398 | 121 | def test_raring_cloud_image_url(self): | ||
2399 | 122 | self.assertValue('http://cloud-images.ubuntu.com/raring/current/', | ||
2400 | 123 | 'vm.cloud_image_url') | ||
2401 | 124 | |||
2402 | 125 | def test_raring_cloud_image_name(self): | ||
2403 | 126 | self.assertValue('raring-server-cloudimg-amd64-disk1.img', | ||
2404 | 127 | 'vm.cloud_image_name') | ||
2405 | 128 | |||
2406 | 129 | def test_apt_proxy_set(self): | ||
2407 | 130 | proxy = 'apt_proxy: http://example.org:4321' | ||
2408 | 131 | self.conf.set('vm.apt_proxy', proxy) | ||
2409 | 132 | self.assertEqual(proxy, self.conf.expand_options('{vm.apt_proxy}')) | ||
2410 | 133 | |||
2411 | 134 | def test_download_cache_with_user_expansion(self): | ||
2412 | 135 | download_cache = '~/installers' | ||
2413 | 136 | self.conf.set('vm.download_cache', download_cache) | ||
2414 | 137 | self.assertValue(os.path.join(self.home_dir, 'installers'), | ||
2415 | 138 | 'vm.download_cache') | ||
2416 | 139 | |||
2417 | 140 | def test_images_dir_with_user_expansion(self): | ||
2418 | 141 | images_dir = '~/images' | ||
2419 | 142 | self.conf.set('vm.images_dir', images_dir) | ||
2420 | 143 | self.assertValue(os.path.join(self.home_dir, 'images'), | ||
2421 | 144 | 'vm.images_dir') | ||
2422 | 145 | |||
2423 | 146 | |||
2424 | 147 | class TestPathOption(TestCaseWithHome): | ||
2425 | 148 | |||
2426 | 149 | def assertConverted(self, expected, value): | ||
2427 | 150 | option = setup_vm.PathOption('foo', help='A path.') | ||
2428 | 151 | self.assertEquals(expected, option.convert_from_unicode(None, value)) | ||
2429 | 152 | |||
2430 | 153 | def test_absolute_path(self): | ||
2431 | 154 | self.assertConverted('/test/path', '/test/path') | ||
2432 | 155 | |||
2433 | 156 | def test_home_path_with_expansion(self): | ||
2434 | 157 | self.assertConverted(self.home_dir, '~') | ||
2435 | 158 | |||
2436 | 159 | def test_path_in_home_with_expansion(self): | ||
2437 | 160 | self.assertConverted(os.path.join(self.home_dir, 'test/path'), | ||
2438 | 161 | '~/test/path') | ||
2439 | 162 | |||
2440 | 163 | |||
2441 | 164 | class TestDownload(TestCaseWithHome): | ||
2442 | 165 | |||
2443 | 166 | # FIXME: Needs parametrization against vm.{cloud_image_name|iso_name} and | ||
2444 | 167 | # {download_iso|download_cloud_image} -- vila 2013-02-07 | ||
2445 | 168 | |||
2446 | 169 | def setUp(self): | ||
2447 | 170 | # Downloading real isos or images is too long for tests, instead, we | ||
2448 | 171 | # fake it by downloading a small but known to exist file: MD5SUMS | ||
2449 | 172 | super(TestDownload, self).setUp() | ||
2450 | 173 | download_cache = os.path.join(self.test_base_dir, 'downloads') | ||
2451 | 174 | os.mkdir(download_cache) | ||
2452 | 175 | self.conf = setup_vm.VmStack('foo') | ||
2453 | 176 | self.conf.store._load_from_string(''' | ||
2454 | 177 | vm.iso_name=MD5SUMS | ||
2455 | 178 | vm.cloud_image_name=MD5SUMS | ||
2456 | 179 | vm.release=raring | ||
2457 | 180 | vm.cpu_model=amd64 | ||
2458 | 181 | vm.download_cache=%s | ||
2459 | 182 | ''' % (download_cache,)) | ||
2460 | 183 | |||
2461 | 184 | def test_download_iso(self): | ||
2462 | 185 | vm = setup_vm.Kvm(self.conf) | ||
2463 | 186 | self.assertTrue(vm.download_iso()) | ||
2464 | 187 | # Trying to download again will find the file in the cache | ||
2465 | 188 | self.assertFalse(vm.download_iso()) | ||
2466 | 189 | # Forcing the download even when the file is present | ||
2467 | 190 | self.assertTrue(vm.download_iso(force=True)) | ||
2468 | 191 | |||
2469 | 192 | def test_download_cloud_image(self): | ||
2470 | 193 | vm = setup_vm.Kvm(self.conf) | ||
2471 | 194 | self.assertTrue(vm.download_cloud_image()) | ||
2472 | 195 | # Trying to download again will find the file in the cache | ||
2473 | 196 | self.assertFalse(vm.download_cloud_image()) | ||
2474 | 197 | # Forcing the download even when the file is present | ||
2475 | 198 | self.assertTrue(vm.download_cloud_image(force=True)) | ||
2476 | 199 | |||
2477 | 200 | def test_download_unknown_iso_fail(self): | ||
2478 | 201 | self.conf.set('vm.iso_name', 'I-dont-exist') | ||
2479 | 202 | vm = setup_vm.Kvm(self.conf) | ||
2480 | 203 | self.assertRaises(setup_vm.CommandError, vm.download_iso) | ||
2481 | 204 | |||
2482 | 205 | def test_download_unknown_cloud_image_fail(self): | ||
2483 | 206 | self.conf.set('vm.cloud_image_name', 'I-dont-exist') | ||
2484 | 207 | vm = setup_vm.Kvm(self.conf) | ||
2485 | 208 | self.assertRaises(setup_vm.CommandError, vm.download_cloud_image) | ||
2486 | 209 | |||
2487 | 210 | def test_download_iso_with_unknown_cache_fail(self): | ||
2488 | 211 | dl_cache = os.path.join(self.test_base_dir, 'I-dont-exist') | ||
2489 | 212 | self.conf.set('vm.download_cache', dl_cache) | ||
2490 | 213 | vm = setup_vm.Kvm(self.conf) | ||
2491 | 214 | self.assertRaises(setup_vm.ConfigValueError, vm.download_iso) | ||
2492 | 215 | |||
2493 | 216 | def test_download_cloud_image_with_unknown_cache_fail(self): | ||
2494 | 217 | dl_cache = os.path.join(self.test_base_dir, 'I-dont-exist') | ||
2495 | 218 | self.conf.set('vm.download_cache', dl_cache) | ||
2496 | 219 | vm = setup_vm.Kvm(self.conf) | ||
2497 | 220 | self.assertRaises(setup_vm.ConfigValueError, vm.download_cloud_image) | ||
2498 | 221 | |||
2499 | 222 | |||
2500 | 223 | class TestMetaData(TestCaseWithHome): | ||
2501 | 224 | |||
2502 | 225 | def setUp(self): | ||
2503 | 226 | super(TestMetaData, self).setUp() | ||
2504 | 227 | self.conf = setup_vm.VmStack('foo') | ||
2505 | 228 | self.vm = setup_vm.Kvm(self.conf) | ||
2506 | 229 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
2507 | 230 | os.mkdir(images_dir) | ||
2508 | 231 | config_dir = os.path.join(self.test_base_dir, 'config') | ||
2509 | 232 | self.conf.store._load_from_string(''' | ||
2510 | 233 | vm.name=foo | ||
2511 | 234 | vm.images_dir=%s | ||
2512 | 235 | vm.config_dir=%s | ||
2513 | 236 | ''' % (images_dir, config_dir,)) | ||
2514 | 237 | |||
2515 | 238 | def test_create_meta_data(self): | ||
2516 | 239 | self.vm.create_meta_data() | ||
2517 | 240 | self.assertTrue(os.path.exists(self.vm._config_dir)) | ||
2518 | 241 | self.assertTrue(os.path.exists(self.vm._meta_data_path)) | ||
2519 | 242 | with open(self.vm._meta_data_path) as f: | ||
2520 | 243 | meta_data = f.readlines() | ||
2521 | 244 | self.assertEqual(2, len(meta_data)) | ||
2522 | 245 | self.assertEqual('instance-id: foo\n', meta_data[0]) | ||
2523 | 246 | self.assertEqual('local-hostname: foo\n', meta_data[1]) | ||
2524 | 247 | |||
2525 | 248 | |||
2526 | 249 | class TestYaml(testtools.TestCase): | ||
2527 | 250 | |||
2528 | 251 | def yaml_load(self, *args, **kwargs): | ||
2529 | 252 | return setup_vm.yaml.safe_load(*args, **kwargs) | ||
2530 | 253 | |||
2531 | 254 | def yaml_dump(self, *args, **kwargs): | ||
2532 | 255 | return setup_vm.yaml.safe_dump(*args, **kwargs) | ||
2533 | 256 | |||
2534 | 257 | def test_load_scalar(self): | ||
2535 | 258 | self.assertEqual({'foo': 'bar'}, self.yaml_load(StringIO('{foo: bar}'))) | ||
2536 | 259 | # Surprisingly the enclosing braces are not needed, probably a special | ||
2537 | 260 | # case for the highest level | ||
2538 | 261 | self.assertEqual({'foo': 'bar'}, self.yaml_load(StringIO('foo: bar'))) | ||
2539 | 262 | |||
2540 | 263 | def test_dump_scalar(self): | ||
2541 | 264 | self.assertEqual('{foo: bar}\n', self.yaml_dump(dict(foo='bar'))) | ||
2542 | 265 | |||
2543 | 266 | def test_load_list(self): | ||
2544 | 267 | self.assertEqual({'foo': ['a', 'b', 'c']}, | ||
2545 | 268 | # Single space indentation is enough | ||
2546 | 269 | self.yaml_load(StringIO('''\ | ||
2547 | 270 | foo: | ||
2548 | 271 | - a | ||
2549 | 272 | - b | ||
2550 | 273 | - c | ||
2551 | 274 | '''))) | ||
2552 | 275 | |||
2553 | 276 | def test_dump_list(self): | ||
2554 | 277 | # No more enclosing braces... yeah for consistency :-/ | ||
2555 | 278 | self.assertEqual('foo: [a, b, c]\n', | ||
2556 | 279 | self.yaml_dump(dict(foo=['a', 'b', 'c']))) | ||
2557 | 280 | |||
2558 | 281 | def test_load_dict(self): | ||
2559 | 282 | self.assertEqual({'foo': {'bar': 'baz'}}, | ||
2560 | 283 | self.yaml_load(StringIO('{foo: {bar: baz}}'))) | ||
2561 | 284 | multiple_lines = '''\ | ||
2562 | 285 | foo: {bar: multiple | ||
2563 | 286 | lines} | ||
2564 | 287 | ''' | ||
2565 | 288 | self.assertEqual({'foo': {'bar': 'multiple lines'}}, | ||
2566 | 289 | self.yaml_load(StringIO(multiple_lines))) | ||
2567 | 290 | |||
2568 | 291 | |||
2569 | 292 | |||
2570 | 293 | class TestLaunchpadAccess(TestCaseWithHome): | ||
2571 | 294 | |||
2572 | 295 | def setUp(self): | ||
2573 | 296 | super(TestLaunchpadAccess, self).setUp() | ||
2574 | 297 | self.conf = setup_vm.VmStack('foo') | ||
2575 | 298 | self.vm = setup_vm.Kvm(self.conf) | ||
2576 | 299 | self.ci_data = setup_vm.CIUserData(self.conf) | ||
2577 | 300 | |||
2578 | 301 | def test_cant_find_private_key(self): | ||
2579 | 302 | self.conf.store._load_from_string('vm.launchpad_id = I-dont-exist') | ||
2580 | 303 | e = self.assertRaises(setup_vm.ConfigPathNotFound, | ||
2581 | 304 | self.ci_data.set_launchpad_access) | ||
2582 | 305 | key_path = '~/.ssh/I-dont-exist@setup_vm' | ||
2583 | 306 | self.assertEqual(key_path, e.path) | ||
2584 | 307 | self.assertTrue(unicode(e).startswith( | ||
2585 | 308 | 'You need to create the {p} keypair'.format(p=key_path))) | ||
2586 | 309 | |||
2587 | 310 | def test_id_with_key(self): | ||
2588 | 311 | ssh_dir = os.path.join(self.home_dir, '.ssh') | ||
2589 | 312 | os.mkdir(ssh_dir) | ||
2590 | 313 | key_path = os.path.join(ssh_dir, 'user@setup_vm') | ||
2591 | 314 | with open(key_path, 'w') as f: | ||
2592 | 315 | f.write('key content') | ||
2593 | 316 | self.conf.store._load_from_string('vm.launchpad_id = user') | ||
2594 | 317 | self.assertEqual(None, self.ci_data.launchpad_hook) | ||
2595 | 318 | self.ci_data.set_launchpad_access() | ||
2596 | 319 | self.assertEqual('''\ | ||
2597 | 320 | #!/bin/sh | ||
2598 | 321 | mkdir -p /home/ubuntu/.ssh | ||
2599 | 322 | chown ubuntu:ubuntu ~ubuntu | ||
2600 | 323 | chmod 0700 ~ubuntu | ||
2601 | 324 | chown ubuntu:ubuntu /home/ubuntu/.ssh | ||
2602 | 325 | chmod 0700 /home/ubuntu/.ssh | ||
2603 | 326 | cat >/home/ubuntu/.ssh/id_rsa <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
2604 | 327 | key content | ||
2605 | 328 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
2606 | 329 | chown ubuntu:ubuntu /home/ubuntu/.ssh/id_rsa | ||
2607 | 330 | chmod 0400 /home/ubuntu/.ssh/id_rsa | ||
2608 | 331 | ''', | ||
2609 | 332 | self.ci_data.launchpad_hook) | ||
2610 | 333 | cc = self.ci_data.cloud_config | ||
2611 | 334 | self.assertEquals([['sudo', '-u', 'ubuntu', | ||
2612 | 335 | 'bzr', 'launchpad-login', 'user']], | ||
2613 | 336 | cc['runcmd']) | ||
2614 | 337 | |||
2615 | 338 | |||
2616 | 339 | class TestCIUserData(TestCaseWithHome): | ||
2617 | 340 | |||
2618 | 341 | def setUp(self): | ||
2619 | 342 | super(TestCIUserData, self).setUp() | ||
2620 | 343 | self.conf = setup_vm.VmStack('foo') | ||
2621 | 344 | self.ci_data = setup_vm.CIUserData(self.conf) | ||
2622 | 345 | |||
2623 | 346 | def test_empty_config(self): | ||
2624 | 347 | self.ci_data.populate() | ||
2625 | 348 | # Check default values | ||
2626 | 349 | self.assertIs(None, self.ci_data.root_hook) | ||
2627 | 350 | self.assertIs(None, self.ci_data.ubuntu_hook) | ||
2628 | 351 | cc = self.ci_data.cloud_config | ||
2629 | 352 | self.assertFalse(cc['apt_update']) | ||
2630 | 353 | self.assertFalse(cc['apt_upgrade']) | ||
2631 | 354 | self.assertEqual({'expire': False}, cc['chpasswd']) | ||
2632 | 355 | self.assertEqual('setup_vm finished installing in ${uptime} seconds.', | ||
2633 | 356 | cc['final_message']) | ||
2634 | 357 | self.assertTrue(cc['manage_etc_hosts']) | ||
2635 | 358 | self.assertEqual('ubuntu', cc['password']) | ||
2636 | 359 | self.assertEqual({'mode': 'poweroff'}, cc['power_state']) | ||
2637 | 360 | |||
2638 | 361 | def test_password(self): | ||
2639 | 362 | self.conf.store._load_from_string('vm.password = tagada') | ||
2640 | 363 | self.ci_data.populate() | ||
2641 | 364 | self.assertEquals('tagada', self.ci_data.cloud_config['password']) | ||
2642 | 365 | |||
2643 | 366 | def test_apt_proxy(self): | ||
2644 | 367 | self.conf.store._load_from_string('vm.apt_proxy = tagada') | ||
2645 | 368 | self.ci_data.populate() | ||
2646 | 369 | self.assertEquals('tagada', self.ci_data.cloud_config['apt_proxy']) | ||
2647 | 370 | |||
2648 | 371 | def test_final_message_precise(self): | ||
2649 | 372 | self.conf.store._load_from_string('vm.release = precise') | ||
2650 | 373 | self.ci_data.populate() | ||
2651 | 374 | self.assertEqual('setup_vm finished installing in $UPTIME seconds.', | ||
2652 | 375 | self.ci_data.cloud_config['final_message']) | ||
2653 | 376 | |||
2654 | 377 | def test_poweroff_precise(self): | ||
2655 | 378 | self.conf.store._load_from_string('vm.release = precise') | ||
2656 | 379 | self.ci_data.populate() | ||
2657 | 380 | self.assertEqual(['halt'], self.ci_data.cloud_config['runcmd']) | ||
2658 | 381 | |||
2659 | 382 | def test_poweroff_quantal(self): | ||
2660 | 383 | self.conf.store._load_from_string('vm.release = quantal') | ||
2661 | 384 | self.ci_data.populate() | ||
2662 | 385 | self.assertEqual(['halt'], self.ci_data.cloud_config['runcmd']) | ||
2663 | 386 | |||
2664 | 387 | def test_poweroff_other(self): | ||
2665 | 388 | self.conf.store._load_from_string('vm.release = raring') | ||
2666 | 389 | self.ci_data.populate() | ||
2667 | 390 | self.assertEqual({'mode': 'poweroff'}, | ||
2668 | 391 | self.ci_data.cloud_config['power_state']) | ||
2669 | 392 | self.assertIs(None, self.ci_data.cloud_config.get('runcmd')) | ||
2670 | 393 | |||
2671 | 394 | def test_update_true(self): | ||
2672 | 395 | self.conf.store._load_from_string('vm.update = True') | ||
2673 | 396 | self.ci_data.populate() | ||
2674 | 397 | cc = self.ci_data.cloud_config | ||
2675 | 398 | self.assertTrue(cc['apt_update']) | ||
2676 | 399 | self.assertTrue(cc['apt_upgrade']) | ||
2677 | 400 | |||
2678 | 401 | def test_packages(self): | ||
2679 | 402 | self.conf.store._load_from_string('vm.packages = bzr,ubuntu-desktop') | ||
2680 | 403 | self.ci_data.populate() | ||
2681 | 404 | self.assertEqual(['bzr', 'ubuntu-desktop'], | ||
2682 | 405 | self.ci_data.cloud_config['packages']) | ||
2683 | 406 | |||
2684 | 407 | def test_apt_sources(self): | ||
2685 | 408 | self.conf.store._load_from_string('''\ | ||
2686 | 409 | vm.release = raring | ||
2687 | 410 | # Ensure options are properly expanded (and comments supported ;) | ||
2688 | 411 | _archive_url = http://archive.ubuntu.com/ubuntu | ||
2689 | 412 | _ppa_url = https://u:p@ppa.lp.net/user/ppa/ubuntu | ||
2690 | 413 | vm.apt_sources = deb {_archive_url} {vm.release} partner,\ | ||
2691 | 414 | deb {_archive_url} {vm.release} main,\ | ||
2692 | 415 | deb {_ppa_url} {vm.release} main|ABCDEF | ||
2693 | 416 | ''') | ||
2694 | 417 | self.ci_data.populate() | ||
2695 | 418 | self.assertEqual( | ||
2696 | 419 | [{'source': 'deb http://archive.ubuntu.com/ubuntu raring partner'}, | ||
2697 | 420 | {'source': 'deb http://archive.ubuntu.com/ubuntu raring main'}, | ||
2698 | 421 | {'source': | ||
2699 | 422 | 'deb https://u:p@ppa.lp.net/user/ppa/ubuntu raring main', | ||
2700 | 423 | 'keyid': 'ABCDEF'}], | ||
2701 | 424 | self.ci_data.cloud_config['apt_sources']) | ||
2702 | 425 | |||
2703 | 426 | def create_file(self, path, content): | ||
2704 | 427 | with open(path, 'wb') as f: | ||
2705 | 428 | f.write(content) | ||
2706 | 429 | |||
2707 | 430 | def test_good_ssh_keys(self): | ||
2708 | 431 | paths = ('rsa', 'rsa.pub', 'dsa', 'dsa.pub', 'ecdsa', 'ecdsa.pub') | ||
2709 | 432 | for path in paths: | ||
2710 | 433 | self.create_file(path, '%s\ncontent\n' % (path,)) | ||
2711 | 434 | paths_as_list = ','.join(paths) | ||
2712 | 435 | self.conf.store._load_from_string( | ||
2713 | 436 | 'vm.ssh_keys = %s' % (paths_as_list,)) | ||
2714 | 437 | self.ci_data.populate() | ||
2715 | 438 | self.assertEqual({'dsa_private': 'dsa\ncontent\n', | ||
2716 | 439 | 'dsa_public': 'dsa.pub\ncontent\n', | ||
2717 | 440 | 'ecdsa_private': 'ecdsa\ncontent\n', | ||
2718 | 441 | 'ecdsa_public': 'ecdsa.pub\ncontent\n', | ||
2719 | 442 | 'rsa_private': 'rsa\ncontent\n', | ||
2720 | 443 | 'rsa_public': 'rsa.pub\ncontent\n'}, | ||
2721 | 444 | self.ci_data.cloud_config['ssh_keys']) | ||
2722 | 445 | |||
2723 | 446 | def test_bad_type_ssh_keys(self): | ||
2724 | 447 | self.conf.store._load_from_string('vm.ssh_keys = I-dont-exist') | ||
2725 | 448 | self.assertRaises(setup_vm.ConfigValueError, self.ci_data.populate) | ||
2726 | 449 | |||
2727 | 450 | def test_unknown_ssh_keys(self): | ||
2728 | 451 | self.conf.store._load_from_string('vm.ssh_keys = rsa.pub') | ||
2729 | 452 | self.assertRaises(setup_vm.ConfigPathNotFound, self.ci_data.populate) | ||
2730 | 453 | |||
2731 | 454 | def test_good_ssh_authorized_keys(self): | ||
2732 | 455 | paths = ('home.pub', 'work.pub') | ||
2733 | 456 | for path in paths: | ||
2734 | 457 | self.create_file(path, '%s\ncontent\n' % (path,)) | ||
2735 | 458 | paths_as_list = ','.join(paths) | ||
2736 | 459 | self.conf.store._load_from_string( | ||
2737 | 460 | 'vm.ssh_authorized_keys = %s' % (paths_as_list,)) | ||
2738 | 461 | self.ci_data.populate() | ||
2739 | 462 | self.assertEqual(['home.pub\ncontent\n', 'work.pub\ncontent\n'], | ||
2740 | 463 | self.ci_data.cloud_config['ssh_authorized_keys']) | ||
2741 | 464 | |||
2742 | 465 | def test_unknown_ssh_authorized_keys(self): | ||
2743 | 466 | self.conf.store._load_from_string('vm.ssh_authorized_keys = rsa.pub') | ||
2744 | 467 | self.assertRaises(setup_vm.ConfigPathNotFound, self.ci_data.populate) | ||
2745 | 468 | |||
2746 | 469 | def test_unknown_root_script(self): | ||
2747 | 470 | self.conf.store._load_from_string('vm.root_script = I-dont-exist') | ||
2748 | 471 | self.assertRaises(setup_vm.ConfigPathNotFound, self.ci_data.populate) | ||
2749 | 472 | |||
2750 | 473 | def test_unknown_ubuntu_script(self): | ||
2751 | 474 | self.conf.store._load_from_string('vm.ubuntu_script = I-dont-exist') | ||
2752 | 475 | self.assertRaises(setup_vm.ConfigPathNotFound, self.ci_data.populate) | ||
2753 | 476 | |||
2754 | 477 | def test_expansion_error_in_script(self): | ||
2755 | 478 | root_script_content = '''#!/bin/sh | ||
2756 | 479 | echo Hello {I_dont_exist} | ||
2757 | 480 | ''' | ||
2758 | 481 | with open('root_script.sh', 'w') as f: | ||
2759 | 482 | f.write(root_script_content) | ||
2760 | 483 | self.conf.store._load_from_string('''\ | ||
2761 | 484 | vm.root_script = root_script.sh | ||
2762 | 485 | ''') | ||
2763 | 486 | e = self.assertRaises(errors.ExpandingUnknownOption, | ||
2764 | 487 | self.ci_data.populate) | ||
2765 | 488 | self.assertEqual(root_script_content, e.string) | ||
2766 | 489 | |||
2767 | 490 | def test_unknown_uploaded_scripts(self): | ||
2768 | 491 | self.conf.store._load_from_string( | ||
2769 | 492 | '''vm.uploaded_scripts = I-dont-exist ''') | ||
2770 | 493 | e = self.assertRaises(setup_vm.ConfigPathNotFound, | ||
2771 | 494 | self.ci_data.populate) | ||
2772 | 495 | |||
2773 | 496 | def test_root_script(self): | ||
2774 | 497 | with open('root_script.sh', 'w') as f: | ||
2775 | 498 | f.write('''#!/bin/sh | ||
2776 | 499 | echo Hello {user} | ||
2777 | 500 | ''') | ||
2778 | 501 | self.conf.store._load_from_string('''\ | ||
2779 | 502 | vm.root_script = root_script.sh | ||
2780 | 503 | user=root | ||
2781 | 504 | ''') | ||
2782 | 505 | self.ci_data.populate() | ||
2783 | 506 | # The additional newline after the script is expected | ||
2784 | 507 | self.assertEqual('''\ | ||
2785 | 508 | #!/bin/sh | ||
2786 | 509 | cat >~root/setup_vm_post_install <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
2787 | 510 | #!/bin/sh | ||
2788 | 511 | echo Hello root | ||
2789 | 512 | |||
2790 | 513 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
2791 | 514 | chown root:root ~root/setup_vm_post_install | ||
2792 | 515 | chmod 0700 ~root/setup_vm_post_install | ||
2793 | 516 | ''', self.ci_data.root_hook) | ||
2794 | 517 | self.assertEqual(['~root/setup_vm_post_install'], | ||
2795 | 518 | self.ci_data.cloud_config['runcmd']) | ||
2796 | 519 | |||
2797 | 520 | def test_ubuntu_script(self): | ||
2798 | 521 | with open('ubuntu_script.sh', 'w') as f: | ||
2799 | 522 | f.write('''#!/bin/sh | ||
2800 | 523 | echo Hello {user} | ||
2801 | 524 | ''') | ||
2802 | 525 | self.conf.store._load_from_string('''\ | ||
2803 | 526 | vm.ubuntu_script = ubuntu_script.sh | ||
2804 | 527 | user = ubuntu | ||
2805 | 528 | ''') | ||
2806 | 529 | self.ci_data.populate() | ||
2807 | 530 | # The additional newline after the script is expected | ||
2808 | 531 | self.assertEqual('''\ | ||
2809 | 532 | #!/bin/sh | ||
2810 | 533 | cat >~ubuntu/setup_vm_post_install <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
2811 | 534 | #!/bin/sh | ||
2812 | 535 | echo Hello ubuntu | ||
2813 | 536 | |||
2814 | 537 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
2815 | 538 | chown ubuntu:ubuntu ~ubuntu/setup_vm_post_install | ||
2816 | 539 | chmod 0700 ~ubuntu/setup_vm_post_install | ||
2817 | 540 | ''', self.ci_data.ubuntu_hook) | ||
2818 | 541 | # The command is run as root, so we need to 'su ubuntu' first | ||
2819 | 542 | self.assertEqual([['su', '-l', | ||
2820 | 543 | '-c', '~ubuntu/setup_vm_post_install', | ||
2821 | 544 | 'ubuntu']], | ||
2822 | 545 | self.ci_data.cloud_config['runcmd']) | ||
2823 | 546 | |||
2824 | 547 | def test_uploaded_scripts(self): | ||
2825 | 548 | paths = ('foo', 'bar') | ||
2826 | 549 | for path in paths: | ||
2827 | 550 | self.create_file(path, '%s\ncontent\n' % (path,)) | ||
2828 | 551 | paths_as_list = ','.join(paths) | ||
2829 | 552 | self.conf.store._load_from_string( | ||
2830 | 553 | 'vm.uploaded_scripts = %s' % (paths_as_list,)) | ||
2831 | 554 | self.ci_data.populate() | ||
2832 | 555 | self.assertEqual('''\ | ||
2833 | 556 | #!/bin/sh | ||
2834 | 557 | cat >~ubuntu/setup_vm_uploads <<'EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN' | ||
2835 | 558 | mkdir -p ~ubuntu/bin | ||
2836 | 559 | cd ~ubuntu/bin | ||
2837 | 560 | cat >foo <<'EOFfoo' | ||
2838 | 561 | foo | ||
2839 | 562 | content | ||
2840 | 563 | |||
2841 | 564 | EOFfoo | ||
2842 | 565 | chmod 0755 foo | ||
2843 | 566 | cat >bar <<'EOFbar' | ||
2844 | 567 | bar | ||
2845 | 568 | content | ||
2846 | 569 | |||
2847 | 570 | EOFbar | ||
2848 | 571 | chmod 0755 bar | ||
2849 | 572 | EOSETUPVMCONTENTREALLYUNIQUEDONTBREAKFORFUN | ||
2850 | 573 | chown ubuntu:ubuntu ~ubuntu/setup_vm_uploads | ||
2851 | 574 | chmod 0700 ~ubuntu/setup_vm_uploads | ||
2852 | 575 | ''', | ||
2853 | 576 | self.ci_data.uploaded_scripts_hook) | ||
2854 | 577 | self.assertEqual([['su', '-l', | ||
2855 | 578 | '-c', '~ubuntu/setup_vm_uploads', | ||
2856 | 579 | 'ubuntu']], | ||
2857 | 580 | self.ci_data.cloud_config['runcmd']) | ||
2858 | 581 | |||
2859 | 582 | |||
2860 | 583 | class TestCreateUserData(TestCaseWithHome): | ||
2861 | 584 | |||
2862 | 585 | def setUp(self): | ||
2863 | 586 | super(TestCreateUserData, self).setUp() | ||
2864 | 587 | self.conf = setup_vm.VmStack('foo') | ||
2865 | 588 | self.vm = setup_vm.Kvm(self.conf) | ||
2866 | 589 | |||
2867 | 590 | def test_empty_config(self): | ||
2868 | 591 | config_dir = os.path.join(self.test_base_dir, 'config') | ||
2869 | 592 | os.mkdir(config_dir) | ||
2870 | 593 | # The config is *almost* empty, we need to set config_dir though as the | ||
2871 | 594 | # user-data needs to be stored there. | ||
2872 | 595 | self.conf.store._load_from_string('vm.config_dir=%s' % (config_dir,)) | ||
2873 | 596 | self.vm.create_user_data() | ||
2874 | 597 | self.assertTrue(os.path.exists(self.vm._config_dir)) | ||
2875 | 598 | self.assertTrue(os.path.exists(self.vm._user_data_path)) | ||
2876 | 599 | with open(self.vm._user_data_path) as f: | ||
2877 | 600 | user_data = f.readlines() | ||
2878 | 601 | # We care about the two first lines only here, checking the format (or | ||
2879 | 602 | # cloud-init is confused) | ||
2880 | 603 | self.assertEqual('#cloud-config-archive\n', user_data[0]) | ||
2881 | 604 | self.assertEqual("- {content: '#cloud-config\n", user_data[1]) | ||
2882 | 605 | |||
2883 | 606 | |||
2884 | 607 | class TestSeed(TestCaseWithHome): | ||
2885 | 608 | |||
2886 | 609 | def setUp(self): | ||
2887 | 610 | super(TestSeed, self).setUp() | ||
2888 | 611 | self.conf = setup_vm.VmStack('foo') | ||
2889 | 612 | self.vm = setup_vm.Kvm(self.conf) | ||
2890 | 613 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
2891 | 614 | os.mkdir(images_dir) | ||
2892 | 615 | config_dir = os.path.join(self.test_base_dir, 'config') | ||
2893 | 616 | self.conf.store._load_from_string(''' | ||
2894 | 617 | vm.name=foo | ||
2895 | 618 | vm.release=raring | ||
2896 | 619 | vm.config_dir=%s | ||
2897 | 620 | vm.images_dir=%s | ||
2898 | 621 | ''' % (config_dir, images_dir,)) | ||
2899 | 622 | |||
2900 | 623 | def test_create_meta_data(self): | ||
2901 | 624 | self.vm.create_meta_data() | ||
2902 | 625 | self.assertTrue(os.path.exists(self.vm._meta_data_path)) | ||
2903 | 626 | |||
2904 | 627 | def test_create_user_data(self): | ||
2905 | 628 | self.vm.create_user_data() | ||
2906 | 629 | self.assertTrue(os.path.exists(self.vm._user_data_path)) | ||
2907 | 630 | |||
2908 | 631 | def test_create_seed(self): | ||
2909 | 632 | self.assertTrue(self.vm._seed_path is None) | ||
2910 | 633 | self.vm.create_seed() | ||
2911 | 634 | self.assertFalse(self.vm._seed_path is None) | ||
2912 | 635 | self.assertTrue(os.path.exists(self.vm._seed_path)) | ||
2913 | 636 | |||
2914 | 637 | |||
2915 | 638 | class TestImageFromCloud(TestCaseWithHome): | ||
2916 | 639 | |||
2917 | 640 | def setUp(self): | ||
2918 | 641 | super(TestImageFromCloud, self).setUp() | ||
2919 | 642 | self.conf = setup_vm.VmStack('foo') | ||
2920 | 643 | self.vm = setup_vm.KvmFromCloudImage(self.conf) | ||
2921 | 644 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
2922 | 645 | os.mkdir(images_dir) | ||
2923 | 646 | download_cache_dir = os.path.join(self.test_base_dir, 'download') | ||
2924 | 647 | os.mkdir(download_cache_dir) | ||
2925 | 648 | self.conf.store._load_from_string(''' | ||
2926 | 649 | vm.name=foo | ||
2927 | 650 | vm.release=raring | ||
2928 | 651 | vm.images_dir=%s | ||
2929 | 652 | vm.download_cache=%s | ||
2930 | 653 | vm.cloud_image_name=fake.img | ||
2931 | 654 | vm.disk_size=1M | ||
2932 | 655 | ''' % (images_dir, download_cache_dir)) | ||
2933 | 656 | |||
2934 | 657 | def test_create_disk_image(self): | ||
2935 | 658 | cloud_image_path = os.path.join(self.conf.get('vm.download_cache'), | ||
2936 | 659 | self.conf.get('vm.cloud_image_name')) | ||
2937 | 660 | # We need a fake cloud image that can be converted | ||
2938 | 661 | setup_vm.run_subprocess( | ||
2939 | 662 | ['sudo', 'qemu-img', 'create', | ||
2940 | 663 | cloud_image_path, self.conf.get('vm.disk_size')]) | ||
2941 | 664 | self.assertTrue(self.vm._disk_image_path is None) | ||
2942 | 665 | self.vm.create_disk_image() | ||
2943 | 666 | self.assertFalse(self.vm._disk_image_path is None) | ||
2944 | 667 | self.assertTrue(os.path.exists(self.vm._disk_image_path)) | ||
2945 | 668 | |||
2946 | 669 | |||
2947 | 670 | class TestImageWithBacking(TestCaseWithHome): | ||
2948 | 671 | |||
2949 | 672 | def setUp(self): | ||
2950 | 673 | (download_cache_dir, | ||
2951 | 674 | reference_cloud_image_name) = requires_known_reference_image(self) | ||
2952 | 675 | super(TestImageWithBacking, self).setUp() | ||
2953 | 676 | # We'll share the images_dir between vms | ||
2954 | 677 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
2955 | 678 | os.mkdir(images_dir) | ||
2956 | 679 | # Create a shared config | ||
2957 | 680 | conf = setup_vm.VmStack(None) | ||
2958 | 681 | conf.store._load_from_string(''' | ||
2959 | 682 | vm.release=raring | ||
2960 | 683 | vm.images_dir=%s | ||
2961 | 684 | vm.download_cache=%s | ||
2962 | 685 | vm.disk_size=2G | ||
2963 | 686 | [selftest-from-cloud] | ||
2964 | 687 | vm.name=selftest-from-cloud | ||
2965 | 688 | vm.cloud_image_name=%s | ||
2966 | 689 | [selftest-backing] | ||
2967 | 690 | vm.name=selftest-backing | ||
2968 | 691 | vm.backing=selftest-from-cloud.qcow2 | ||
2969 | 692 | ''' % (images_dir, download_cache_dir, reference_cloud_image_name)) | ||
2970 | 693 | conf.store.save() | ||
2971 | 694 | # To bypass creating a real vm, we start from the cloud image that is a | ||
2972 | 695 | # real and bootable one, so we just convert it. That also makes it | ||
2973 | 696 | # available in vm.images_dir | ||
2974 | 697 | temp_vm = setup_vm.KvmFromCloudImage( | ||
2975 | 698 | setup_vm.VmStack('selftest-from-cloud')) | ||
2976 | 699 | temp_vm.create_disk_image() | ||
2977 | 700 | |||
2978 | 701 | def test_create_image_with_backing(self): | ||
2979 | 702 | vm = setup_vm.KvmFromBacking(setup_vm.VmStack('selftest-backing')) | ||
2980 | 703 | self.assertTrue(vm._disk_image_path is None) | ||
2981 | 704 | vm.create_disk_image() | ||
2982 | 705 | self.assertFalse(vm._disk_image_path is None) | ||
2983 | 706 | self.assertTrue(os.path.exists(vm._disk_image_path)) | ||
2984 | 707 | |||
2985 | 708 | |||
2986 | 709 | class TestVmStates(testtools.TestCase): | ||
2987 | 710 | |||
2988 | 711 | def assertStates(self, expected, lines): | ||
2989 | 712 | self.assertEqual(expected, setup_vm.vm_states(lines)) | ||
2990 | 713 | |||
2991 | 714 | def test_empty(self): | ||
2992 | 715 | self.assertStates({},[]) | ||
2993 | 716 | |||
2994 | 717 | def test_garbage(self): | ||
2995 | 718 | self.assertRaises(ValueError, self.assertStates, None, ['']) | ||
2996 | 719 | |||
2997 | 720 | def test_known_states(self): | ||
2998 | 721 | # From a real life sample | ||
2999 | 722 | self.assertStates({'foo': 'shut off', 'bar': 'running'}, | ||
3000 | 723 | ['- foo shut off', | ||
3001 | 724 | '19 bar running']) | ||
3002 | 725 | |||
3003 | 726 | |||
3004 | 727 | class TestConsoleParsing(testtools.TestCase): | ||
3005 | 728 | |||
3006 | 729 | def _parse_console_monitor(self, string): | ||
3007 | 730 | mon = setup_vm.ConsoleMonitor(StringIO(string)) | ||
3008 | 731 | lines = [] | ||
3009 | 732 | for line in mon.parse(): | ||
3010 | 733 | lines.append(line) | ||
3011 | 734 | return lines | ||
3012 | 735 | |||
3013 | 736 | def test_fails_on_empty(self): | ||
3014 | 737 | self.assertRaises(setup_vm.ConsoleEOFError, | ||
3015 | 738 | self._parse_console_monitor, '') | ||
3016 | 739 | |||
3017 | 740 | def test_fail_on_knwon_cloud_init_errors(self): | ||
3018 | 741 | self.assertRaises( | ||
3019 | 742 | setup_vm.CloudInitError, | ||
3020 | 743 | self._parse_console_monitor, | ||
3021 | 744 | 'Failed loading yaml blob\n') | ||
3022 | 745 | self.assertRaises( | ||
3023 | 746 | setup_vm.CloudInitError, | ||
3024 | 747 | self._parse_console_monitor, | ||
3025 | 748 | 'Unhandled non-multipart userdata starting\n') | ||
3026 | 749 | self.assertRaises( | ||
3027 | 750 | setup_vm.CloudInitError, | ||
3028 | 751 | self._parse_console_monitor, | ||
3029 | 752 | "failed to render string to stdout: cannot find 'uptime'\n") | ||
3030 | 753 | self.assertRaises( | ||
3031 | 754 | setup_vm.CloudInitError, | ||
3032 | 755 | self._parse_console_monitor, | ||
3033 | 756 | "Failed loading of cloud config " | ||
3034 | 757 | "'/var/lib/cloud/instance/cloud-config.txt'. " | ||
3035 | 758 | "Continuing with empty config\n") | ||
3036 | 759 | |||
3037 | 760 | def test_succeds_on_final_message(self): | ||
3038 | 761 | lines = self._parse_console_monitor(''' | ||
3039 | 762 | Lalala | ||
3040 | 763 | I'm doing my work | ||
3041 | 764 | It goes nicely | ||
3042 | 765 | setup_vm finished installing in 1 seconds. | ||
3043 | 766 | That was fast isn't it ? | ||
3044 | 767 | * Will now halt | ||
3045 | 768 | [ 33.204755] Power down. | ||
3046 | 769 | ''') | ||
3047 | 770 | # We stop as soon as we get the final message and ignore the rest | ||
3048 | 771 | self.assertEquals(' * Will now halt\n', | ||
3049 | 772 | lines[-1]) | ||
3050 | 773 | |||
3051 | 774 | |||
3052 | 775 | class TestConsoleParsingWithFile(TestCaseWithHome): | ||
3053 | 776 | |||
3054 | 777 | def _parse_file_monitor(self, string): | ||
3055 | 778 | with open('console', 'w') as f: | ||
3056 | 779 | f.write(string) | ||
3057 | 780 | mon = setup_vm.FileMonitor('console') | ||
3058 | 781 | for line in mon.parse(): | ||
3059 | 782 | pass | ||
3060 | 783 | return mon.lines | ||
3061 | 784 | |||
3062 | 785 | def test_succeeds_with_file(self): | ||
3063 | 786 | content = '''\ | ||
3064 | 787 | Yet another install | ||
3065 | 788 | Going well | ||
3066 | 789 | setup_vm finished installing in 0.5 seconds. | ||
3067 | 790 | Wow, even faster ! | ||
3068 | 791 | * Will now halt | ||
3069 | 792 | Whatever, won't read that | ||
3070 | 793 | ''' | ||
3071 | 794 | lines = self._parse_file_monitor(content) | ||
3072 | 795 | |||
3073 | 796 | def xtest_fails_on_empty_file(self): | ||
3074 | 797 | # FIXME: We need some sort of timeout there... | ||
3075 | 798 | self.assertRaises(setup_vm.CommandError, self._parse_file_monitor, '') | ||
3076 | 799 | |||
3077 | 800 | def test_fail_on_knwon_cloud_init_errors_with_file(self): | ||
3078 | 801 | self.assertRaises( | ||
3079 | 802 | setup_vm.CloudInitError, | ||
3080 | 803 | self._parse_file_monitor, | ||
3081 | 804 | 'Failed loading yaml blob\n') | ||
3082 | 805 | self.assertRaises( | ||
3083 | 806 | setup_vm.CloudInitError, | ||
3084 | 807 | self._parse_file_monitor, | ||
3085 | 808 | 'Unhandled non-multipart userdata starting\n') | ||
3086 | 809 | self.assertRaises( | ||
3087 | 810 | setup_vm.CloudInitError, | ||
3088 | 811 | self._parse_file_monitor, | ||
3089 | 812 | "failed to render string to stdout: cannot find 'uptime'\n") | ||
3090 | 813 | |||
3091 | 814 | |||
3092 | 815 | class TestInstallWithSeed(TestCaseWithHome): | ||
3093 | 816 | |||
3094 | 817 | def setUp(self): | ||
3095 | 818 | (download_cache, | ||
3096 | 819 | reference_cloud_image_name) = requires_known_reference_image(self) | ||
3097 | 820 | super(TestInstallWithSeed, self).setUp() | ||
3098 | 821 | # We need to allow other users to read this dir | ||
3099 | 822 | os.chmod(self.test_base_dir, 0755) | ||
3100 | 823 | # We also need to sudo rm it as root created some files there | ||
3101 | 824 | self.addCleanup( | ||
3102 | 825 | setup_vm.run_subprocess, | ||
3103 | 826 | ['sudo', 'rm', '-fr', | ||
3104 | 827 | os.path.join(self.test_base_dir, 'home', '.virtinst')]) | ||
3105 | 828 | self.conf = setup_vm.VmStack('selftest-seed') | ||
3106 | 829 | self.vm = setup_vm.KvmFromCloudImage(self.conf) | ||
3107 | 830 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
3108 | 831 | os.mkdir(images_dir, 0755) | ||
3109 | 832 | config_dir = os.path.join(self.test_base_dir, 'config') | ||
3110 | 833 | self.conf.store._load_from_string(''' | ||
3111 | 834 | vm.name=selftest-seed | ||
3112 | 835 | vm.update=False # Shorten install time | ||
3113 | 836 | vm.cpus=2, | ||
3114 | 837 | vm.release=raring | ||
3115 | 838 | vm.config_dir=%s | ||
3116 | 839 | vm.images_dir=%s | ||
3117 | 840 | vm.download_cache=%s | ||
3118 | 841 | vm.cloud_image_name=%s | ||
3119 | 842 | vm.disk_size=8G | ||
3120 | 843 | ''' % (config_dir, images_dir, download_cache, reference_cloud_image_name)) | ||
3121 | 844 | |||
3122 | 845 | def assertVmState(self, expected): | ||
3123 | 846 | states = setup_vm.vm_states() | ||
3124 | 847 | self.assertEqual(expected, states[self.vm.conf.get('vm.name')]) | ||
3125 | 848 | |||
3126 | 849 | def test_install_with_seed(self): | ||
3127 | 850 | self.addCleanup(self.vm.undefine) | ||
3128 | 851 | self.vm.install() | ||
3129 | 852 | self.assertVmState('shut off') | ||
3130 | 853 | |||
3131 | 854 | |||
3132 | 855 | class TestInstallWithBacking(TestCaseWithHome): | ||
3133 | 856 | |||
3134 | 857 | def setUp(self): | ||
3135 | 858 | (download_cache_dir, | ||
3136 | 859 | reference_cloud_image_name) = requires_known_reference_image(self) | ||
3137 | 860 | super(TestInstallWithBacking, self).setUp() | ||
3138 | 861 | # We need to allow other users to read this dir | ||
3139 | 862 | os.chmod(self.test_base_dir, 0755) | ||
3140 | 863 | # We also need to sudo rm it as root created some files there | ||
3141 | 864 | self.addCleanup( | ||
3142 | 865 | setup_vm.run_subprocess, | ||
3143 | 866 | ['sudo', 'rm', '-fr', | ||
3144 | 867 | os.path.join(self.test_base_dir, 'home', '.virtinst')]) | ||
3145 | 868 | self.conf = setup_vm.VmStack('selftest-backing') | ||
3146 | 869 | self.vm = setup_vm.KvmFromBacking(self.conf) | ||
3147 | 870 | # We'll share the images_dir between vms | ||
3148 | 871 | images_dir = os.path.join(self.test_base_dir, 'images') | ||
3149 | 872 | os.mkdir(images_dir, 0755) | ||
3150 | 873 | config_dir = os.path.join(self.test_base_dir, 'config') | ||
3151 | 874 | # Create a shared config | ||
3152 | 875 | conf = setup_vm.VmStack(None) | ||
3153 | 876 | conf.store._load_from_string(''' | ||
3154 | 877 | vm.release=raring | ||
3155 | 878 | vm.config_dir=%s | ||
3156 | 879 | vm.images_dir=%s | ||
3157 | 880 | vm.download_cache=%s | ||
3158 | 881 | vm.disk_size=2G | ||
3159 | 882 | vm.update=False # Shorten install time | ||
3160 | 883 | [selftest-from-cloud] | ||
3161 | 884 | vm.name=selftest-from-cloud | ||
3162 | 885 | vm.cloud_image_name=%s | ||
3163 | 886 | [selftest-backing] | ||
3164 | 887 | vm.name=selftest-backing | ||
3165 | 888 | vm.backing=selftest-from-cloud.qcow2 | ||
3166 | 889 | ''' % (config_dir, images_dir, download_cache_dir, reference_cloud_image_name)) | ||
3167 | 890 | conf.store.save() | ||
3168 | 891 | # Fake a previous install by just re-using the reference cloud image | ||
3169 | 892 | temp_vm = setup_vm.KvmFromCloudImage( | ||
3170 | 893 | setup_vm.VmStack('selftest-from-cloud')) | ||
3171 | 894 | temp_vm.create_disk_image() | ||
3172 | 895 | |||
3173 | 896 | def assertVmState(self, vm, expected): | ||
3174 | 897 | states = setup_vm.vm_states() | ||
3175 | 898 | self.assertEqual(expected, states[vm.conf.get('vm.name')]) | ||
3176 | 899 | |||
3177 | 900 | def test_install_with_backing(self): | ||
3178 | 901 | vm = setup_vm.KvmFromBacking(setup_vm.VmStack('selftest-backing')) | ||
3179 | 902 | self.addCleanup(vm.undefine) | ||
3180 | 903 | vm.install() | ||
3181 | 904 | self.assertVmState(vm, 'shut off') | ||
3182 | 905 | |||
3183 | 906 | |||
3184 | 907 | class TestSshKeyGen(TestCaseWithHome): | ||
3185 | 908 | |||
3186 | 909 | def setUp(self): | ||
3187 | 910 | super(TestSshKeyGen, self).setUp() | ||
3188 | 911 | self.conf = setup_vm.VmStack(None) | ||
3189 | 912 | self.vm = setup_vm.VM(self.conf) | ||
3190 | 913 | self.config_dir = os.path.join(self.test_base_dir, 'config') | ||
3191 | 914 | |||
3192 | 915 | def load_config(self, more): | ||
3193 | 916 | content = '''\ | ||
3194 | 917 | vm.config_dir=%s | ||
3195 | 918 | vm.name=foo | ||
3196 | 919 | ''' % (self.config_dir,) | ||
3197 | 920 | self.conf.store._load_from_string(content + more) | ||
3198 | 921 | |||
3199 | 922 | def generate_key(self, ssh_type, upper_type=None): | ||
3200 | 923 | if upper_type is None: | ||
3201 | 924 | upper_type = ssh_type.upper() | ||
3202 | 925 | self.load_config('vm.ssh_keys={vm.config_dir}/%s' % (ssh_type,)) | ||
3203 | 926 | self.vm.ssh_keygen() | ||
3204 | 927 | private_path = 'config/%s' % (ssh_type,) | ||
3205 | 928 | self.assertTrue(os.path.exists(private_path)) | ||
3206 | 929 | public_path = 'config/%s.pub' % (ssh_type,) | ||
3207 | 930 | self.assertTrue(os.path.exists(public_path)) | ||
3208 | 931 | public = file(public_path).read() | ||
3209 | 932 | private = file(private_path).read() | ||
3210 | 933 | self.assertTrue(private.startswith( | ||
3211 | 934 | '-----BEGIN %s PRIVATE KEY-----\n' % (upper_type,))) | ||
3212 | 935 | self.assertTrue(private.endswith( | ||
3213 | 936 | '-----END %s PRIVATE KEY-----\n' % (upper_type,))) | ||
3214 | 937 | return private, public | ||
3215 | 938 | |||
3216 | 939 | def test_dsa(self): | ||
3217 | 940 | private, public = self.generate_key('dsa') | ||
3218 | 941 | self.assertTrue(public.startswith('ssh-dss ')) | ||
3219 | 942 | self.assertTrue(public.endswith(' foo\n')) | ||
3220 | 943 | |||
3221 | 944 | def test_rsa(self): | ||
3222 | 945 | private, public = self.generate_key('rsa') | ||
3223 | 946 | self.assertTrue(public.startswith('ssh-rsa ')) | ||
3224 | 947 | self.assertTrue(public.endswith(' foo\n')) | ||
3225 | 948 | |||
3226 | 949 | def test_ecdsa(self): | ||
3227 | 950 | private, public = self.generate_key('ecdsa', 'EC') | ||
3228 | 951 | self.assertTrue(public.startswith('ecdsa-sha2-nistp256 ')) | ||
3229 | 952 | self.assertTrue(public.endswith(' foo\n')) | ||
3230 | 953 | |||
3231 | 954 | |||
3232 | 955 | class TestOptionParsing(testtools.TestCase): | ||
3233 | 956 | |||
3234 | 957 | def setUp(self): | ||
3235 | 958 | super(TestOptionParsing, self).setUp() | ||
3236 | 959 | self.out = StringIO() | ||
3237 | 960 | self.err = StringIO() | ||
3238 | 961 | |||
3239 | 962 | def parse_args(self, args): | ||
3240 | 963 | return setup_vm.arg_parser.parse_args(args, self.out, self.err) | ||
3241 | 964 | |||
3242 | 965 | def test_nothing(self): | ||
3243 | 966 | self.assertRaises(SystemExit, self.parse_args, []) | ||
3244 | 967 | |||
3245 | 968 | def test_install(self): | ||
3246 | 969 | ns = self.parse_args(['foo', '--install']) | ||
3247 | 970 | self.assertEquals('foo', ns.name) | ||
3248 | 971 | self.assertTrue(ns.install) | ||
3249 | 972 | self.assertFalse(ns.download) | ||
3250 | 973 | |||
3251 | 974 | def test_download(self): | ||
3252 | 975 | ns = self.parse_args(['foo', '--download']) | ||
3253 | 976 | self.assertEquals('foo', ns.name) | ||
3254 | 977 | self.assertFalse(ns.install) | ||
3255 | 978 | self.assertTrue(ns.download) | ||
3256 | 979 | |||
3257 | 980 | class TestBuildCommands(testtools.TestCase): | ||
3258 | 981 | |||
3259 | 982 | def setUp(self): | ||
3260 | 983 | super(TestBuildCommands, self).setUp() | ||
3261 | 984 | self.out = StringIO() | ||
3262 | 985 | self.err = StringIO() | ||
3263 | 986 | |||
3264 | 987 | def build_commands(self, args): | ||
3265 | 988 | return setup_vm.build_commands(args, self.out, self.err) | ||
3266 | 989 | |||
3267 | 990 | def test_install(self): | ||
3268 | 991 | cmds = self.build_commands(['--install', 'foo']) | ||
3269 | 992 | self.assertEqual(1, len(cmds)) | ||
3270 | 993 | self.assertTrue(isinstance(cmds[0], setup_vm.Install)) | ||
3271 | 994 | |||
3272 | 995 | def test_download(self): | ||
3273 | 996 | cmds = self.build_commands(['--download', 'foo']) | ||
3274 | 997 | self.assertEqual(1, len(cmds)) | ||
3275 | 998 | self.assertTrue(isinstance(cmds[0], setup_vm.Download)) | ||
3276 | 999 | |||
3277 | 1000 | def test_ssh_keygen(self): | ||
3278 | 1001 | cmds = self.build_commands(['--ssh-keygen', 'foo']) | ||
3279 | 1002 | self.assertEqual(1, len(cmds)) | ||
3280 | 1003 | self.assertTrue(isinstance(cmds[0], setup_vm.SshKeyGen)) | ||
3281 | 1004 | |||
3282 | 1005 | def test_download_and_install(self): | ||
3283 | 1006 | cmds = self.build_commands(['--install', '--download', 'foo']) | ||
3284 | 1007 | self.assertEqual(2, len(cmds)) | ||
3285 | 1008 | # Download comes first | ||
3286 | 1009 | self.assertTrue(isinstance(cmds[0], setup_vm.Download)) | ||
3287 | 1010 | self.assertTrue(isinstance(cmds[1], setup_vm.Install)) | ||
3288 | 1011 | |||
3289 | 1012 | |||
3290 | 1013 | # FIXME: This needs to be parametrized for KvmFromCloudImage and | ||
3291 | 1014 | # KvmFromBacking. Since we don't define vm.backing below, we're only testing | ||
3292 | 1015 | # KvmFromCloudImage for now. -- vila 2013-02-13 | ||
3293 | 1016 | class TestInstall(TestCaseWithHome): | ||
3294 | 1017 | |||
3295 | 1018 | def setUp(self): | ||
3296 | 1019 | super(TestInstall, self).setUp() | ||
3297 | 1020 | self.conf = setup_vm.VmStack('I-dont-exist') | ||
3298 | 1021 | self.conf.store._load_from_string(''' | ||
3299 | 1022 | vm.name=I-dont-exist | ||
3300 | 1023 | vm.release=raring | ||
3301 | 1024 | vm.cpu_model=amd64 | ||
3302 | 1025 | ''') | ||
3303 | 1026 | self.states = [] | ||
3304 | 1027 | |||
3305 | 1028 | def vm_states(source=None): | ||
3306 | 1029 | return self.states | ||
3307 | 1030 | self.patch(setup_vm, 'vm_states', vm_states) | ||
3308 | 1031 | self.vm = None | ||
3309 | 1032 | |||
3310 | 1033 | def install(self): | ||
3311 | 1034 | class FakeKvm(setup_vm.Kvm): | ||
3312 | 1035 | |||
3313 | 1036 | def __init__(self, conf): | ||
3314 | 1037 | super(FakeKvm, self).__init__(conf) | ||
3315 | 1038 | self.undefine_called = False | ||
3316 | 1039 | self.install_called = False | ||
3317 | 1040 | |||
3318 | 1041 | # Make sure we avoid dangerous or costly calls | ||
3319 | 1042 | def poweroff(self): | ||
3320 | 1043 | pass | ||
3321 | 1044 | |||
3322 | 1045 | def undefine(self): | ||
3323 | 1046 | self.undefine_called = True | ||
3324 | 1047 | |||
3325 | 1048 | def install(self): | ||
3326 | 1049 | self.install_called = True | ||
3327 | 1050 | |||
3328 | 1051 | |||
3329 | 1052 | self.vm = FakeKvm(self.conf) | ||
3330 | 1053 | cmd = setup_vm.Install(self.vm) | ||
3331 | 1054 | cmd.run() | ||
3332 | 1055 | |||
3333 | 1056 | def test_install_while_running(self): | ||
3334 | 1057 | self.conf.set('vm.name', 'foo') | ||
3335 | 1058 | self.states = {'foo': 'running'} | ||
3336 | 1059 | self.assertRaises(setup_vm.SetupVmError, self.install) | ||
3337 | 1060 | self.assertFalse(self.vm.install_called) | ||
3338 | 1061 | self.assertFalse(self.vm.undefine_called) | ||
3339 | 1062 | |||
3340 | 1063 | def test_install_unknown(self): | ||
3341 | 1064 | self.states = {} | ||
3342 | 1065 | self.install() | ||
3343 | 1066 | self.assertTrue(self.vm.install_called) | ||
3344 | 1067 | self.assertFalse(self.vm.undefine_called) | ||
3345 | 1068 | |||
3346 | 1069 | def test_install_shutoff(self): | ||
3347 | 1070 | self.conf.set('vm.name', 'foo') | ||
3348 | 1071 | self.states = {'foo': 'shut off'} | ||
3349 | 1072 | self.install() | ||
3350 | 1073 | self.assertTrue(self.vm.install_called) | ||
3351 | 1074 | self.assertTrue(self.vm.undefine_called) | ||
3352 | 0 | 1075 | ||
3353 | === added file 'setup_vm/tests/test_test.py' | |||
3354 | --- setup_vm/tests/test_test.py 1970-01-01 00:00:00 +0000 | |||
3355 | +++ setup_vm/tests/test_test.py 2013-04-17 01:29:27 +0000 | |||
3356 | @@ -0,0 +1,58 @@ | |||
3357 | 1 | import os | ||
3358 | 2 | |||
3359 | 3 | import testtools | ||
3360 | 4 | |||
3361 | 5 | import tests | ||
3362 | 6 | |||
3363 | 7 | |||
3364 | 8 | def assertTestSuccess(test, inner): | ||
3365 | 9 | """The received test runs successfully.""" | ||
3366 | 10 | result = testtools.TestResult() | ||
3367 | 11 | inner.run(result) | ||
3368 | 12 | test.assertEqual(0, len(result.errors) + len(result.failures)) | ||
3369 | 13 | test.assertEqual(1, result.testsRun) | ||
3370 | 14 | return result | ||
3371 | 15 | |||
3372 | 16 | |||
3373 | 17 | class TestEnv(testtools.TestCase): | ||
3374 | 18 | |||
3375 | 19 | |||
3376 | 20 | def test_env_preserved(self): | ||
3377 | 21 | os.environ['NOBODY_USES_THIS'] = 'foo' | ||
3378 | 22 | |||
3379 | 23 | class Inner(testtools.TestCase): | ||
3380 | 24 | |||
3381 | 25 | def test_overridden(self): | ||
3382 | 26 | tests.isolate_env(self, {'NOBODY_USES_THIS': 'bar'}) | ||
3383 | 27 | self.assertEqual('bar', os.environ['NOBODY_USES_THIS']) | ||
3384 | 28 | |||
3385 | 29 | assertTestSuccess(self, Inner('test_overridden')) | ||
3386 | 30 | self.assertEqual('foo', os.environ['NOBODY_USES_THIS']) | ||
3387 | 31 | |||
3388 | 32 | def test_env_var_deleted(self): | ||
3389 | 33 | os.environ['NOBODY_USES_THIS'] = 'foo' | ||
3390 | 34 | |||
3391 | 35 | class Inner(testtools.TestCase): | ||
3392 | 36 | |||
3393 | 37 | def test_deleted(self): | ||
3394 | 38 | tests.isolate_env(self, {'NOBODY_USES_THIS': None}) | ||
3395 | 39 | self.assertIs('deleted', | ||
3396 | 40 | os.environ.get('NOBODY_USES_THIS', 'deleted')) | ||
3397 | 41 | assertTestSuccess(self, Inner('test_deleted')) | ||
3398 | 42 | self.assertEqual('foo', os.environ['NOBODY_USES_THIS']) | ||
3399 | 43 | |||
3400 | 44 | |||
3401 | 45 | class TestTmp(testtools.TestCase): | ||
3402 | 46 | |||
3403 | 47 | def test_cwd_in_tmp(self): | ||
3404 | 48 | |||
3405 | 49 | class Inner(testtools.TestCase): | ||
3406 | 50 | |||
3407 | 51 | def setUp(self): | ||
3408 | 52 | super(Inner, self).setUp() | ||
3409 | 53 | tests.set_cwd_to_tmp(self) | ||
3410 | 54 | |||
3411 | 55 | def test_cwd_in_tmp(self): | ||
3412 | 56 | self.assertEqual(os.getcwdu(), self.test_base_dir) | ||
3413 | 57 | |||
3414 | 58 | assertTestSuccess(self, Inner('test_cwd_in_tmp')) | ||
3415 | 0 | 59 | ||
3416 | === added directory 'setup_vm/u1' | |||
3417 | === added file 'setup_vm/u1/install' | |||
3418 | --- setup_vm/u1/install 1970-01-01 00:00:00 +0000 | |||
3419 | +++ setup_vm/u1/install 2013-04-17 01:29:27 +0000 | |||
3420 | @@ -0,0 +1,71 @@ | |||
3421 | 1 | #!/bin/sh -ex | ||
3422 | 2 | |||
3423 | 3 | # Allow ssh access to launchpad. | ||
3424 | 4 | # This should probably be provided by setup_vm. -- vila 2013-03-10 | ||
3425 | 5 | ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts | ||
3426 | 6 | # Use the openjdk. | ||
3427 | 7 | sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java | ||
3428 | 8 | # Get the branch. | ||
3429 | 9 | bzr branch lp:ubuntuone-servers {u1.src_dir} | ||
3430 | 10 | # Setup the environment. | ||
3431 | 11 | cd {u1.src_dir} | ||
3432 | 12 | # Set up the correct configuration. | ||
3433 | 13 | cat <<EOF >configs/local.conf | ||
3434 | 14 | [meta] | ||
3435 | 15 | extends: development-appserver-lazr.conf | ||
3436 | 16 | |||
3437 | 17 | [general] | ||
3438 | 18 | port: {u1.port} | ||
3439 | 19 | django_module: u1servers.web.localsettings | ||
3440 | 20 | |||
3441 | 21 | [upay] | ||
3442 | 22 | consumer_id: U1 | ||
3443 | 23 | port: {pay.port} | ||
3444 | 24 | hostname: {pay.address} | ||
3445 | 25 | url_format: http://%(host)s:%(port)d/api/2.0 | ||
3446 | 26 | |||
3447 | 27 | [upay_u1ms] | ||
3448 | 28 | consumer_id: U1 | ||
3449 | 29 | port: {pay.port} | ||
3450 | 30 | hostname: {pay.address} | ||
3451 | 31 | url_format: http://%(host)s:%(port)d/api/2.0 | ||
3452 | 32 | |||
3453 | 33 | [url] | ||
3454 | 34 | openid_sso_server: {sso.url} | ||
3455 | 35 | |||
3456 | 36 | EOF | ||
3457 | 37 | # XXX The secrets file is overlayed, so we can't use the config file. | ||
3458 | 38 | # This is an ugly way to overwrite the default values. | ||
3459 | 39 | cat <<EOF >>configs/dev_secrets-lazr.conf | ||
3460 | 40 | ubuntu_pay_username: u1qauser | ||
3461 | 41 | ubuntu_pay_password: u1qapassword | ||
3462 | 42 | ubuntu_pay_username_u1ms: u1qauser | ||
3463 | 43 | ubuntu_pay_password_u1ms: u1qapassword | ||
3464 | 44 | |||
3465 | 45 | EOF | ||
3466 | 46 | cat <<EOF >servers/u1servers/web/localsettings.py | ||
3467 | 47 | from u1servers.web.devsettings import * | ||
3468 | 48 | |||
3469 | 49 | OPENID_SSO_SERVER_URL = config.url.openid_sso_server | ||
3470 | 50 | OPENID_SSO_LOGOUT_URL = '%s/+logout?return_to=%s' % ( | ||
3471 | 51 | OPENID_SSO_SERVER_URL, BASE_URL) | ||
3472 | 52 | |||
3473 | 53 | if __name__ == os.environ.get("DJANGO_SETTINGS_MODULE"): | ||
3474 | 54 | # This only gets executed if the configured DJANGO_SETTINGS_MODULE matches | ||
3475 | 55 | # the current module name. | ||
3476 | 56 | from ubuntuone import dispatch | ||
3477 | 57 | dispatch.connect_all(async=True) | ||
3478 | 58 | |||
3479 | 59 | from u1servers.web import email | ||
3480 | 60 | email.connect_receivers() | ||
3481 | 61 | |||
3482 | 62 | # Triggered when the env variable U1_PAY_HOST is defined with | ||
3483 | 63 | # "<hostname>:<port>" | ||
3484 | 64 | if config.upay.hostname or config.upay_u1ms.hostname: | ||
3485 | 65 | from u1backends.account.upayclient import init_payclient | ||
3486 | 66 | init_payclient() | ||
3487 | 67 | EOF | ||
3488 | 68 | make update-sourcedeps | ||
3489 | 69 | # TODO ask on #u1-ops if there's a better way. | ||
3490 | 70 | sed -i 's/development-lazr.conf/local.conf/g' utilities/supervisor-dev.conf.tpl | ||
3491 | 71 | sed -i 's/development-appserver-lazr.conf/local.conf/g' utilities/supervisor-dev.conf.tpl | ||
3492 | 0 | 72 | ||
3493 | === added file 'setup_vm/u1/run' | |||
3494 | --- setup_vm/u1/run 1970-01-01 00:00:00 +0000 | |||
3495 | +++ setup_vm/u1/run 2013-04-17 01:29:27 +0000 | |||
3496 | @@ -0,0 +1,4 @@ | |||
3497 | 1 | #!/bin/sh | ||
3498 | 2 | |||
3499 | 3 | cd ~/{u1.src_dir} | ||
3500 | 4 | HOSTNAME={u1.address} DJANGO_SETTINGS_MODULE=u1servers.web.localsettings U1CONFIG=`pwd`/configs/local.conf make start | ||
3501 | 0 | 5 | ||
3502 | === added file 'setup_vm/u1/test' | |||
3503 | --- setup_vm/u1/test 1970-01-01 00:00:00 +0000 | |||
3504 | +++ setup_vm/u1/test 2013-04-17 01:29:27 +0000 | |||
3505 | @@ -0,0 +1,15 @@ | |||
3506 | 1 | #!/bin/sh | ||
3507 | 2 | |||
3508 | 3 | |||
3509 | 4 | cd {u1.src_dir} | ||
3510 | 5 | # When run from the host against the u1 guest: | ||
3511 | 6 | # sudo apt-get install python-mocker | ||
3512 | 7 | # scp ubuntu@{u1.address}:~/ubuntuone-servers/configs/local.conf configs/local.conf | ||
3513 | 8 | # scp ubuntu@{u1.address}:~/ubuntuone-servers/servers/u1servers/web/localsettings.py servers/u1servers/web/localsettings.py | ||
3514 | 9 | # TODO ask on #u1-ops if there's a better way. | ||
3515 | 10 | # sed -i 's/development-lazr.conf/local.conf/g' utilities/supervisor-dev.conf.tpl | ||
3516 | 11 | # sed -i 's/development-appserver-lazr.conf/local.conf/g' utilities/supervisor-dev.conf.tpl | ||
3517 | 12 | # echo 9999 >tmp/statsd.port | ||
3518 | 13 | # make update-sourcedeps | ||
3519 | 14 | U1CONFIG=`pwd`/configs/local.conf make smoke-test | ||
3520 | 15 | U1CONFIG=`pwd`/configs/local.conf make acceptance-test | ||
3521 | 0 | 16 | ||
3522 | === added directory 'setup_vm/unity' | |||
3523 | === added file 'setup_vm/unity/install-sources' | |||
3524 | --- setup_vm/unity/install-sources 1970-01-01 00:00:00 +0000 | |||
3525 | +++ setup_vm/unity/install-sources 2013-04-17 01:29:27 +0000 | |||
3526 | @@ -0,0 +1,19 @@ | |||
3527 | 1 | #!/bin/sh | ||
3528 | 2 | # Allow ssh access to launchpad. | ||
3529 | 3 | # This should probably be provided by setup_vm. -- vila 2013-03-10 | ||
3530 | 4 | ssh-keyscan bazaar.launchpad.net >>~/.ssh/known_hosts | ||
3531 | 5 | # Install sst and dependencies from source | ||
3532 | 6 | mkdir src | ||
3533 | 7 | cd src | ||
3534 | 8 | bzr branch lp:~ubuntuone-hackers/ubuntuone-servers/selenium | ||
3535 | 9 | bzr branch lp:~canonical-isd-qa/selenium-simple-test/trunk selenium-simple-test | ||
3536 | 10 | cd ~/src/selenium | ||
3537 | 11 | python setup.py install --user | ||
3538 | 12 | cd ~/src/selenium-simple-test | ||
3539 | 13 | python setup.py install --user | ||
3540 | 14 | |||
3541 | 15 | # If the need arise to use sst-run, it may become necessary to create a | ||
3542 | 16 | # symlink to /home/ubuntu/.local/bin/sst-run | ||
3543 | 17 | |||
3544 | 18 | # Also note that unittest2 is installed as a side-effect of installing sst | ||
3545 | 19 | # even if we're already using pyton-2.7 (which includes unittest2 features). | ||
3546 | 0 | 20 | ||
3547 | === added file 'setup_vm/unity/run-sso-client' | |||
3548 | --- setup_vm/unity/run-sso-client 1970-01-01 00:00:00 +0000 | |||
3549 | +++ setup_vm/unity/run-sso-client 2013-04-17 01:29:27 +0000 | |||
3550 | @@ -0,0 +1,11 @@ | |||
3551 | 1 | #!/bin/sh -ex | ||
3552 | 2 | |||
3553 | 3 | # We can use U1_DEBUG=True to get debug messages on the console. | ||
3554 | 4 | USSOC_SERVICE_URL={sso.url}/api/1.0/ /usr/lib/ubuntu-sso-client/ubuntu-sso-login & | ||
3555 | 5 | # XXX ugly sleep. | ||
3556 | 6 | sleep 5s | ||
3557 | 7 | # TODO x86_64 sounds like trouble. | ||
3558 | 8 | # This has just stopped working on raring. See http://pad.lv/1161067 | ||
3559 | 9 | # TODO in order for the application to be accessible with testability, we need | ||
3560 | 10 | # TESTABILITY=1 | ||
3561 | 11 | /usr/lib/ubuntu-sso-client/ubuntu-sso-login-qt --app_name 'Ubuntu One' --help_text '...' --ping_url '{u1.url}/oauth/sso-finished-so-get-tokens/%7Bemail%7D?platform_version=3.8.0-2-generic&platform=Linux&client_version=4.1.90&platform_arch=x86_64' --policy_url {u1.url}/privacy/ --tc_url {u1.url}/terms/ | ||
3562 | 0 | 12 | ||
3563 | === added file 'setup_vm/unity/run-syncdaemon' | |||
3564 | --- setup_vm/unity/run-syncdaemon 1970-01-01 00:00:00 +0000 | |||
3565 | +++ setup_vm/unity/run-syncdaemon 2013-04-17 01:29:27 +0000 | |||
3566 | @@ -0,0 +1,4 @@ | |||
3567 | 1 | #!/bin/sh -ex | ||
3568 | 2 | |||
3569 | 3 | /usr/lib/ubuntuone-client/ubuntuone-syncdaemon --disable_ssl_verify --dns_srv=None --host={filesync.address} & | ||
3570 | 4 | u1sdtool --connect | ||
3571 | 0 | 5 | ||
3572 | === added file 'setup_vm/unity/run-unity-lens-music' | |||
3573 | --- setup_vm/unity/run-unity-lens-music 1970-01-01 00:00:00 +0000 | |||
3574 | +++ setup_vm/unity/run-unity-lens-music 2013-04-17 01:29:27 +0000 | |||
3575 | @@ -0,0 +1,6 @@ | |||
3576 | 1 | #!/bin/sh -ex | ||
3577 | 2 | |||
3578 | 3 | # TODO x86_64 sounds like trouble. | ||
3579 | 4 | # We can use G_MESSAGES_DEBUG=all to get debug messages on the console. | ||
3580 | 5 | # TODO change the name of the environment variables, it's not just staging. | ||
3581 | 6 | pkill unity-music; U1_STAGING_WEBAPI={u1.url} U1_STAGING_AUTHENTICATION={sso.url} /usr/lib/x86_64-linux-gnu/unity-lens-music/unity-musicstore-daemon | ||
3582 | 0 | 7 | ||
3583 | === added file 'setup_vm/unity/transient-dist-upgrade' | |||
3584 | --- setup_vm/unity/transient-dist-upgrade 1970-01-01 00:00:00 +0000 | |||
3585 | +++ setup_vm/unity/transient-dist-upgrade 2013-04-17 01:29:27 +0000 | |||
3586 | @@ -0,0 +1,4 @@ | |||
3587 | 1 | #!/bin/sh | ||
3588 | 2 | # For an unclear reason (probably a transient raring issue) we need to | ||
3589 | 3 | # dist-upgrade instead of just upgrade | ||
3590 | 4 | apt-get dist-upgrade -y | ||
3591 | 0 | 5 | ||
3592 | === added file 'setup_vm/vms.conf' | |||
3593 | --- setup_vm/vms.conf 1970-01-01 00:00:00 +0000 | |||
3594 | +++ setup_vm/vms.conf 2013-04-17 01:29:27 +0000 | |||
3595 | @@ -0,0 +1,96 @@ | |||
3596 | 1 | # This must be defined in some other vms.conf file (user or system) | ||
3597 | 2 | # sso.address=sso.local | ||
3598 | 3 | # pay.address=pay.local | ||
3599 | 4 | # u1.address=u1.local | ||
3600 | 5 | # ppa.ubuntuone-hackers.password | ||
3601 | 6 | |||
3602 | 7 | sso.src_dir=canonical-identity-provider | ||
3603 | 8 | sso.port=8001 | ||
3604 | 9 | sso.url=http://{sso.address}:{sso.port} | ||
3605 | 10 | sso.imap_port=2143 | ||
3606 | 11 | sso.smtp_port=2025 | ||
3607 | 12 | |||
3608 | 13 | pay.src_dir=canonical-payment-service | ||
3609 | 14 | pay.port=8002 | ||
3610 | 15 | pay.url=http://{pay.address}:{pay.port} | ||
3611 | 16 | |||
3612 | 17 | ppa.ubuntuone_hackers=deb https://{vm.launchpad_id}:{ppa.ubuntuone_hackers.password}@private-ppa.launchpad.net/ubuntuone/hackers/ubuntu {vm.release} main|4BD0ECAE | ||
3613 | 18 | |||
3614 | 19 | u1.src_dir=ubuntuone-servers | ||
3615 | 20 | u1.port=8003 | ||
3616 | 21 | u1.url=http://{u1.address}:{u1.port} | ||
3617 | 22 | |||
3618 | 23 | [precise-server-pristine] | ||
3619 | 24 | vm.name=precise-server-pristine | ||
3620 | 25 | vm.release=precise | ||
3621 | 26 | vm.packages=bzr, avahi-daemon, emacs23 | ||
3622 | 27 | vm.update=True | ||
3623 | 28 | |||
3624 | 29 | [sso] | ||
3625 | 30 | vm.name=sso | ||
3626 | 31 | vm.release=precise | ||
3627 | 32 | vm.backing=precise-server-pristine.qcow2 | ||
3628 | 33 | vm.packages=config-manager, fabric, libpq-dev, make, memcached, postgresql-plpython, python-m2crypto, python-dev, python-setuptools, python-virtualenv, swig, wget, libxml2-dev, libxslt1-dev | ||
3629 | 34 | vm.ubuntu_script=sso/install | ||
3630 | 35 | vm.update=True | ||
3631 | 36 | vm.uploaded_scripts=sso/run, sso/run-for-pay, sso/run-for-u1 | ||
3632 | 37 | |||
3633 | 38 | [pay] | ||
3634 | 39 | vm.name=pay | ||
3635 | 40 | vm.release=precise | ||
3636 | 41 | vm.backing=precise-server-pristine.qcow2 | ||
3637 | 42 | vm.packages=config-manager, fabric, libpq-dev, make, postgresql-plpython, python-dev, python-setuptools, python-virtualenv, wget, libxml2-dev, libxslt1-dev | ||
3638 | 43 | vm.ubuntu_script=pay/install | ||
3639 | 44 | vm.update=True | ||
3640 | 45 | vm.uploaded_scripts=pay/run, pay/run-for-u1 | ||
3641 | 46 | |||
3642 | 47 | [u1] | ||
3643 | 48 | vm.name=u1 | ||
3644 | 49 | vm.release=precise | ||
3645 | 50 | vm.backing=precise-server-pristine.qcow2 | ||
3646 | 51 | vm.apt_sources={ppa.ubuntuone_hackers} | ||
3647 | 52 | vm.packages=openjdk-7-jre,ubuntuone-developer-dependencies | ||
3648 | 53 | vm.ubuntu_script=u1/install | ||
3649 | 54 | vm.update=True | ||
3650 | 55 | vm.uploaded_scripts=u1/run | ||
3651 | 56 | |||
3652 | 57 | [raring-desktop-pristine] | ||
3653 | 58 | vm.name=raring-desktop-pristine | ||
3654 | 59 | vm.release=raring | ||
3655 | 60 | # python-unittest2 is not strictly required here but works around sst | ||
3656 | 61 | # insisting on installing it locally. | ||
3657 | 62 | vm.packages=bzr, emacs23, python-setuptools, python-unittest2, python-autopilot, unity-autopilot, ubuntu-desktop, avahi-daemon | ||
3658 | 63 | vm.update=True | ||
3659 | 64 | # Roughly all vms installing ubuntu-desktop need to complete the | ||
3660 | 65 | # installation by making the ubuntu user part of the admin group. | ||
3661 | 66 | vm.root_script = bin/ubuntu_admin.sh | ||
3662 | 67 | |||
3663 | 68 | [purchase-testing] | ||
3664 | 69 | vm.name=purchase-testing | ||
3665 | 70 | vm.release=raring | ||
3666 | 71 | vm.backing=raring-desktop-pristine.qcow2 | ||
3667 | 72 | vm.apt_sources=deb http://ppa.launchpad.net/ubuntuone/dashpurchase-testing/ubuntu {vm.release} main|4BD0ECAE | ||
3668 | 73 | vm.update=True | ||
3669 | 74 | vm.ubuntu_script=purchase-testing/install | ||
3670 | 75 | |||
3671 | 76 | [unity-prevalidation] | ||
3672 | 77 | vm.name=unity-prevalidation | ||
3673 | 78 | vm.release=raring | ||
3674 | 79 | vm.backing=raring-desktop-pristine.qcow2 | ||
3675 | 80 | vm.apt_sources=deb http://ppa.launchpad.net/ubuntu-unity/experimental-prevalidation/ubuntu {vm.release} main|52D62F45 | ||
3676 | 81 | vm.uploaded_scripts=unity/run-sso-client, unity/run-unity-lens-music | ||
3677 | 82 | # TODO unity/run-syncdaemon. We don't yet have the hermetic filesync server. | ||
3678 | 83 | vm.update=True | ||
3679 | 84 | vm.root_script=unity/transient-dist-upgrade | ||
3680 | 85 | vm.ubuntu_script=unity/install-sources | ||
3681 | 86 | |||
3682 | 87 | [indash-didrocks] | ||
3683 | 88 | vm.name=indash-didrocks | ||
3684 | 89 | vm.release=raring | ||
3685 | 90 | vm.backing=raring-desktop-pristine.qcow2 | ||
3686 | 91 | vm.apt_sources=ppa:didrocks/ppa | ||
3687 | 92 | vm.uploaded_scripts=unity/run-sso-client, unity/run-unity-lens-music | ||
3688 | 93 | # TODO unity/run-syncdaemon. We don't yet have the hermetic filesync server. | ||
3689 | 94 | vm.update=True | ||
3690 | 95 | vm.root_script=unity/transient-dist-upgrade | ||
3691 | 96 | vm.ubuntu_script=unity/install-sources |
Currently blocked by: https:/ /bugs.launchpad .net/ubuntuone- servers/ +bug/1169218
We can work it around making a new Consumer and User on Ubuntu Pay.