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

« back to all changes in this revision

Viewing changes to tests/xmlconfig.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:
28
28
from virtinst import VirtualVideoDevice
29
29
from virtinst import VirtualController
30
30
from virtinst import VirtualWatchdog
31
 
import tests
32
 
 
33
 
conn = tests.open_testdriver()
34
 
 
35
 
def get_basic_paravirt_guest():
36
 
    g = virtinst.ParaVirtGuest(connection=conn, type="xen")
 
31
from virtinst import VirtualInputDevice
 
32
import utils
 
33
 
 
34
conn = utils.open_testdriver()
 
35
scratch = os.path.join(os.getcwd(), "tests", "testscratchdir")
 
36
 
 
37
def get_basic_paravirt_guest(testconn=conn, installer=None):
 
38
    g = virtinst.ParaVirtGuest(connection=testconn, type="xen")
37
39
    g.name = "TestGuest"
38
40
    g.memory = int(200)
39
41
    g.maxmemory = int(400)
40
42
    g.uuid = "12345678-1234-1234-1234-123456789012"
41
 
    g.boot = ["/boot/vmlinuz","/boot/initrd"]
 
43
    g.boot = ["/boot/vmlinuz", "/boot/initrd"]
42
44
    g.graphics = (True, "vnc", None, "ja")
43
45
    g.vcpus = 5
 
46
 
 
47
    if installer:
 
48
        g.installer = installer
 
49
 
 
50
    g.installer._scratchdir = scratch
44
51
    return g
45
52
 
46
 
