Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit 1b84a30

Browse files
committed
tests: Leverage virtinst URI parsing more
Means we can drop similar functionality from xmlconfig
1 parent 3fc8cd1 commit 1b84a30

12 files changed

Lines changed: 374 additions & 413 deletions

File tree

tests/cli-test-xml/clone-disk-noexist.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<domain type='xen'>
1+
<domain type='test'>
22
<name>test-clone-noexist</name>
33
<currentMemory>204800</currentMemory>
44
<memory>409600</memory>

tests/cli-test-xml/compare/clone-auto1.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<domain type="xen" id="3">
2+
<domain type="test" id="3">
33
<name>test-for-clone1</name>
44
<uuid>00000000-1111-2222-3333-444444444444</uuid>
55
<memory>409600</memory>
@@ -60,6 +60,5 @@
6060
<source path="/tmp/foo.log"/>
6161
<target port="0"/>
6262
</parallel>
63-
<memballoon model="xen"/>
6463
</devices>
6564
</domain>

tests/cli-test-xml/compare/clone-auto2.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<domain type="xen" id="2">
2+
<domain type="test" id="2">
33
<name>newvm</name>
44
<uuid>00000000-1111-2222-3333-444444444444</uuid>
55
<memory>409600</memory>
@@ -34,6 +34,5 @@
3434
<source path="/tmp/foo.log"/>
3535
<target port="0"/>
3636
</parallel>
37-
<memballoon model="xen"/>
3837
</devices>
3938
</domain>

tests/image.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import os
2323

2424
import utils
25-
import xmlconfig
2625

2726
qemuuri = "__virtinst_test__test:///default,caps=%s/tests/capabilities-xml/capabilities-kvm.xml,qemu,predictable" % os.getcwd()
2827

@@ -82,12 +81,12 @@ def _image2XMLhelper(self, image_xml, output_xmls, qemu=False):
8281
inst = virtinst.ImageInstaller(image, caps, boot_index=idx,
8382
conn=conn)
8483

85-
xmlconfig.set_conn(conn)
84+
utils.set_conn(conn)
8685

8786
if inst.is_hvm():
88-
g = xmlconfig.get_basic_fullyvirt_guest(typ=gtype)
87+
g = utils.get_basic_fullyvirt_guest(typ=gtype)
8988
else:
90-
g = xmlconfig.get_basic_paravirt_guest()
89+
g = utils.get_basic_paravirt_guest()
9190

9291
g.installer = inst
9392
g._prepare_install(None)
@@ -98,7 +97,7 @@ def _image2XMLhelper(self, image_xml, output_xmls, qemu=False):
9897
utils.diff_compare(g.get_config_xml(install=False),
9998
image2guestdir + fname, expect_out=expect_out)
10099

101-
xmlconfig.reset_conn()
100+
utils.reset_conn()
102101

103102
# Build libvirt XML from the image xml
104103
# XXX: This doesn't set up devices, so the guest xml will be pretty

tests/utils.py

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,56 @@
1919
import logging
2020

2121
import libvirt
22+
23+
import virtinst
2224
import virtinst.cli
25+
from virtinst import VirtualAudio
26+
from virtinst import VirtualDisk
27+
from virtinst import VirtualVideoDevice
2328

2429
# Used to ensure consistent SDL xml output
2530
os.environ["HOME"] = "/tmp"
2631
os.environ["DISPLAY"] = ":3.4"
2732

2833
_cwd = os.getcwd()
34+
scratch = os.path.join(_cwd, "tests", "testscratchdir")
2935
_testuri = "test:///%s/tests/testdriver.xml" % _cwd
3036
_fakeuri = "__virtinst_test__" + _testuri + ",predictable"
3137
_kvmcaps = "%s/tests/capabilities-xml/libvirt-0.7.6-qemu-caps.xml" % _cwd
32-
_kvmuri = "%s,caps=%s,qemu" % (_fakeuri, _kvmcaps)
38+
_plainkvm = "%s,qemu" % _fakeuri
39+
_plainxen = "%s,xen" % _fakeuri
40+
_kvmuri = "%s,caps=%s" % (_plainkvm, _kvmcaps)
3341

3442
def get_debug():
3543
return ("DEBUG_TESTS" in os.environ and
3644
os.environ["DEBUG_TESTS"] == "1")
3745

46+
def _make_uri(base, connver=None, libver=None):
47+
if connver:
48+
base += ",connver=%s" % connver
49+
if libver:
50+
base += ",libver=%s" % libver
51+
return base
52+
3853
def open_testdriver():
3954
return virtinst.cli.getConnection(_testuri)
40-
4155
def open_testkvmdriver():
4256
return virtinst.cli.getConnection(_kvmuri)
57+
def open_plainkvm(connver=None, libver=None):
58+
return virtinst.cli.getConnection(_make_uri(_plainkvm, connver, libver))
59+
def open_plainxen(connver=None, libver=None):
60+
return virtinst.cli.getConnection(_make_uri(_plainxen, connver, libver))
61+
62+
_default_conn = open_testdriver()
63+
_conn = None
64+
def set_conn(newconn):
65+
global _conn
66+
_conn = newconn
67+
def reset_conn():
68+
set_conn(_default_conn)
69+
def get_conn():
70+
return _conn
71+
reset_conn()
4372

