~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to tests/image.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import unittest
18
18
import libvirt
19
19
import virtinst
 
20
import virtinst.cli
20
21
import virtinst.ImageParser
21
22
import os
22
23
 
23
 
import tests
 
24
import utils
24
25
import xmlconfig
25
26
 
 
27
qemuuri = "__virtinst_test__test:///default,caps=%s/tests/capabilities-xml/capabilities-kvm.xml,qemu,predictable" % os.getcwd()
 
28
 
26
29
class TestImageParser(unittest.TestCase):
27
30
 
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())
31
36
 
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)
60
65
 
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",
 
68
                              qemu=True)
 
69
 
 
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")
69
 
 
70
 
        # ( boot index from virt-image xml, filename to compare against)
71
 
        matrix = [ (0, "image-xenpv32.xml"),
72
 
                   (1, "image-xenfv32.xml") ]
73
 
 
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]
 
75
 
 
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"
 
79
 
 
80
        for idx in range(len(output_xmls)):
 
81
            fname = output_xmls[idx]
 
82
            inst = virtinst.ImageInstaller(image, caps, boot_index=idx,
 
83
                                           conn=conn)
76
84
 
77
85
            if inst.is_hvm():
78
 
                g = xmlconfig.get_basic_fullyvirt_guest()
 
86
                g = xmlconfig.get_basic_fullyvirt_guest(typ=gtype,
 
87
                                                        testconn=conn)
79
88
            else:
80
 
                g = xmlconfig.get_basic_paravirt_guest()
 
89
                g = xmlconfig.get_basic_paravirt_guest(testconn=conn)
81
90
 
82
91
            g.installer = inst
83
92
            g._prepare_install(None)
84
93
 
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),
 
96
 
 
97
            utils.diff_compare(g.get_config_xml(install=False),
88
98
                               image2guestdir + fname, expect_out=expect_out)
89
99
 
 
100
 
 
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"])
 
110
 
90
111
if __name__ == "__main__":
91
112
    unittest.main()