def get_basic_fullyvirt_guest(typ="xen"):
47
 
    g = virtinst.FullVirtGuest(connection=conn, type=typ,
 
53
def get_basic_fullyvirt_guest(typ="xen", testconn=conn, installer=None):
 
54
    g = virtinst.FullVirtGuest(connection=testconn, type=typ,
48
55
                               emulator="/usr/lib/xen/bin/qemu-dm",
49
56
                               arch="i686")
50
57
    g.name = "TestGuest"
52
59
    g.maxmemory = int(400)
53
60
    g.uuid = "12345678-1234-1234-1234-123456789012"
54
61
    g.cdrom = "/dev/loop0"
55
 
    g.set_os_type("other")
56
 
    g.set_os_variant("generic")
57
62
    g.graphics = (True, "sdl")
58
63
    g.features['pae'] = 0
59
64
    g.vcpus = 5
60
 
    return g
61
 
 
62
 
def get_floppy(path="/default-pool/testvol1.img"):
 
65
    if installer:
 
66
        g.installer = installer
 
67
 
 
68
    g.installer._scratchdir = scratch
 
69
    return g
 
70
 
 
71
def make_import_installer(os_type="hvm"):
 
72
    inst = virtinst.ImportInstaller(type="xen", os_type=os_type, conn=conn)
 
73
    return inst
 
74
 
 
75
def make_distro_installer(location="/default-pool/default-vol", gtype="xen"):
 
76
    inst = virtinst.DistroInstaller(type=gtype, os_type="hvm", conn=conn,
 
77
                                    location=location)
 
78
    return inst
 
79
 
 
80
def make_live_installer(location="/dev/loop0", gtype="xen"):
 
81
    inst = virtinst.LiveCDInstaller(type=gtype, os_type="hvm",
 
82
                                    conn=conn, location=location)
 
83
    return inst
 
84
 
 
85
def make_pxe_installer(gtype="xen"):
 
86
    inst = virtinst.PXEInstaller(type=gtype, os_type="hvm", conn=conn)
 
87
    return inst
 
88
 
 
89
def build_win_kvm(path=None):
 
90
    g = get_basic_fullyvirt_guest("kvm")
 
91
    g.os_type = "windows"
 
92
    g.os_variant = "winxp"
 
93
    g.disks.append(get_filedisk(path))
 
94
    g.disks.append(get_blkdisk())
 
95
    g.nics.append(get_virtual_network())
 
96
    g.add_device(VirtualAudio())
 
97
    g.add_device(VirtualVideoDevice(g.conn))
 
98
 
 
99
    return g
 
100
 
 
101
def get_floppy(path=None):
 
102
    if not path:
 
103
        path = "/default-pool/testvol1.img"
63
104
    return VirtualDisk(path, conn=conn, device=VirtualDisk.DEVICE_FLOPPY)
64
105
 
65
 
def get_filedisk(path="/tmp/test.img"):
 
106
def get_filedisk(path=None):
 
107
    if not path:
 
108
        path = "/tmp/test.img"
66
109
    return VirtualDisk(path, size=.0001, conn=conn)
67
110
 
68
 
def get_blkdisk():
69
 
    return VirtualDisk("/dev/loop0", conn=conn)
 
111
def get_blkdisk(path="/dev/loop0"):
 
112
    return VirtualDisk(path, conn=conn)
70
113
 
71
114
def get_virtual_network():
72
115
    dev = virtinst.VirtualNetworkInterface()
81
124
def xen_uri():
82
125
    return "xen:///"
83
126
 
 
127
def build_xmlfile(filebase):
 
128
    if not filebase:
 
129
        return None
 
130
    return os.path.join("tests/xmlconfig-xml", filebase + ".xml")
 
131
 
84
132
class TestXMLConfig(unittest.TestCase):
85
133
 
86
 
    def _compare(self, xenguest, filebase, do_install, do_disk_boot=False):
87
 
        filename = os.path.join("tests/xmlconfig-xml", filebase + ".xml")
88
 
        xenguest._prepare_install(progress.BaseMeter())
89
 
        try:
90
 
            actualXML = xenguest.get_config_xml(install=do_install,
91
 
                                                disk_boot=do_disk_boot)
92
 
            tests.diff_compare(actualXML, filename)
93
 
            # Libvirt throws errors since we are defining domain
94
 
            # type='xen', when test driver can only handle type='test'
95
 
            # Sanitize the XML so we can define
96
 
            actualXML = actualXML.replace("<domain type='xen'>",
97
 
                                          "<domain type='test'>")
98
 
            actualXML = actualXML.replace(">linux<", ">xen<")
99
 
 
100
 
            # Should probably break this out into a separate function
101
 
            dom = xenguest.conn.defineXML(actualXML)
102
 
            dom.create()
 
134
    def tearDown(self):
 
135
        if os.path.exists(scratch):
 
136
            os.rmdir(scratch)
 
137
 
 
138
    def _compare(self, guest, filebase, do_install, do_disk_boot=False):
 
139
        filename = build_xmlfile(filebase)
 
140
 
 
141
        guest._prepare_install(progress.BaseMeter())
 
142
        try:
 
143
            actualXML = guest.get_config_xml(install=do_install,
 
144
                                             disk_boot=do_disk_boot)
 
145
 
 
146
            utils.diff_compare(actualXML, filename)
 
147
            utils.test_create(guest.conn, actualXML)
 
148
        finally:
 
149
            guest._cleanup_install()
 
150
 
 
151
    def _testInstall(self, guest,
 
152
                     instxml=None, bootxml=None, contxml=None):
 
153
        instname = build_xmlfile(instxml)
 
154
        bootname = build_xmlfile(bootxml)
 
155
        contname = build_xmlfile(contxml)
 
156
        consolecb = None
 
157
        meter = None
 
158
        removeOld = None
 
159
        wait = True
 
160
        dom = None
 
161
 
 
162
        old_getxml = guest.get_config_xml
 
163
        def new_getxml(install=True, disk_boot=False):
 
164
            xml = old_getxml(install, disk_boot)
 
165
            return utils.sanitize_xml_for_define(xml)
 
166
        guest.get_config_xml = new_getxml
 
167
 
 
168
        try:
 
169
            dom = guest.start_install(consolecb, meter, removeOld, wait)
103
170
            dom.destroy()
104
 
            dom.undefine()
 
171
 
 
172
            # Replace kernel/initrd with known info
 
173
            if (guest.installer._install_bootconfig and
 
174
                guest.installer._install_bootconfig.kernel):
 
175
                guest.installer._install_bootconfig.kernel = "kernel"
 
176
                guest.installer._install_bootconfig.initrd = "initrd"
 
177
 
 
178
            xmlinst = guest.get_config_xml(True, False)
 
179
            xmlboot = guest.get_config_xml(False, False)
 
180
            xmlcont = guest.get_config_xml(True, True)
 
181
 
 
182
            if instname:
 
183
                utils.diff_compare(xmlinst, instname)
 
184
            if contname:
 
185
                utils.diff_compare(xmlcont, contname)
 
186
            if bootname:
 
187
                utils.diff_compare(xmlboot, bootname)
 
188
 
 
189
            if guest.get_continue_inst():
 
190
                guest.continue_install(consolecb, meter, wait)
 
191
 
105
192
        finally:
106
 
            xenguest._cleanup_install()
107
 
 
108
 
    def conn_function_wrappers(self, guest, filename, do_boot,
 
193
            if dom:
 
194
                try:
 
195
                    dom.destroy()
 
196
                except:
 
197
                    pass
 
198
                try:
 
199
                    dom.undefine()
 
200
                except:
 
201
                    pass
 
202
 
 
203
 
 
204
    def conn_function_wrappers(self, guest, funcargs,
 
205
                               func=None,
109
206
                               conn_version=None,
110
207
                               conn_uri=None,
111
 
                               libvirt_version=None,
112
 
                               do_disk_boot=False):
113
 
        testconn = guest.conn
 
208
                               libvirt_version=None):
 
209
        testconn = guest
 
210
        if isinstance(guest, virtinst.Guest):
 
211
            testconn = guest.conn
114
212
 
115
213
        def set_func(newfunc, funcname, obj, force=False):
116
214
            if newfunc or force:
137
235
            old_version = set_version(conn_version)
138
236
            old_uri = set_uri(conn_uri)
139
237
            old_libvirt_version = set_libvirt_version(libvirt_version)
140
 
            self._compare(guest, filename, do_boot, do_disk_boot)
 
238
 
 
239
            if not func:
 
240
                func = self._compare
 
241
            func(*funcargs)
141
242
        finally:
142
243
            set_version(*old_version)
143
244
            set_uri(*old_uri)
145
246
 
146
247
    def testBootParavirtDiskFile(self):
147
248
        g = get_basic_paravirt_guest()
148
 
        g.disks.append(get_filedisk())
 
249
        g.disks.append(get_filedisk("/tmp/somerandomfilename.img"))
149
250
        self._compare(g, "boot-paravirt-disk-file", False)
150
251
 
 
252
        # Just cram some post_install_checks in here
 
253
        try:
 
254
            g.post_install_check()
 
255
            raise AssertionError("Expected OSError, none caught.")
 
256
        except OSError:
 
257
            pass
 
258
 
 
259
        g.disks[0].path = "virt-install"
 
260
        self.assertEquals(g.post_install_check(), False)
 
261
 
 
262
        g.disks[0].driver_type = "raw"
 
263
        self.assertEquals(g.post_install_check(), False)
 
264
 
 
265
        g.disks[0].driver_type = "foobar"
 
266
        self.assertEquals(g.post_install_check(), True)
 
267
 
151
268
    def testBootParavirtDiskFileBlktapCapable(self):
152
269
        oldblktap = virtinst._util.is_blktap_capable
153
270
        try:
215
332
 
216
333
 
217
334
 
218
 
 
219
335
    def testInstallParavirtDiskFile(self):
220
336
        g = get_basic_paravirt_guest()
221
337
        g.disks.append(get_filedisk())
277
393
        self._compare(g, "install-fullyvirt-disk-block", True)
278
394
 
279
395
    def testInstallFVPXE(self):
280
 
        g = get_basic_fullyvirt_guest()
281
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
282
 
                                            conn=g.conn)
 
