20
21
import virtinst.ImageParser
27
qemuuri = "__virtinst_test__test:///default,caps=%s/tests/capabilities-xml/capabilities-kvm.xml,qemu,predictable" % os.getcwd()
26
29
class TestImageParser(unittest.TestCase):
28
31
basedir = "tests/image-xml/"
29
32
conn = libvirt.open("test:///default")
33
qemuconn = virtinst.cli._open_test_uri(qemuuri)
30
34
caps = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
35
qemucaps = virtinst.CapabilitiesParser.parse(qemuconn.getCapabilities())
32
37
def testImageParsing(self):
33
38
f = open(os.path.join(self.basedir, "image.xml"), "r")
58
63
virtinst.ImageInstaller(image, self.caps, 0)
59
64
self.assertTrue(True)
61
# Build libvirt XML from the image xml
62
# XXX: This doesn't set up devices, so the guest xml will be pretty
63
# XXX: sparse. There should really be a helper in the Image classes
64
# XXX: that turns virt-image xml into a minimal Guest object, but
65
# XXX: maybe that's just falling into the realm of virt-convert
66
def testImage2XML(self):
66
def testStorageFormat(self):
67
self._image2XMLhelper("image-format.xml", "image-format-out.xml",
70
def _image2XMLhelper(self, image_xml, output_xmls, qemu=False):
67
71
image2guestdir = self.basedir + "image2guest/"
68
image = virtinst.ImageParser.parse_file(self.basedir + "image.xml")
70
# ( boot index from virt-image xml, filename to compare against)
71
matrix = [ (0, "image-xenpv32.xml"),
72
(1, "image-xenfv32.xml") ]
74
for idx, fname in matrix:
75
inst = virtinst.ImageInstaller(image, self.caps, boot_index=idx)
72
image = virtinst.ImageParser.parse_file(self.basedir + image_xml)
73
if type(output_xmls) is not list:
74
output_xmls = [output_xmls]
76
conn = qemu and self.qemuconn or self.conn
77
caps = qemu and self.qemucaps or self.caps
78
gtype = qemu and "qemu" or "xen"
80
for idx in range(len(output_xmls)):
81
fname = output_xmls[idx]
82
inst = virtinst.ImageInstaller(image, caps, boot_index=idx,
78
g = xmlconfig.get_basic_fullyvirt_guest()
86
g = xmlconfig.get_basic_fullyvirt_guest(typ=gtype,
80
g = xmlconfig.get_basic_paravirt_guest()
89
g = xmlconfig.get_basic_paravirt_guest(testconn=conn)
83
92
g._prepare_install(None)
85
expect_out = tests.read_file(image2guestdir + fname)
94
expect_out = utils.read_file(image2guestdir + fname)
86
95
expect_out = expect_out.replace("REPLACEME", os.getcwd())
87
tests.diff_compare(g.get_config_xml(install=True),
97
utils.diff_compare(g.get_config_xml(install=False),
88
98
image2guestdir + fname, expect_out=expect_out)
101
# Build libvirt XML from the image xml
102
# XXX: This doesn't set up devices, so the guest xml will be pretty
103
# XXX: sparse. There should really be a helper in the Image classes
104
# XXX: that turns virt-image xml into a minimal Guest object, but
105
# XXX: maybe that's just falling into the realm of virt-convert
106
def testImage2XML(self):
107
self._image2XMLhelper("image.xml", ["image-xenpv32.xml",
108
"image-xenfv32.xml"])
109
self._image2XMLhelper("image-kernel.xml", ["image-xenpv32-kernel.xml"])
90
111
if __name__ == "__main__":