ia64/xen-unstable

view tools/python/xen/xm/tests/test_create.py @ 11435:f7368ad7c795

Added vmunused flag to unit test results to match recent change.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Sep 05 17:26:18 2006 +0100 (2006-09-05)
parents 724af97aea47
children a18ae238eb53
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 'vncunused' : 1,
55 'xauthority': xen.xm.create.get_xauthority(),
56 })
59 def testConfigFile(self):
60 (fd, fname) = tempfile.mkstemp()
61 try:
62 os.write(fd,
63 '''
64 kernel = "/boot/vmlinuz-xenU-smp"
65 memory = 768
66 name = "dom1"
67 vcpus = 4
68 disk = ['phy:/dev/virt-blkdev-backend/dom1,sda1,w',
69 'phy:/dev/virt-blkdev-backend/usr,sda2,r']
70 root = "/dev/sda1 ro"
71 extra = " profile=1 GATEWAY=10.0.1.254 NETMASK=255.255.0.0 IPADDR=10.0.134.1 HOSTNAME=dom1"
72 on_poweroff = 'destroy'
73 on_reboot = 'destroy'
74 on_crash = 'destroy'
75 ''')
76 finally:
77 os.close(fd)
79 self.t('-f %s display=fakedisplay' % fname,
80 { 'kernel' : '/boot/vmlinuz-xenU-smp',
81 'memory' : 768,
82 'name' : 'dom1',
83 'vcpus' : 4,
84 'nics' : -1,
85 'root' : '/dev/sda1 ro',
86 'extra' : ' profile=1 GATEWAY=10.0.1.254 NETMASK=255.255.0.0 IPADDR=10.0.134.1 HOSTNAME=dom1',
87 'on_poweroff' : 'destroy',
88 'on_reboot' : 'destroy',
89 'on_crash' : 'destroy',
90 'disk' : [['phy:/dev/virt-blkdev-backend/dom1',
91 'sda1', 'w', None],
92 ['phy:/dev/virt-blkdev-backend/usr',
93 'sda2', 'r', None]],
95 'xm_file' : fname,
96 'defconfig' : fname,
97 'display' : 'fakedisplay',
99 'boot' : 'c',
100 'dhcp' : 'off',
101 'interface' : 'eth0',
102 'path' : '.:/etc/xen',
103 'builder' : 'linux',
105 'vncunused' : 1,
106 'xauthority' : xen.xm.create.get_xauthority(),
107 })
110 def testConfigFileAndCommandLine(self):
111 (fd, fname) = tempfile.mkstemp()
112 try:
113 os.write(fd,
114 '''
115 name = "testname"
116 memory = 256
117 kernel = "/mykernel"
118 maxmem = 1024
119 cpu = 2
120 cpu_weight = 0.75
121 ''')
122 finally:
123 os.close(fd)
125 self.t('-f %s display=fakedisplay macaddr=ab:cd:ef:ed' %
126 fname,
127 { 'name' : 'testname',
128 'xm_file' : fname,
129 'defconfig' : fname,
130 'kernel' : '/mykernel',
131 'display' : 'fakedisplay',
132 'macaddr' : 'ab:cd:ef:ed',
133 'memory' : 256,
134 'maxmem' : 1024,
135 'cpu' : 2,
136 'cpu_weight' : 0.75,
137 'vcpus' : 1,
138 'boot' : 'c',
139 'dhcp' : 'off',
140 'interface' : 'eth0',
141 'path' : '.:/etc/xen',
142 'builder' : 'linux',
143 'nics' : -1,
145 'vncunused' : 1,
146 'xauthority' : xen.xm.create.get_xauthority(),
147 })
150 def testHVMConfigFile(self):
151 (fd, fname) = tempfile.mkstemp()
152 try:
153 os.write(fd,
154 '''
155 kernel = "/usr/lib/xen/boot/hvmloader"
156 builder='hvm'
157 memory = 128
158 name = "ExampleHVMDomain"
159 vcpus=1
160 vif = [ 'type=ioemu, bridge=xenbr0' ]
161 disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
162 device_model = '/usr/lib/xen/bin/qemu-dm'
163 sdl=0
164 vnc=1
165 vncviewer=1
166 ne2000=0
167 ''')
168 finally:
169 os.close(fd)
171 self.t('-f %s display=fakedisplay' % fname,
172 { 'kernel' : '/usr/lib/xen/boot/hvmloader',
173 'builder' : 'hvm',
174 'memory' : 128,
175 'name' : 'ExampleHVMDomain',
176 'vcpus' : 1,
177 'nics' : -1,
178 'vif' : ['type=ioemu, bridge=xenbr0'],
179 'disk' : [['file:/var/images/min-el3-i386.img',
180 'ioemu:hda', 'w', None]],
181 'device_model': '/usr/lib/xen/bin/qemu-dm',
183 'extra' : ('VNC_VIEWER=%s:%d ' %
184 (xen.xm.create.get_host_addr(),
185 xen.xm.create.VNC_BASE_PORT +
186 xen.xm.create.choose_vnc_display())),
187 'vnc' : 1,
188 'vncunused' : 1,
189 'vncviewer' : 1,
191 'xm_file' : fname,
192 'defconfig' : fname,
193 'display' : 'fakedisplay',
195 'boot' : 'c',
196 'dhcp' : 'off',
197 'interface' : 'eth0',
198 'path' : '.:/etc/xen',
200 'xauthority' : xen.xm.create.get_xauthority(),
201 })
204 def test_suite():
205 return unittest.makeSuite(test_create)