396
        i = make_pxe_installer()
 
397
        g = get_basic_fullyvirt_guest(installer=i)
283
398
        g.disks.append(get_filedisk())
284
399
        self._compare(g, "install-fullyvirt-pxe", True)
285
400
 
286
401
    def testBootFVPXE(self):
287
 
        g = get_basic_fullyvirt_guest()
288
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
289
 
                                            conn=g.conn)
 
402
        i = make_pxe_installer()
 
403
        g = get_basic_fullyvirt_guest(installer=i)
290
404
        g.disks.append(get_filedisk())
291
405
        self._compare(g, "boot-fullyvirt-pxe", False)
292
406
 
 
407
    def testBootFVPXEAlways(self):
 
408
        i = make_pxe_installer()
 
409
        g = get_basic_fullyvirt_guest(installer=i)
 
410
        g.disks.append(get_filedisk())
 
411
 
 
412
        g.installer.bootconfig.bootorder = [
 
413
            g.installer.bootconfig.BOOT_DEVICE_NETWORK]
 
414
        g.installer.bootconfig.enable_bootmenu = True
 
415
        g.seclabel.model = "default"
 
416
 
 
417
        self._compare(g, "boot-fullyvirt-pxe-always", False)
 
418
 
293
419
    def testInstallFVPXENoDisks(self):
294
 
        g = get_basic_fullyvirt_guest()
295
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
296
 
                                            conn=g.conn)
 
420
        i = make_pxe_installer()
 
421
        g = get_basic_fullyvirt_guest(installer=i)
297
422
        self._compare(g, "install-fullyvirt-pxe-nodisks", True)
298
423
 
299
424
    def testBootFVPXENoDisks(self):
300
 
        g = get_basic_fullyvirt_guest()
301
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
302
 
                                            conn=g.conn)
 
425
        i = make_pxe_installer()
 
426
        g = get_basic_fullyvirt_guest(installer=i)
303
427
        self._compare(g, "boot-fullyvirt-pxe-nodisks", False)
304
428
 
305
429
    def testInstallFVLiveCD(self):
306
 
        g = get_basic_fullyvirt_guest()
307
 
        g.installer = virtinst.LiveCDInstaller(type="xen", os_type="hvm",
308
 
                                               conn=g.conn,
309
 
                                               location="/dev/loop0")
 
430
        i = make_live_installer()
 
431
        g = get_basic_fullyvirt_guest(installer=i)
310
432
        self._compare(g, "install-fullyvirt-livecd", False)
311
433
 
312
434
    def testDoubleInstall(self):
313
435
        # Make sure that installing twice generates the same XML, to ensure
314
436
        # we aren't polluting the device list during the install process
 
437
        i = make_live_installer()
 
438
        g = get_basic_fullyvirt_guest(installer=i)
 
439
        self._compare(g, "install-fullyvirt-livecd", False)
 
440
        self._compare(g, "install-fullyvirt-livecd", False)
 
441
 
 
442
    def testDefaultDeviceRemoval(self):
315
443
        g = get_basic_fullyvirt_guest()
316
 
        g.installer = virtinst.LiveCDInstaller(type="xen", os_type="hvm",
317
 
                                               conn=g.conn,
318
 
                                               location="/dev/loop0")
319
 
        self._compare(g, "install-fullyvirt-livecd", False)
320
 
        self._compare(g, "install-fullyvirt-livecd", False)
321
 
 
 
444
        g.disks.append(get_filedisk())
 
445
 
 
446
        inp = VirtualInputDevice(g.conn)
 
447
        cons = VirtualCharDevice.get_dev_instance(conn,
 
448
                                VirtualCharDevice.DEV_CONSOLE,
 
449
                                VirtualCharDevice.CHAR_PTY)
 
450
        g.add_device(inp)
 
451
        g.add_device(cons)
 
452
 
 
453
        g.remove_device(inp)
 
454
        g.remove_device(cons)
 
455
 
 
456
        self._compare(g, "boot-default-device-removal", False)
 
457
 
 
458
    def testOSDeviceDefaultChange(self):
 
459
        """
 
460
        Make sure device defaults are properly changed if we change OS
 
461
        distro/variant mid process
 
462
        """
 
463
        i = make_distro_installer(gtype="kvm")
 
464
        g = get_basic_fullyvirt_guest("kvm", installer=i)
 
465
 
 
466
        do_install = False
 