4473
# Register libvirt handler
4574
def libvirt_callback(ignore, err):
@@ -105,3 +134,89 @@ def diff_compare(actual_out, filename=None, expect_out=None):
105134
tofile="Generated Output"))
106135
if diff:
107136
raise AssertionError("Conversion outputs did not match.\n%s" % diff)
137+
138+
139+
def get_basic_paravirt_guest(installer=None):
140+
g = virtinst.ParaVirtGuest(connection=_conn, type="xen")
141+
g.name = "TestGuest"
142+
g.memory = int(200)
143+
g.maxmemory = int(400)
144+
g.uuid = "12345678-1234-1234-1234-123456789012"
145+
g.boot = ["/boot/vmlinuz", "/boot/initrd"]
146+
g.graphics = (True, "vnc", None, "ja")
147+
g.vcpus = 5
148+
149+
if installer:
150+
g.installer = installer
151+
152+
g.installer._scratchdir = scratch
153+
return g
154+
155+
def get_basic_fullyvirt_guest(typ="xen", installer=None):
156+
g = virtinst.FullVirtGuest(connection=_conn, type=typ,
157+
emulator="/usr/lib/xen/bin/qemu-dm",
158+
arch="i686")
159+
g.name = "TestGuest"
160+
g.memory = int(200)
161+
g.maxmemory = int(400)
162+
g.uuid = "12345678-1234-1234-1234-123456789012"
163+
g.cdrom = "/dev/loop0"
164+
g.graphics = (True, "sdl")
165+
g.features['pae'] = 0
166+
g.vcpus = 5
167+
if installer:
168+
g.installer = installer
169+
170+
g.installer._scratchdir = scratch
171+
return g
172+
173+
def make_import_installer(os_type="hvm"):
174+
inst = virtinst.ImportInstaller(type="xen", os_type=os_type, conn=_conn)
175+
return inst
176+
177+
def make_distro_installer(location="/default-pool/default-vol", gtype="xen"):
178+
inst = virtinst.DistroInstaller(type=gtype, os_type="hvm", conn=_conn,
179+
location=location)
180+
return inst
181+
182+
def make_live_installer(location="/dev/loop0", gtype="xen"):
183+
inst = virtinst.LiveCDInstaller(type=gtype, os_type="hvm",
184+
conn=_conn, location=location)
185+
return inst
186+
187+
def make_pxe_installer(gtype="xen"):
188+
inst = virtinst.PXEInstaller(type=gtype, os_type="hvm", conn=_conn)
189+
return inst
190+
191+
def build_win_kvm(path=None):
192+
g = get_basic_fullyvirt_guest("kvm")
193+
g.os_type = "windows"
194+
g.os_variant = "winxp"
195+
g.disks.append(get_filedisk(path))
196+
g.disks.append(get_blkdisk())
197+
g.nics.append(get_virtual_network())
198+
g.add_device(VirtualAudio())
199+
g.add_device(VirtualVideoDevice(g.conn))
200+
201+
return g
202+
203+
def get_floppy(path=None):
204+
if not path:
205+
path = "/default-pool/testvol1.img"
206+
return VirtualDisk(path, conn=_conn, device=VirtualDisk.DEVICE_FLOPPY)
207+
208+
def get_filedisk(path=None):
209+
if not path:
210+
path = "/tmp/test.img"
211+
return VirtualDisk(path, size=.0001, conn=_conn)
212+
213+
def get_blkdisk(path="/dev/loop0"):
214+
return VirtualDisk(path, conn=_conn)
215+
216+
def get_virtual_network():
217+
dev = virtinst.VirtualNetworkInterface(conn=_conn)
218+
dev.macaddr = "11:22:33:44:55:66"
219+
dev.type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
220+
dev.network = "default"
221+
return dev
222+

tests/xmlconfig-xml/rhel6-kvm-stage1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<input type='tablet' bus='usb'/>
4343
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
4444
<console type='pty'/>
45-
<sound model='es1370'/>
45+
<sound model='ich6'/>
4646
<video>
4747
<model type='cirrus'/>
4848
</video>

tests/xmlconfig-xml/rhel6-kvm-stage2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<input type='tablet' bus='usb'/>
4141
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
4242
<console type='pty'/>
43-
<sound model='es1370'/>
43+
<sound model='ich6'/>
4444
<video>
4545
<model type='cirrus'/>
4646
</video>

tests/xmlconfig-xml/winxp-kvm-stage1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<input type='tablet' bus='usb'/>
4242
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
4343
<console type='pty'/>
44-
<sound model='es1370'/>
44+
<sound model='ich6'/>
4545
<video>
4646
<model type='vga'/>
4747
</video>

tests/xmlconfig-xml/winxp-kvm-stage2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<input type='tablet' bus='usb'/>
4141
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
4242
<console type='pty'/>
43-
<sound model='es1370'/>
43+
<sound model='ich6'/>
4444
<video>
4545
<model type='vga'/>
4646
</video>

tests/xmlconfig-xml/winxp-kvm-stage3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<input type='tablet' bus='usb'/>
4141
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
4242
<console type='pty'/>
43-
<sound model='es1370'/>
43+
<sound model='ich6'/>
4444
<video>
4545
<model type='vga'/>
4646
</video>

0 commit comments

Comments
 (0)