ia64/xen-unstable

view tools/python/xen/xm/tests/test_create.py @ 9955:3534801f08da

Remove ssidref field from test -- this now only works if there is a policy in
place at the time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Fri May 05 16:46:48 2006 +0100 (2006-05-05)
parents 9fcfdab04aa9
children 724af97aea47
line source
1 import os
2 import os.path
3 import tempfile
4 import unittest
6 import xen.xend.XendRoot
8 xen.xend.XendRoot.XendRoot.config_default = '/dev/null'
10 import xen.xm.create
13 class test_create(unittest.TestCase):
15 def assertEqualModuloNulls_(self, a, b):
16 for k, v in a.iteritems():
17 if v:
18 self.failUnless(k in b, '%s not in b' % k)
19 self.assertEqual(v, b[k])
20 else:
21 self.assert_(k not in b or not b[k], '%s in b' % k)
24 def assertEqualModuloNulls(self, a, b):
25 self.assertEqualModuloNulls_(a, b)
26 self.assertEqualModuloNulls_(b, a)
29 def t(self, args, expected):
30 self.assertEqualModuloNulls(
31 xen.xm.create.parseCommandLine(args.split(' '))[0].vals.__dict__,
32 expected)
35 def testCommandLine(self):
36 (fd, fname) = tempfile.mkstemp()
37 os.close(fd)
38 self.t('-f %s kernel=/mykernel display=fakedisplay '
39 'macaddr=ab:cd:ef:ed' % fname,
40 { 'name' : os.path.basename(fname),
41 'xm_file' : fname,
42 'defconfig' : fname,
43 'kernel' : '/mykernel',
44 'display' : 'fakedisplay',
45 'macaddr' : 'ab:cd:ef:ed',
46 'memory' : 128,
47 'vcpus' : 1,
48 'boot' : 'c',
49 'dhcp' : 'off',
50 'interface' : 'eth0',
51 'path' : '.:/etc/xen',
52 'builder' : 'linux',
53 'nics' : -1,
54 'xauthority': xen.xm.create.get_xauthority(),
55 })
58 def testConfigFile(self):
59 (fd, fname) = tempfile.mkstemp()
60 try:
61 os.write(fd,
62 '''
63 kernel = "/boot/vmlinuz-xenU-smp"
64 memory = 768
65 name = "dom1"
66 vcpus = 4
67 disk = ['phy:/dev/virt-blkdev-backend/dom1,sda1,w',
68 'phy:/dev/virt-blkdev-backend/usr,sda2,r']
69 root = "/dev/sda1 ro"
70 extra = " profile=1 GATEWAY=10.0.1.254 NETMASK=255.255.0.0 IPADDR=10.0.134.1 HOSTNAME=dom1"
71 on_poweroff = 'destroy'
72 on_reboot = 'destroy'
73 on_crash = 'destroy'
74 ''')
75 finally:
76 os.close(fd)
78 self.t('-f %s display=fakedisplay' % fname,
79 { 'kernel' : '/boot/vmlinuz-xenU-smp',
80 'memory' : 768,
81 'name' : 'dom1',
82 'vcpus' : 4,
83 'nics' : -1,
84 'root' : '/dev/sda1 ro',
85 'extra' : ' profile=1 GATEWAY=10.0.1.254 NETMASK=255.255.0.0 IPADDR=10.0.134.1 HOSTNAME=dom1',
86 'on_poweroff' : 'destroy',
87 'on_reboot' : 'destroy',
88 'on_crash' : 'destroy',
89 'disk' : [['phy:/dev/virt-blkdev-backend/dom1',
90 'sda1', 'w', None],
91 ['phy:/dev/virt-blkdev-backend/usr',
92 'sda2', 'r', None]],
94 'xm_file' : fname,
95 'defconfig' : fname,
96 'display' : 'fakedisplay',
98 'boot' : 'c',
99 'dhcp' : 'off',
100 'interface' : 'eth0',
101 'path' : '.:/etc/xen',
102 'builder' : 'linux',
104 'xauthority' : xen.xm.create.get_xauthority(),
105 })
108 def testConfigFileAndCommandLine(self):
109 (fd, fname) = tempfile.mkstemp()
110 try:
111 os.write(fd,
112 '''
113 name = "testname"
114 memory = 256
115 kernel = "/mykernel"
116 maxmem = 1024
117 cpu = 2
118 cpu_weight = 0.75
119 ''')
120 finally:
121 os.close(fd)
123 self.t('-f %s display=fakedisplay macaddr=ab:cd:ef:ed' %
124 fname,
125 { 'name' : 'testname',
126 'xm_file' : fname,
127 'defconfig' : fname,
128 'kernel' : '/mykernel',
129 'display' : 'fakedisplay',
130 'macaddr' : 'ab:cd:ef:ed',
131 'memory' : 256,
132 'maxmem' : 1024,
133 'cpu' : 2,
134 'cpu_weight' : 0.75,
135 'vcpus' : 1,
136 'boot' : 'c',
137 'dhcp' : 'off',
138 'interface' : 'eth0',
139 'path' : '.:/etc/xen',
140 'builder' : 'linux',
141 'nics' : -1,
143 'xauthority' : xen.xm.create.get_xauthority(),
144 })
147 def testHVMConfigFile(self):
148 (fd, fname) = tempfile.mkstemp()
149 try:
150 os.write(fd,
151 '''
152 kernel = "/usr/lib/xen/boot/hvmloader"
153 builder='hvm'
154 memory = 128
155 name = "ExampleHVMDomain"
156 vcpus=1
157 vif = [ 'type=ioemu, bridge=xenbr0' ]
158 disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
159 device_model = '/usr/lib/xen/bin/qemu-dm'
160 sdl=0
161 vnc=1
162 vncviewer=1
163 ne2000=0
164 ''')
165 finally:
166 os.close(fd)
168 self.t('-f %s display=fakedisplay' % fname,
169 { 'kernel' : '/usr/lib/xen/boot/hvmloader',
170 'builder' : 'hvm',
171 'memory' : 128,
172 'name' : 'ExampleHVMDomain',
173 'vcpus' : 1,
174 'nics' : -1,
175 'vif' : ['type=ioemu, bridge=xenbr0'],
176 'disk' : [['file:/var/images/min-el3-i386.img',
177 'ioemu:hda', 'w', None]],
178 'device_model': '/usr/lib/xen/bin/qemu-dm',
180 'extra' : ('VNC_VIEWER=%s:%d ' %
181 (xen.xm.create.get_host_addr(),
182 xen.xm.create.VNC_BASE_PORT + 1)),
183 'vnc' : 1,
184 'vncviewer' : 1,
186 'xm_file' : fname,
187 'defconfig' : fname,
188 'display' : 'fakedisplay',
190 'boot' : 'c',
191 'dhcp' : 'off',
192 'interface' : 'eth0',
193 'path' : '.:/etc/xen',
195 'xauthority' : xen.xm.create.get_xauthority(),
196 })
199 def test_suite():
200 return unittest.makeSuite(test_create)