467
        g.installer.cdrom = True
 
468
        g.disks.append(get_floppy())
 
469
        g.disks.append(get_filedisk())
 
470
        g.disks.append(get_blkdisk())
 
471
        g.nics.append(get_virtual_network())
 
472
 
 
473
        # Call get_config_xml to set first round of defaults without an
 
474
        # os_variant set
 
475
        fargs = (do_install,)
 
476
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri,
 
477
                                    func=g.get_config_xml)
 
478
 
 
479
        g.os_variant = "fedora11"
 
480
        fargs = (g, "install-f11", do_install)
 
481
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
322
482
 
323
483
    def testInstallFVImport(self):
324
 
        g = get_basic_fullyvirt_guest()
 
484
        i = make_import_installer()
 
485
        g = get_basic_fullyvirt_guest(installer=i)
 
486
 
325
487
        g.disks.append(get_filedisk())
326
 
        g.installer = virtinst.ImportInstaller(type="xen", os_type="hvm",
327
 
                                               conn=g.conn)
328
488
        self._compare(g, "install-fullyvirt-import", False)
329
489
 
 
490
    def testInstallFVImportKernel(self):
 
491
        i = make_import_installer()
 
492
        g = get_basic_fullyvirt_guest(installer=i)
 
493
 
 
494
        g.disks.append(get_filedisk())
 
495
        g.installer.bootconfig.kernel = "kernel"
 
496
        g.installer.bootconfig.initrd = "initrd"
 
497
        g.installer.bootconfig.kernel_args = "my kernel args"
 
498
 
 
499
        self._compare(g, "install-fullyvirt-import-kernel", False)
 
500
 
 
501
    def testInstallFVImportMulti(self):
 
502
        i = make_import_installer()
 
503
        g = get_basic_fullyvirt_guest(installer=i)
 
504
 
 
505
        g.installer.bootconfig.enable_bootmenu = False
 
506
        g.installer.bootconfig.bootorder = ["hd", "fd", "cdrom", "network"]
 
507
        g.disks.append(get_filedisk())
 
508
        self._compare(g, "install-fullyvirt-import-multiboot", False)
 
509
 
330
510
    def testInstallPVImport(self):
331
 
        g = get_basic_paravirt_guest()
 
511
        i = make_import_installer("xen")
 
512
        g = get_basic_paravirt_guest(installer=i)
 
513
 
332
514
        g.disks.append(get_filedisk())
333
 
        g.installer = virtinst.ImportInstaller(type="xen", os_type="xen",
334
 
                                               conn=g.conn)
335
515
        self._compare(g, "install-paravirt-import", False)
336
516
 
337
517
    def testQEMUDriverName(self):
338
518
        g = get_basic_fullyvirt_guest()
339
519
        g.disks.append(get_blkdisk())
340
 
        self.conn_function_wrappers(g, "misc-qemu-driver-name", True,
341
 
                                    conn_uri=qemu_uri)
 
520
        fargs = (g, "misc-qemu-driver-name", True)
 
521
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
342
522
 
343
523
        g = get_basic_fullyvirt_guest()
344
524
        g.disks.append(get_filedisk())
345
 
        self.conn_function_wrappers(g, "misc-qemu-driver-type", True,
346
 
                                    conn_uri=qemu_uri)
 
525
        g.disks.append(get_blkdisk("/iscsi-pool/diskvol1"))
 
526
        fargs = (g, "misc-qemu-driver-type", True)
 
527
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
347
528
 
348
529
        g = get_basic_fullyvirt_guest()
349
530
        g.disks.append(get_filedisk("/default-pool/iso-vol"))
350
 
        self.conn_function_wrappers(g, "misc-qemu-iso-disk", True,
351
 
                                    conn_uri=qemu_uri)
 
531
        fargs = (g, "misc-qemu-iso-disk", True)
 
532
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
352
533
 
353
534
        g = get_basic_fullyvirt_guest()
354
535
        g.disks.append(get_filedisk("/default-pool/iso-vol"))
355
536
        g.disks[0].driver_type = "qcow2"
356
 
        self.conn_function_wrappers(g, "misc-qemu-driver-overwrite", True,
357
 
                                    conn_uri=qemu_uri)
 
537
        fargs = (g, "misc-qemu-driver-overwrite", True)
 
538
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
358
539
 
359
540
    def testXMLEscaping(self):
360
541
        g = get_basic_fullyvirt_guest()
 
542
        g.description = "foooo barrrr \n baz && snarf. '' \"\" @@$\n"
361
543
        g.disks.append(get_filedisk("/tmp/ISO&'&s"))
362
544
        self._compare(g, "misc-xml-escaping", True)
363
545
 
364
546
    # OS Type/Version configurations
365
547
    def testF10(self):
366
 
        g = get_basic_fullyvirt_guest("kvm")
 
548
        i = make_pxe_installer(gtype="kvm")
 
549
        g = get_basic_fullyvirt_guest("kvm", installer=i)
 
550
 
367
551
        g.os_type = "linux"
368
552
        g.os_variant = "fedora10"
369
 
        g.installer = virtinst.PXEInstaller(type="kvm", os_type="hvm",
370
 
                                            conn=g.conn)
371
553
        g.disks.append(get_filedisk())
372
554
        g.disks.append(get_blkdisk())
373
555
        g.nics.append(get_virtual_network())
374
 
        self.conn_function_wrappers(g, "install-f10", True,
375
 
                                    conn_uri=qemu_uri)
 
