2014-01-21 00:09:13 +08:00
|
|
|
# Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-10-28 04:59:47 +08:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
|
|
|
|
import virtinst
|
|
|
|
from virtinst import VirtualDisk
|
2015-04-07 03:42:40 +08:00
|
|
|
from virtcli import CLIConfig
|
2013-04-12 04:32:00 +08:00
|
|
|
|
2013-04-11 07:48:07 +08:00
|
|
|
from tests import utils
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-12 04:32:00 +08:00
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
_default_conn = utils.open_testdriver()
|
|
|
|
|
|
|
|
|
|
|
|
def _make_guest(installer=None, conn=None):
|
|
|
|
if conn is None:
|
|
|
|
conn = _default_conn
|
|
|
|
|
2015-07-10 18:06:48 +08:00
|
|
|
g = conn.caps.lookup_virtinst_guest()
|
2014-12-10 00:33:43 +08:00
|
|
|
g.type = "kvm"
|
|
|
|
g.name = "TestGuest"
|
|
|
|
g.memory = int(200 * 1024)
|
|
|
|
g.maxmemory = int(400 * 1024)
|
|
|
|
g.uuid = "12345678-1234-1234-1234-123456789012"
|
|
|
|
gdev = virtinst.VirtualGraphics(conn)
|
|
|
|
gdev.type = "vnc"
|
|
|
|
gdev.keymap = "ja"
|
|
|
|
g.add_device(gdev)
|
|
|
|
g.features.pae = False
|
|
|
|
g.vcpus = 5
|
|
|
|
|
|
|
|
if not installer:
|
|
|
|
installer = _make_installer(conn=conn)
|
|
|
|
g.installer = installer
|
|
|
|
g.emulator = "/usr/lib/xen/bin/qemu-dm"
|
|
|
|
g.os.arch = "i686"
|
|
|
|
g.os.os_type = "hvm"
|
|
|
|
|
|
|
|
g.add_default_input_device()
|
|
|
|
g.add_default_console_device()
|
|
|
|
g.add_device(virtinst.VirtualAudio(g.conn))
|
|
|
|
|
|
|
|
# Floppy disk
|
|
|
|
path = "/dev/default-pool/testvol1.img"
|
|
|
|
d = VirtualDisk(conn)
|
|
|
|
d.path = path
|
|
|
|
d.device = d.DEVICE_FLOPPY
|
|
|
|
d.validate()
|
|
|
|
g.add_device(d)
|
|
|
|
|
|
|
|
# File disk
|
|
|
|
path = "/dev/default-pool/new-test-suite.img"
|
|
|
|
d = virtinst.VirtualDisk(conn)
|
|
|
|
d.path = path
|
|
|
|
|
|
|
|
if d.wants_storage_creation():
|
|
|
|
parent_pool = d.get_parent_pool()
|
|
|
|
vol_install = virtinst.VirtualDisk.build_vol_install(conn,
|
|
|
|
os.path.basename(path), parent_pool, .0000001, True)
|
|
|
|
d.set_vol_install(vol_install)
|
|
|
|
|
|
|
|
d.validate()
|
|
|
|
g.add_device(d)
|
|
|
|
|
|
|
|
# Block disk
|
|
|
|
path = "/dev/disk-pool/diskvol1"
|
|
|
|
d = virtinst.VirtualDisk(conn)
|
|
|
|
d.path = path
|
|
|
|
d.validate()
|
|
|
|
g.add_device(d)
|
|
|
|
|
|
|
|
# Network device
|
|
|
|
dev = virtinst.VirtualNetworkInterface(conn)
|
|
|
|
dev.macaddr = "22:22:33:44:55:66"
|
|
|
|
dev.type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
|
|
|
|
dev.source = "default"
|
|
|
|
g.add_device(dev)
|
|
|
|
|
|
|
|
return g
|
|
|
|
|
|
|
|
|
|
|
|
def _make_installer(location=None, conn=None):
|
|
|
|
conn = conn or _default_conn
|
|
|
|
inst = virtinst.DistroInstaller(conn)
|
|
|
|
if location:
|
|
|
|
inst.location = location
|
|
|
|
else:
|
|
|
|
inst.location = "/dev/null"
|
|
|
|
inst.cdrom = True
|
|
|
|
return inst
|
|
|
|
|
|
|
|
|
|
|
|
class TestXMLMisc(unittest.TestCase):
|
|
|
|
"""
|
|
|
|
Misc tests for various XML special behavior. These should only aim for
|
|
|
|
testing any particularly tricky bits, general XML generation should
|
|
|
|
be through virt-install examples in clitest
|
|
|
|
"""
|
|
|
|
def _compare(self, guest, filebase, do_install):
|
|
|
|
filename = os.path.join("tests/xmlconfig-xml", filebase + ".xml")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-08-15 07:43:02 +08:00
|
|
|
inst_xml, boot_xml = guest.start_install(return_xml=True, dry=True)
|
2014-12-10 00:33:43 +08:00
|
|
|
if do_install:
|
2013-08-15 07:43:02 +08:00
|
|
|
actualXML = inst_xml
|
|
|
|
else:
|
|
|
|
actualXML = boot_xml
|
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
utils.diff_compare(actualXML, filename)
|
|
|
|
utils.test_create(guest.conn, actualXML)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testDefaultBridge(self):
|
2014-12-10 00:33:43 +08:00
|
|
|
# Test our handling of the default bridge routines
|
2013-03-18 05:06:52 +08:00
|
|
|
origfunc = None
|
|
|
|
try:
|
2016-08-25 04:14:33 +08:00
|
|
|
from virtinst import deviceinterface
|
|
|
|
origfunc = getattr(deviceinterface, "_default_bridge")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def newbridge(ignore_conn):
|
2014-10-28 07:26:31 +08:00
|
|
|
return "bzz0"
|
2016-08-25 04:14:33 +08:00
|
|
|
setattr(deviceinterface, "_default_bridge", newbridge)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
dev1 = virtinst.VirtualNetworkInterface(_default_conn)
|
2013-03-18 05:06:52 +08:00
|
|
|
dev1.macaddr = "22:22:33:44:55:66"
|
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
dev2 = virtinst.VirtualNetworkInterface(_default_conn,
|
2013-07-18 05:58:24 +08:00
|
|
|
parsexml=dev1.get_xml_config())
|
2013-03-18 05:06:52 +08:00
|
|
|
dev2.source = None
|
|
|
|
dev2.source = "foobr0"
|
|
|
|
dev2.macaddr = "22:22:33:44:55:67"
|
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
dev3 = virtinst.VirtualNetworkInterface(_default_conn,
|
2013-07-18 05:58:24 +08:00
|
|
|
parsexml=dev1.get_xml_config())
|
2013-03-18 05:06:52 +08:00
|
|
|
dev3.source = None
|
|
|
|
dev3.macaddr = "22:22:33:44:55:68"
|
|
|
|
|
2013-07-18 05:58:24 +08:00
|
|
|
utils.diff_compare(dev1.get_xml_config(), None,
|
2013-07-25 02:37:07 +08:00
|
|
|
"<interface type=\"bridge\">\n"
|
|
|
|
" <source bridge=\"bzz0\"/>\n"
|
|
|
|
" <mac address=\"22:22:33:44:55:66\"/>\n"
|
|
|
|
"</interface>\n")
|
2013-07-18 05:58:24 +08:00
|
|
|
utils.diff_compare(dev2.get_xml_config(), None,
|
|
|
|
"<interface type=\"bridge\">\n"
|
2013-07-25 02:37:07 +08:00
|
|
|
" <source bridge=\"foobr0\"/>\n"
|
|
|
|
" <mac address=\"22:22:33:44:55:67\"/>\n"
|
|
|
|
"</interface>\n")
|
2013-07-18 05:58:24 +08:00
|
|
|
utils.diff_compare(dev3.get_xml_config(), None,
|
|
|
|
"<interface type=\"bridge\">\n"
|
2013-07-25 02:37:07 +08:00
|
|
|
" <mac address=\"22:22:33:44:55:68\"/>\n"
|
|
|
|
"</interface>\n")
|
2013-03-18 05:06:52 +08:00
|
|
|
finally:
|
2016-08-25 04:14:33 +08:00
|
|
|
if origfunc:
|
|
|
|
from virtinst import deviceinterface
|
|
|
|
setattr(deviceinterface, "_default_bridge", origfunc)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testCpustrToTuple(self):
|
2014-12-10 00:33:43 +08:00
|
|
|
# Various testing our cpustr handling
|
|
|
|
conn = _default_conn
|
2013-03-18 05:06:52 +08:00
|
|
|
base = [False] * 16
|
|
|
|
|
|
|
|
expect = base[:]
|
|
|
|
expect[1] = expect[2] = expect[3] = True
|
|
|
|
self.assertEquals(tuple(expect),
|
2014-12-10 00:33:43 +08:00
|
|
|
virtinst.DomainNumatune.cpuset_str_to_tuple(conn, "1-3"))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
expect = base[:]
|
|
|
|
expect[1] = expect[3] = expect[5] = expect[10] = expect[11] = True
|
|
|
|
self.assertEquals(tuple(expect),
|
2014-12-10 00:33:43 +08:00
|
|
|
virtinst.DomainNumatune.cpuset_str_to_tuple(conn, "1,3,5,10-11"))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
self.assertRaises(ValueError,
|
2014-12-10 00:33:43 +08:00
|
|
|
virtinst.DomainNumatune.cpuset_str_to_tuple,
|
|
|
|
conn, "16")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-10-03 19:20:54 +08:00
|
|
|
def testDiskNumbers(self):
|
2014-12-10 00:33:43 +08:00
|
|
|
# Various testing our target generation
|
2013-10-03 19:20:54 +08:00
|
|
|
self.assertEquals("a", VirtualDisk.num_to_target(1))
|
|
|
|
self.assertEquals("b", VirtualDisk.num_to_target(2))
|
|
|
|
self.assertEquals("z", VirtualDisk.num_to_target(26))
|
|
|
|
self.assertEquals("aa", VirtualDisk.num_to_target(27))
|
|
|
|
self.assertEquals("ab", VirtualDisk.num_to_target(28))
|
|
|
|
self.assertEquals("az", VirtualDisk.num_to_target(52))
|
|
|
|
self.assertEquals("ba", VirtualDisk.num_to_target(53))
|
|
|
|
self.assertEquals("zz", VirtualDisk.num_to_target(27 * 26))
|
|
|
|
self.assertEquals("aaa", VirtualDisk.num_to_target(27 * 26 + 1))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-23 13:31:48 +08:00
|
|
|
self.assertEquals(VirtualDisk.target_to_num("hda"), 0)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("hdb"), 1)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("sdz"), 25)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("sdaa"), 26)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("vdab"), 27)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("vdaz"), 51)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("xvdba"), 52)
|
2014-12-10 00:33:43 +08:00
|
|
|
self.assertEquals(VirtualDisk.target_to_num("xvdzz"),
|
|
|
|
26 * (25 + 1) + 25)
|
|
|
|
self.assertEquals(VirtualDisk.target_to_num("xvdaaa"),
|
|
|
|
26 * 26 * 1 + 26 * 1 + 0)
|
2014-02-12 22:44:40 +08:00
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
disk = virtinst.VirtualDisk(_default_conn)
|
2013-10-03 20:40:24 +08:00
|
|
|
disk.bus = "ide"
|
|
|
|
|
|
|
|
self.assertEquals("hda", disk.generate_target([]))
|
|
|
|
self.assertEquals("hdb", disk.generate_target(["hda"]))
|
|
|
|
self.assertEquals("hdc", disk.generate_target(["hdb", "sda"]))
|
|
|
|
self.assertEquals("hdb", disk.generate_target(["hda", "hdd"]))
|
|
|
|
|
2014-02-17 23:41:02 +08:00
|
|
|
disk.bus = "virtio-scsi"
|
2014-12-10 00:33:43 +08:00
|
|
|
self.assertEquals("sdb",
|
|
|
|
disk.generate_target(["sda", "sdg", "sdi"], 0))
|
2014-02-12 22:44:40 +08:00
|
|
|
self.assertEquals("sdh", disk.generate_target(["sda", "sdg"], 1))
|
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
def testQuickTreeinfo(self):
|
|
|
|
# Simple sanity test to make sure detect_distro works. test-urls
|
|
|
|
# does much more exhaustive testing but it's only run occasionally
|
|
|
|
i = _make_installer(
|
|
|
|
location="tests/cli-test-xml/fakefedoratree")
|
|
|
|
g = _make_guest(i)
|
2013-08-11 06:48:43 +08:00
|
|
|
v = i.detect_distro(g)
|
|
|
|
self.assertEquals(v, "fedora17")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
i = _make_installer(
|
|
|
|
location="tests/cli-test-xml/fakerhel6tree")
|
|
|
|
g = _make_guest(i)
|
|
|
|
v = i.detect_distro(g)
|
|
|
|
self.assertEquals(v, "rhel6.0")
|
|
|
|
|
|
|
|
def testCPUTopology(self):
|
|
|
|
# Test CPU topology determining
|
|
|
|
cpu = virtinst.CPU(_default_conn)
|
|
|
|
cpu.sockets = "2"
|
|
|
|
cpu.set_topology_defaults(6)
|
|
|
|
self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [2, 3, 1])
|
|
|
|
|
|
|
|
cpu = virtinst.CPU(_default_conn)
|
|
|
|
cpu.cores = "4"
|
|
|
|
cpu.set_topology_defaults(9)
|
|
|
|
self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [2, 4, 1])
|
|
|
|
|
|
|
|
cpu = virtinst.CPU(_default_conn)
|
|
|
|
cpu.threads = "3"
|
|
|
|
cpu.set_topology_defaults(14)
|
|
|
|
self.assertEquals([cpu.sockets, cpu.cores, cpu.threads], [4, 1, 3])
|
|
|
|
|
|
|
|
cpu = virtinst.CPU(_default_conn)
|
|
|
|
cpu.sockets = 5
|
|
|
|
cpu.cores = 2
|
|
|
|
self.assertEquals(cpu.vcpus_from_topology(), 10)
|
|
|
|
|
|
|
|
cpu = virtinst.CPU(_default_conn)
|
|
|
|
self.assertEquals(cpu.vcpus_from_topology(), 1)
|
|
|
|
|
|
|
|
def testAC97(self):
|
|
|
|
# Test setting ac97 version given various version combos
|
|
|
|
def has_ac97(conn):
|
|
|
|
g = _make_guest(conn=conn)
|
|
|
|
|
|
|
|
g.os_variant = "fedora11"
|
|
|
|
|
|
|
|
# pylint: disable=unpacking-non-sequence
|
|
|
|
xml, ignore = g.start_install(return_xml=True, dry=True)
|
|
|
|
return "ac97" in xml
|
|
|
|
|
2015-04-23 05:06:35 +08:00
|
|
|
self.assertTrue(has_ac97(utils.open_kvm(connver=11000)))
|
|
|
|
self.assertFalse(has_ac97(utils.open_kvm(libver=5000)))
|
|
|
|
self.assertFalse(has_ac97(utils.open_kvm(libver=7000, connver=7000)))
|
2014-12-10 00:33:43 +08:00
|
|
|
|
|
|
|
def testOSDeviceDefaultChange(self):
|
|
|
|
"""
|
|
|
|
Make sure device defaults are properly changed if we change OS
|
|
|
|
distro/variant mid process
|
|
|
|
"""
|
2015-03-24 04:48:43 +08:00
|
|
|
# Use connver=12005 so that non-rhel displays ac97
|
2015-04-23 05:06:35 +08:00
|
|
|
conn = utils.open_kvm_rhel(connver=12005)
|
2014-12-10 00:33:43 +08:00
|
|
|
|
2015-04-08 04:38:52 +08:00
|
|
|
g = _make_guest(conn=conn)
|
2014-12-10 00:33:43 +08:00
|
|
|
g.os_variant = "fedora11"
|
2015-04-08 04:38:52 +08:00
|
|
|
self._compare(g, "install-f11-norheldefaults", False)
|
2014-12-10 00:33:43 +08:00
|
|
|
|
|
|
|
try:
|
2015-04-07 03:42:40 +08:00
|
|
|
CLIConfig.stable_defaults = True
|
2015-04-08 04:38:52 +08:00
|
|
|
|
|
|
|
g = _make_guest(conn=conn)
|
|
|
|
g.os_variant = "fedora11"
|
2014-12-10 00:33:43 +08:00
|
|
|
origemu = g.emulator
|
|
|
|
g.emulator = "/usr/libexec/qemu-kvm"
|
2015-03-24 04:48:43 +08:00
|
|
|
self.assertTrue(g.conn.stable_defaults())
|
|
|
|
|
2014-12-10 00:33:43 +08:00
|
|
|
setattr(g.conn, "_support_cache", {})
|
2015-04-08 04:38:52 +08:00
|
|
|
self._compare(g, "install-f11-rheldefaults", False)
|
2014-12-10 00:33:43 +08:00
|
|
|
g.emulator = origemu
|
|
|
|
setattr(g.conn, "_support_cache", {})
|
|
|
|
finally:
|
2015-04-07 03:42:40 +08:00
|
|
|
CLIConfig.stable_defaults = False
|
2014-12-10 00:33:43 +08:00
|
|
|
|
2015-07-21 01:06:34 +08:00
|
|
|
def test_hyperv_clock(self):
|
|
|
|
def _make(connver):
|
|
|
|
conn = utils.open_kvm(libver=1002002, connver=connver)
|
|
|
|
g = _make_guest(conn=conn)
|
|
|
|
g.os_variant = "win7"
|
|
|
|
g.emulator = "/usr/libexec/qemu-kvm"
|
|
|
|
return g
|
|
|
|
|
|
|
|
try:
|
|
|
|
g = _make(2000000)
|
|
|
|
self._compare(g, "install-hyperv-clock", True)
|
|
|
|
|
|
|
|
g = _make(1009000)
|
|
|
|
self._compare(g, "install-hyperv-noclock", True)
|
|
|
|
|
|
|
|
CLIConfig.stable_defaults = True
|
|
|
|
|
|
|
|
g = _make(1005003)
|
|
|
|
self._compare(g, "install-hyperv-clock", True)
|
|
|
|
|
|
|
|
g = _make(1005002)
|
|
|
|
self._compare(g, "install-hyperv-noclock", True)
|
|
|
|
finally:
|
|
|
|
CLIConfig.stable_defaults = False
|