ia64/xen-unstable

view tools/python/xen/xm/tests/test_create.py @ 16739:33dcf04d7715

tools/docs: Fix example and default IP addresses.

In various places in documentation and code, IP addresses are provided
as examples, defaults, or dummy configuration. In general the
specific IP addresses used in Xen are not always appropriate. (For
example, 1.2.3.4 is used in a few places!)

The following addresses should be used:
* For examples and documentation, 192.0.2.0/24. (See RFC3330.)
* For defaults for private networks, a random network from RFC1918.
I have randomly selected 172.30.206.0/24 for this purpose and
documented this in at the only registry I know of,
www.ucam.org/cam-grin. This network should henceforth be used for
default configurations of local bridges, test networks, etc. in
Xen tools.

The following addresses should NOT be used:
* 10.0.*.*, 10.1.*.*, 192.168.0.*, 192.168.1.*, etc. Using these
addresses gives greatly increased likelihood of collision, as
ignorant network administrators and reckless middlebox vendors
often pick networks from the bottom of 10/8 and 192.168/16.
* 169.254.*.*. These are reserved for zeroconf (ad-hoc networking)
and should not be used for Xen private networks, bridges, etc.,
etc. Use of these addresses by Xen scripts causes trouble on hosts
(eg laptops) which find themselves in ad-hoc networking
environments. I think this is not hypothetical (!) since at least
one Linux distribution have specific code to detect this case and
cause Xen startup to fail iff the host already has an external
zeroconf address.
* 1.2.3.4. WTF !?

I have also used 127.0.255.255 in one place where apparently a dummy
address is needed (some Linux kernels won't accept a lack of an NFS
server address). If 127.0.255.255 is mistakenly used it is unlikely
to do any damage to real traffic even if it does escape into the
network at large.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 15:13:40 2008 +0000 (2008-01-17)
parents a18ae238eb53
children 23f9857f642f
line source
1 import os
2 import os.path
3 import tempfile
4 import unittest
6 import xen.xend.XendOptions
8 xen.xend.XendOptions.XendOptions.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=192.0.2.254 NETMASK=255.255.255.0 IPADDR=192.0.2.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=192.0.2.254 NETMASK=255.255.255.0 IPADDR=192.0.2.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)