556
        fargs = (g, "install-f10", True)
 
557
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
376
558
 
377
559
    def testF11(self):
378
 
        g = get_basic_fullyvirt_guest("kvm")
 
560
        i = make_distro_installer(gtype="kvm")
 
561
        g = get_basic_fullyvirt_guest("kvm", installer=i)
 
562
 
379
563
        g.os_type = "linux"
380
564
        g.os_variant = "fedora11"
381
 
        g.installer = virtinst.DistroInstaller(type="kvm", os_type="hvm",
382
 
                                               conn=g.conn,
383
 
                                               location="/default-pool/default-vol")
384
565
        g.installer.cdrom = True
385
566
        g.disks.append(get_floppy())
386
567
        g.disks.append(get_filedisk())
387
568
        g.disks.append(get_blkdisk())
388
569
        g.nics.append(get_virtual_network())
389
 
        self.conn_function_wrappers(g, "install-f11", False,
390
 
                                    conn_uri=qemu_uri)
 
570
        fargs = (g, "install-f11", False)
 
571
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
391
572
 
392
573
    def testF11AC97(self):
393
574
        def build_guest():
394
 
            g = get_basic_fullyvirt_guest("kvm")
 
575
            i = make_distro_installer(gtype="kvm")
 
576
            g = get_basic_fullyvirt_guest("kvm", installer=i)
 
577
 
395
578
            g.os_type = "linux"
396
579
            g.os_variant = "fedora11"
397
 
            g.installer = virtinst.DistroInstaller(type="kvm", os_type="hvm",
398
 
                            conn=g.conn, location="/default-pool/default-vol")
399
580
            g.installer.cdrom = True
400
581
            g.disks.append(get_floppy())
401
582
            g.disks.append(get_filedisk())
417
598
            return 11000
418
599
 
419
600
        g = build_guest()
420
 
        self.conn_function_wrappers(g, "install-f11-ac97", False,
 
601
        fargs = (g, "install-f11-ac97", False)
 
602
        self.conn_function_wrappers(g, fargs,
421
603
                                    conn_uri=qemu_uri,
422
604
                                    conn_version=conn_support_ac97)
423
605
 
424
606
        g = build_guest()
425
 
        self.conn_function_wrappers(g, "install-f11-noac97", False,
 
607
        fargs = (g, "install-f11-noac97", False)
 
608
        self.conn_function_wrappers(g, fargs,
426
609
                                    libvirt_version=libvirt_nosupport_ac97,
427
610
                                    conn_uri=qemu_uri)
428
611
 
429
612
        g = build_guest()
430
 
        self.conn_function_wrappers(g, "install-f11-noac97", False,
 
613
        fargs = (g, "install-f11-noac97", False)
 
614
        self.conn_function_wrappers(g, fargs,
431
615
                                    conn_version=conn_nosupport_ac97,
432
616
                                    conn_uri=qemu_uri)
433
617
 
 
618
    def testKVMKeymap(self):
 
619
        def conn_nosupport_autokeymap():
 
620
            return 10000
 
621
        def conn_support_autokeymap():
 
622
            return 11000
 
623
 
 
624
        def test1():
 
625
            g = virtinst.VirtualGraphics(conn=conn, type="vnc")
 
626
            self.assertTrue(g.keymap != None)
 
627
        self.conn_function_wrappers(conn, (), func=test1,
 
628
                                    conn_uri=qemu_uri,
 
629
                                    conn_version=conn_nosupport_autokeymap)
 
630
 
 
631
        def test2():
 
632
            g = virtinst.VirtualGraphics(conn=conn, type="vnc")
 
633
            self.assertTrue(g.keymap == None)
 
634
        self.conn_function_wrappers(conn, (), func=test2,
 
635
                                    conn_uri=qemu_uri,
 
636
                                    conn_version=conn_support_autokeymap)
 
637
 
434
638
 
435
639
    def testF11Qemu(self):
436
 
        g = get_basic_fullyvirt_guest("qemu")
 
640
        i = make_distro_installer(gtype="qemu")
 
641
        g = get_basic_fullyvirt_guest("qemu", installer=i)
 
642
 
437
643
        g.os_type = "linux"
438
644
        g.os_variant = "fedora11"
439
 
        g.installer = virtinst.DistroInstaller(type="qemu", os_type="hvm",
440
 
                                               conn=g.conn,
441
 
                                               location="/default-pool/default-vol")
442
645
        g.installer.cdrom = True
443
646
        g.disks.append(get_floppy())
444
647
        g.disks.append(get_filedisk())
445
648
        g.disks.append(get_blkdisk())
446
649
        g.nics.append(get_virtual_network())
447
 
        self.conn_function_wrappers(g, "install-f11-qemu", False,
448
 
                                    conn_uri=qemu_uri)
 
650
        fargs = (g, "install-f11-qemu", False)
 
651
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
449
652
 
450
653
    def testF11Xen(self):
451
 
        g = get_basic_fullyvirt_guest("xen")
 
654
        i = make_distro_installer(gtype="xen")
 
655
        g = get_basic_fullyvirt_guest("xen", installer=i)
 
656
 
452
657
        g.os_type = "linux"
453
658
        g.os_variant = "fedora11"
454
 
        g.installer = virtinst.DistroInstaller(type="xen", os_type="hvm",
455
 
                                               conn=g.conn,
456
 
                                               location="/default-pool/default-vol")
457
659
        g.installer.cdrom = True
458
660
        g.disks.append(get_floppy())
459
661
        g.disks.append(get_filedisk())
460
662
        g.disks.append(get_blkdisk())
461
663
        g.nics.append(get_virtual_network())
462
 
        self.conn_function_wrappers(g, "install-f11-xen", False,
463
 
                                    conn_uri=xen_uri)
464
 
 
465
 
    def _build_win_kvm(self):
466
 
        g = get_basic_fullyvirt_guest("kvm")
467
 
        g.os_type = "windows"
468
 
        g.os_variant = "winxp"
469
 
        g.disks.append(get_filedisk())
470
 
        g.disks.append(get_blkdisk())
471
 
        g.nics.append(get_virtual_network())
472
 
        g.add_device(VirtualAudio())
473
 
        g.add_device(VirtualVideoDevice(g.conn))
474
 
 
475
 
        return g
 
664
        fargs = (g, "install-f11-xen", False)
 
665
        self.conn_function_wrappers(g, fargs, conn_uri=xen_uri)
476
666
 
477
667
    def testInstallWindowsKVM(self):
478
 
        g = self._build_win_kvm()
479
 
        self.conn_function_wrappers(g, "winxp-kvm-stage1", True,
480
 
                                    conn_uri=qemu_uri)
 
668
        g = build_win_kvm("/default-pool/winxp.img")
 
669
        fargs = (g, "winxp-kvm-stage1", True)
 
670
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
481
671
 
482
672
    def testContinueWindowsKVM(self):
483
 
        g = self._build_win_kvm()
484
 
        self.conn_function_wrappers(g, "winxp-kvm-stage2", True,
485
 
                                    conn_uri=qemu_uri,
486
 
                                    do_disk_boot=True)
 
673
        g = build_win_kvm("/default-pool/winxp.img")
 
674
        fargs = (g, "winxp-kvm-stage2", True, True)
 
675
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
487
676
 
488
677
    def testBootWindowsKVM(self):
489
 
        g = self._build_win_kvm()
490
 
        self.conn_function_wrappers(g, "winxp-kvm-stage3", False,
491
 
                                    conn_uri=qemu_uri)
 
678
        g = build_win_kvm("/default-pool/winxp.img")
 
679
        fargs = (g, "winxp-kvm-stage3", False)
 
680
        self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
492
681
 
493
682
 
494
683
    def testInstallWindowsXenNew(self):
510
699
        for f, xml in [(old_xen_ver, "install-windowsxp-xenold"),
511
700
                       (new_xen_ver, "install-windowsxp-xennew")]:
512
701
 
513
 
            self.conn_function_wrappers(g, xml, True,
514
 
                                        conn_version=f,
515
 
                                        conn_uri=xen_uri)
 
702
            fargs = (g, xml, True)
 
703
            self.conn_function_wrappers(g, fargs,
 
704
                                        conn_version=f, conn_uri=xen_uri)
516
705
 
517
706
 
518
707
    # Device heavy configurations
519
708
    def testManyDisks2(self):
520
 
        g = get_basic_fullyvirt_guest()
 
709
        i = make_pxe_installer()
 
710
        g = get_basic_fullyvirt_guest(installer=i)
 
711
 
521
712
        g.disks.append(get_filedisk())
522
713
        g.disks.append(get_blkdisk())
523
714
        g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
524
 
                                   device=VirtualDisk.DEVICE_CDROM))
 
715
                                   device=VirtualDisk.DEVICE_CDROM,
 
716
                                   driverType="raw"))
 
