ia64/xen-unstable

view tools/python/scripts/test_vm_create.py @ 19527:0e24e9674ded

tools: Always use sane upstream (`native') python paths

Previously, by default we would install our python modules into
/usr/lib/python/xen, for example /usr/lib/python/xen/__init__.py.
Upstream python's standard install location (a) includes the Python
version number and (b) puts things in site-packages by default.

Our best conjecture for the reason for this was an attempt to make the
installs portable between different python versions. However, that
doesn't work because compiled python modules (.pyc), and C python
extensions corresponding to one version of python, are not compatible
across different versions of python.

This is why upstream include the version number.

site-packages is the standard location for locally-installed packages
and is automatically included on the python search path.

In this change, we abandon our own unusual python path setup:

* Invoke setup.py in an entirely standard manner. We pass
PREFIX and DESTDIR using the appropriate options provided by
setup.py for those purposes (adding them to setup.py calls
which were previously lacking them).

* Since the installation locations are now on the standard
python path, we no longer need to add anything to the path
in any of our python utilities. Therefore remove all that
code from every python script. (Many of these scripts
unconditionally added /usr/lib/python and /usr/lib64/python which
is wrong even in the old world.)

* There is no longer any special `Xen python path'. xen-python-path
is no longer needed. It is no longer called by anything in our
tree. However since out-of-tree callers may still invoke it, we
retain it. It now prints a fixed string referring to a directory
which does not to exist; callers (who use it to augment their
python path) will thus add a nonexistent directory to their python
path which is harmless.

* Remove various workarounds including use of setup.py --home
(which is intended for something completely different).

* Remove tests for the XEN_PYTHON_NATIVE_INSTALL build-time
environment variable. The new behaviour is the behaviour which we
should have had if this variable had been set. That is, it is now
as if this variable was always set but also bugs in the resulting
install have been fixed.

This should be a proper fix for the bug addressed by c/s 19515.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 08 19:13:04 2009 +0100 (2009-04-08)
parents 2adbc1d22fe7
children
line source
1 #!/usr/bin/python
3 vm_cfg = {
4 'name_label': 'APIVM',
5 'user_version': 1,
6 'is_a_template': False,
7 'auto_power_on': False, # TODO
9 'memory_static_min': 64,
10 'memory_static_max': 128,
11 #'memory_dynamic_min': 64,
12 #'memory_dynamic_max': 128,
15 'VCPUs_policy': 'credit',
16 'VCPUs_params': '',
17 'VCPUs_number': 2,
19 'actions_after_shutdown': 'destroy',
20 'actions_after_reboot': 'restart',
21 'actions_after_crash': 'destroy',
23 'PV_bootloader': '',
24 'PV_bootloader_args': '',
26 'PV_kernel': '/boot/vmlinuz-2.6.18-xenU',
27 'PV_ramdisk': '',
28 'PV_args': 'root=/dev/sda1 ro',
30 #'HVM_boot': '',
31 'platform_std_VGA': False,
32 'platform_serial': '',
33 'platform_localtime': False,
34 'platform_clock_offset': False,
35 'platform_enable_audio': False,
36 'PCI_bus': ''
37 }
39 vdi_cfg = {
40 'name_label': 'API_VDI',
41 'name_description': '',
42 'virtual_size': 100 * 1024 * 1024 * 1024,
43 'type': 'system',
44 'parent': '',
45 'SR_name': 'QCoW',
46 'sharable': False,
47 'read_only': False,
48 }
50 vbd_cfg = {
51 'VDI': '',
52 'VM': '',
53 'device': 'sda2',
54 'mode': 'RW',
55 'type': 'disk',
56 'driver': 'paravirtualised',
57 }
59 local_vdi_cfg = {
60 'name_label': 'gentoo.amd64.img',
61 'name_description': '',
62 'virtual_size': 0,
63 'type': 'system',
64 'parent': '',
65 'SR_name': 'Local',
66 'sharable': False,
67 'read_only': False,
68 'other_config': {'location': 'file:/root/gentoo.amd64.img'},
69 }
71 local_vbd_cfg = {
72 'VDI': '',
73 'VM': '',
74 'device': 'sda1',
75 'mode': 'RW',
76 'type': 'disk',
77 'driver': 'paravirtualised',
78 }
80 vif_cfg = {
81 'name': 'API_VIF',
82 'type': 'paravirtualised',
83 'device': '',
84 'network': '',
85 'MAC': '',
86 'MTU': 1500,
87 }
89 console_cfg = {
90 'protocol': 'rfb',
91 'other_config': {'vncunused': 1, 'vncpasswd': 'testing'},
92 }
94 import sys
95 import time
97 from xapi import connect, execute
99 def test_vm_create():
100 server, session = connect()
101 vm_uuid = None
102 vdi_uuid = None
103 local_vdi_uuid = None
104 local_vbd_uuid = None
105 vbd_uuid = None
106 vif_uuid = None
108 # List all VMs
109 vm_list = execute(server, 'VM.get_all', (session,))
110 vm_names = []
111 for vm_uuid in vm_list:
112 vm_record = execute(server, 'VM.get_record', (session, vm_uuid))
113 vm_names.append(vm_record['name_label'])
115 # Get default SR
116 sr_list = execute(server, 'SR.get_by_name_label', (session,
117 vdi_cfg['SR_name']))
118 sr_uuid = sr_list[0]
120 local_sr_list = execute(server, 'SR.get_by_name_label',
121 (session, local_vdi_cfg['SR_name']))
122 local_sr_uuid = local_sr_list[0]
124 # Get default network
125 net_list = execute(server, 'network.get_all', (session,))
126 net_uuid = net_list[0]
128 try:
129 # Create a new VM
130 vm_uuid = execute(server, 'VM.create', (session, vm_cfg))
132 # Create a new VDI
133 vdi_cfg['SR'] = sr_uuid
134 vdi_uuid = execute(server, 'VDI.create', (session, vdi_cfg))
136 # Create a VDI backed VBD
137 vbd_cfg['VM'] = vm_uuid
138 vbd_cfg['VDI'] = vdi_uuid
139 vbd_uuid = execute(server, 'VBD.create', (session, vbd_cfg))
141 # Create a new VDI (Local)
142 local_vdi_cfg['SR'] = local_sr_uuid
143 local_vdi_uuid = execute(server, 'VDI.create',
144 (session, local_vdi_cfg))
146 # Create a new VBD (Local)
147 local_vbd_cfg['VM'] = vm_uuid
148 local_vbd_cfg['VDI'] = local_vdi_uuid
149 local_vbd_uuid = execute(server, 'VBD.create',
150 (session, local_vbd_cfg))
152 # Create a new VIF
153 vif_cfg['network'] = net_uuid
154 vif_cfg['VM'] = vm_uuid
155 vif_uuid = execute(server, 'VIF.create', (session, vif_cfg))
157 # Create a console
158 console_cfg['VM'] = vm_uuid
159 console_uuid = execute(server, 'console.create',
160 (session, console_cfg))
161 print console_uuid
163 # Start the VM
164 execute(server, 'VM.start', (session, vm_uuid, False))
166 time.sleep(30)
168 test_suspend = False
169 if test_suspend:
170 print 'Suspending VM..'
171 execute(server, 'VM.suspend', (session, vm_uuid))
172 print 'Suspended VM.'
173 time.sleep(5)
174 print 'Resuming VM ...'
175 execute(server, 'VM.resume', (session, vm_uuid, False))
176 print 'Resumed VM.'
178 finally:
179 # Wait for user to say we're good to shut it down
180 while True:
181 destroy = raw_input('destroy VM? ')
182 if destroy[0] in ('y', 'Y'):
183 break
185 # Clean up
186 if vif_uuid:
187 execute(server, 'VIF.destroy', (session, vif_uuid))
189 if local_vbd_uuid:
190 execute(server, 'VBD.destroy', (session, local_vbd_uuid))
191 if local_vdi_uuid:
192 execute(server, 'VDI.destroy', (session, local_vdi_uuid))
194 if vbd_uuid:
195 execute(server, 'VBD.destroy', (session, vbd_uuid))
196 if vdi_uuid:
197 execute(server, 'VDI.destroy', (session, vdi_uuid))
199 if vm_uuid:
200 try:
201 execute(server, 'VM.hard_shutdown', (session, vm_uuid))
202 time.sleep(2)
203 except:
204 pass
206 execute(server, 'VM.destroy', (session, vm_uuid))
209 if __name__ == "__main__":
210 test_vm_create()