|
19 | 19 | import logging |
20 | 20 |
|
21 | 21 | import libvirt |
| 22 | + |
| 23 | +import virtinst |
22 | 24 | import virtinst.cli |
| 25 | +from virtinst import VirtualAudio |
| 26 | +from virtinst import VirtualDisk |
| 27 | +from virtinst import VirtualVideoDevice |
23 | 28 |
|
24 | 29 | # Used to ensure consistent SDL xml output |
25 | 30 | os.environ["HOME"] = "/tmp" |
26 | 31 | os.environ["DISPLAY"] = ":3.4" |
27 | 32 |
|
28 | 33 | _cwd = os.getcwd() |
| 34 | +scratch = os.path.join(_cwd, "tests", "testscratchdir") |
29 | 35 | _testuri = "test:///%s/tests/testdriver.xml" % _cwd |
30 | 36 | _fakeuri = "__virtinst_test__" + _testuri + ",predictable" |
31 | 37 | _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) |
33 | 41 |
|
34 | 42 | def get_debug(): |
35 | 43 | return ("DEBUG_TESTS" in os.environ and |
36 | 44 | os.environ["DEBUG_TESTS"] == "1") |
37 | 45 |
|
| 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 | + |
38 | 53 | def open_testdriver(): |
39 | 54 | return virtinst.cli.getConnection(_testuri) |
40 | | - |
41 | 55 | def open_testkvmdriver(): |
42 | 56 | 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() |
43 | 72 |
|
44 | 73 | # Register libvirt handler |
45 | 74 | def libvirt_callback(ignore, err): |
@@ -105,3 +134,89 @@ def diff_compare(actual_out, filename=None, expect_out=None): |
105 | 134 | tofile="Generated Output")) |
106 | 135 | if diff: |
107 | 136 | 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 | + |
0 commit comments