717
        g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
 
718
                                   device=VirtualDisk.DEVICE_DISK,
 
719
                                   driverName="qemu", format="qcow2"))
525
720
        g.disks.append(VirtualDisk(conn=g.conn, path=None,
526
721
                                   device=VirtualDisk.DEVICE_CDROM,
527
722
                                   bus="scsi"))
528
723
        g.disks.append(VirtualDisk(conn=g.conn, path=None,
529
724
                                   device=VirtualDisk.DEVICE_FLOPPY))
530
725
        g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
531
 
                                   device=VirtualDisk.DEVICE_FLOPPY))
 
726
                                   device=VirtualDisk.DEVICE_FLOPPY,
 
727
                                   driverName="phy", driverCache="none"))
532
728
        g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
533
 
                                   bus="virtio"))
 
729
                                   bus="virtio", driverName="qemu",
 
730
                                   driverType="qcow2", driverCache="none"))
534
731
 
535
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
536
 
                                            conn=g.conn)
537
732
        self._compare(g, "boot-many-disks2", False)
538
733
 
539
734
    def testManyNICs(self):
540
 
        g = get_basic_fullyvirt_guest()
 
735
        i = make_pxe_installer()
 
736
        g = get_basic_fullyvirt_guest(installer=i)
 
737
 
541
738
        net1 = VirtualNetworkInterface(type="user",
542
739
                                       macaddr="11:11:11:11:11:11")
543
740
        net2 = get_virtual_network()
545
742
        net3.model = "e1000"
546
743
        net4 = VirtualNetworkInterface(bridge="foobr0",
547
744
                                       macaddr="22:22:22:22:22:22")
 
745
        net4.target_dev = "foo1"
 
746
        net5 = VirtualNetworkInterface(type="ethernet",
 
747
                                       macaddr="00:11:00:22:00:33")
 
748
        net5.source_dev = "testeth1"
548
749
 
549
750
        g.nics.append(net1)
550
751
        g.nics.append(net2)
551
752
        g.nics.append(net3)
552
753
        g.nics.append(net4)
553
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
554
 
                                            conn=g.conn)
 
754
        g.nics.append(net5)
555
755
        self._compare(g, "boot-many-nics", False)
556
756
 
557
757
    def testManyHostdevs(self):
558
 
        g = get_basic_fullyvirt_guest()
 
758
        i = make_pxe_installer()
 
759
        g = get_basic_fullyvirt_guest(installer=i)
 
760
 
559
761
        dev1 = VirtualHostDeviceUSB(g.conn)
560
762
        dev1.product = "0x1234"
561
763
        dev1.vendor = "0x4321"
567
769
 
568
770
        g.hostdevs.append(dev1)
569
771
        g.hostdevs.append(dev2)
570
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
571
 
                                            conn=g.conn)
572
772
        self._compare(g, "boot-many-hostdevs", False)
573
773
 
574
774
    def testManySounds(self):
575
 
        g = get_basic_fullyvirt_guest()
 
775
        i = make_pxe_installer()
 
776
        g = get_basic_fullyvirt_guest(installer=i)
 
777
 
576
778
        g.sound_devs.append(VirtualAudio("sb16", conn=g.conn))
577
779
        g.sound_devs.append(VirtualAudio("es1370", conn=g.conn))
578
780
        g.sound_devs.append(VirtualAudio("pcspk", conn=g.conn))
579
781
        g.sound_devs.append(VirtualAudio(conn=g.conn))
580
782
 
581
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
582
 
                                            conn=g.conn)
583
783
        self._compare(g, "boot-many-sounds", False)
584
784
 
585
785
    def testManyChars(self):
586
 
        g = get_basic_fullyvirt_guest()
 
786
        i = make_pxe_installer()
 
787
        g = get_basic_fullyvirt_guest(installer=i)
 
788
 
587
789
        dev1 = VirtualCharDevice.get_dev_instance(g.conn,
588
790
                                                  VirtualCharDevice.DEV_SERIAL,
589
791
                                                  VirtualCharDevice.CHAR_NULL)
605
807
        dev4.source_host = "my.source.host"
606
808
        dev4.source_port = "2222"
607
809
 
 
810
        dev5 = VirtualCharDevice.get_dev_instance(g.conn,
 
811
                                                  VirtualCharDevice.DEV_CHANNEL,
 
812
                                                  VirtualCharDevice.CHAR_PTY)
 
813
        dev5.target_type = dev5.CHAR_CHANNEL_TARGET_VIRTIO
 
814
        dev5.target_name = "foo.bar.frob"
 
815
 
 
816
        dev6 = VirtualCharDevice.get_dev_instance(g.conn,
 
817
                                                  VirtualCharDevice.DEV_CONSOLE,
 
818
                                                  VirtualCharDevice.CHAR_PTY)
 
819
        dev6.target_type = dev5.CHAR_CONSOLE_TARGET_VIRTIO
 
820
 
 
821
        dev7 = VirtualCharDevice.get_dev_instance(g.conn,
 
822
                                                  VirtualCharDevice.DEV_CONSOLE,
 
823
                                                  VirtualCharDevice.CHAR_PTY)
 
824
 
 
825
        dev8 = VirtualCharDevice.get_dev_instance(g.conn,
 
826
                                                  VirtualCharDevice.DEV_CHANNEL,
 
827
                                                  VirtualCharDevice.CHAR_PTY)
 
828
        dev8.target_type = dev5.CHAR_CHANNEL_TARGET_GUESTFWD
 
829
        dev8.target_address = "1.2.3.4"
 
830
        dev8.target_port = "4567"
 
831
 
608
832
        g.add_device(dev1)
609
833
        g.add_device(dev2)
610
834
        g.add_device(dev3)
611
835
        g.add_device(dev4)
612
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
613
 
                                            conn=g.conn)
 
836
        g.add_device(dev5)
 
837
        g.add_device(dev6)
 
838
        g.add_device(dev7)
 
839
        g.add_device(dev8)
614
840
        self._compare(g, "boot-many-chars", False)
615
841
 
616
842
    def testManyDevices(self):
617
 
        g = get_basic_fullyvirt_guest()
618
 
        g.description = "foooo barrrr \n baz && snarf. '' \"\" @@$\n"
 
843
        i = make_pxe_installer()
 
844
        g = get_basic_fullyvirt_guest(installer=i)
 
845
 
 
846
        g.description = "foooo barrrr somedesc"
619
847
 
620
848
        # Hostdevs
621
849
        dev1 = VirtualHostDeviceUSB(g.conn)
675
903
        vdev2.heads = 3
676
904
 
677
905
        vdev3 = VirtualVideoDevice(g.conn)
 
906
        vdev4 = VirtualVideoDevice(g.conn)
 
907
        vdev4.model_type = "qxl"
 
908
 
678
909
        g.add_device(vdev1)
679
910
        g.add_device(vdev2)
680
911
        g.add_device(vdev3)
 
912
        g.add_device(vdev4)
681
913
 
682
914
        wdev2 = VirtualWatchdog(g.conn)
683
915
        wdev2.model = "ib700"
684
916
        wdev2.action = "none"
685
917
        g.add_device(wdev2)
686
918
 
 
919
        # Check keymap autoconfig
 
920
        gdev1 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
 
921
        self.assertTrue(gdev1.keymap != None)
 
922
        gdev1.keymap = "en-us"
 
923
 
 
924
        # Check keymap None
 
925
        gdev2 = virtinst.VirtualGraphics(conn=g.conn, type="vnc")
 
926
        gdev2.keymap = None
 
927
 
 
928
        gdev3 = virtinst.VirtualGraphics(conn=g.conn, type="sdl")
 
929
        gdev4 = virtinst.VirtualGraphics(conn=g.conn, type="spice")
 
930
 
 
931
        gdev5 = virtinst.VirtualGraphics(conn=g.conn, type="sdl")
 
932
        gdev5.xauth = "fooxauth"
 
933
        gdev5.display = "foodisplay"
 
934
        g.add_device(gdev1)
 
935
        g.add_device(gdev2)
 
936
        g.add_device(gdev3)
 
937
        g.add_device(gdev4)
 
938
        g.add_device(gdev5)
 
939
 
687
940
        g.clock.offset = "localtime"
688
941
 
689
 
        seclabel = virtinst.Seclabel(g.conn)
690
 
        seclabel.type = seclabel.SECLABEL_TYPE_STATIC
691
 
        seclabel.model = "selinux"
692
 
        seclabel.label = "foolabel"
693
 
        seclabel.imagelabel = "imagelabel"
694
 
        g.seclabel = seclabel
 
942
        g.seclabel.type = g.seclabel.SECLABEL_TYPE_STATIC
 
943
        g.seclabel.model = "selinux"
 
944
        g.seclabel.label = "foolabel"
 
945
        g.seclabel.imagelabel = "imagelabel"
695
946
 
696
 
        g.installer = virtinst.PXEInstaller(type="xen", os_type="hvm",
697
 
                                            conn=g.conn)
698
947
        self._compare(g, "boot-many-devices", False)
699
948
 
 
949
    def testCpuset(self):
 
950
        testconn = libvirt.open("test:///default")
 
951
        g = get_basic_fullyvirt_guest(testconn=testconn)
 
952
 
 
953
        # Cpuset
 
954
        cpustr = g.generate_cpuset(g.conn, g.memory)
 
955
        g.cpuset = cpustr
 
956
        g.maxvcpus = 7
 
957
 
 
958
        g.cpu.model = "footest"
 
959
        g.cpu.vendor = "Intel"
 
960
        g.cpu.match = "minimum"
 
961
 
 
962
        g.cpu.threads = "2"
 
963
        g.cpu.sockets = "4"
 
964
        g.cpu.cores = "5"
 
965
 
 
966
        g.cpu.add_feature("x2apic", "force")
 
967
        g.cpu.add_feature("lahf_lm", "forbid")
 
968
 
 
969
        self._compare(g, "boot-cpuset", False)
 
970
 
 
971
        # Test CPU topology determining
 
972
        cpu = virtinst.CPU(g.conn)
 
973
        cpu.sockets = "2"
 
974
        cpu.set_topology_defaults(6)
 
975
        self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [2, 3, 1])
 
976
 
 
977
        cpu = virtinst.CPU(g.conn)
 
978
        cpu.cores = "4"
 
979
        cpu.set_topology_defaults(9)
 
980
        self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [2, 4, 1])
 
981
 
 
982
        cpu = virtinst.CPU(g.conn)
 
983
        cpu.threads = "3"
 
984
        cpu.set_topology_defaults(14)
 
985
        self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [4, 1, 3])
 
986
 
 
987
        cpu = virtinst.CPU(g.conn)
 
988
        cpu.sockets = 5
 
989
        cpu.cores = 2
 
990
        self.assertEquals(cpu.vcpus_from_topology(), 10)
 
991
 
 
992
        cpu = virtinst.CPU(g.conn)
 
993
        self.assertEquals(cpu.vcpus_from_topology(), 1)
 
994
 
 
995
 
 
996
    #
 
997
    # Full Install tests: try to mimic virt-install as much as possible
 
998
    #
 
999
 
 
1000
    def testFullKVMRHEL6(self):
 
1001
        i = make_distro_installer(location="tests/cli-test-xml/fakerhel6tree",
 
1002
                                  gtype="kvm")
 
1003
        g = get_basic_fullyvirt_guest("kvm", installer=i)
 
1004
        g.disks.append(get_floppy())
 
1005
        g.disks.append(get_filedisk("/default-pool/rhel6.img"))
 
1006
        g.disks.append(get_blkdisk())
 
1007
        g.nics.append(get_virtual_network())
 
1008
        g.add_device(VirtualAudio())
 
1009
        g.add_device(VirtualVideoDevice(g.conn))
 
1010
        g.os_autodetect = True
 
1011
 
 
1012
        fargs = (g, "rhel6-kvm-stage1", "rhel6-kvm-stage2")
 
1013
        self.conn_function_wrappers(g, fargs, func=self._testInstall,
 
1014
                                    conn_uri=qemu_uri)
 
1015
 
 
1016
    def testFullKVMWinxp(self):
 
1017
        g = build_win_kvm("/default-pool/winxp.img")
 
1018
        fargs = (g, "winxp-kvm-stage1", "winxp-kvm-stage3", "winxp-kvm-stage2")
 
1019
        self.conn_function_wrappers(g, fargs, func=self._testInstall,
 
1020
                                    conn_uri=qemu_uri)
 
1021
 
700
1022
if __name__ == "__main__":
701
1023
    unittest.main()