uitests: Add a live hotplug and media change test

This commit is contained in:
Cole Robinson 2018-01-21 14:13:42 -05:00
parent ab36d429d6
commit 4a4207189f
2 changed files with 99 additions and 6 deletions

View File

@ -1,3 +1,4 @@
import logging
import os
import libvirt
@ -11,18 +12,25 @@ def _vm_wrapper(vmname, uri="qemu:///system"):
"""
def wrap1(fn):
def wrapper(self, *args, **kwargs):
dom = None
xmlfile = "%s/xml/%s.xml" % (os.path.dirname(__file__), vmname)
conn = libvirt.open(uri)
dom = conn.defineXML(open(xmlfile).read())
try:
xmlfile = "%s/xml/%s.xml" % (os.path.dirname(__file__), vmname)
conn = libvirt.open(uri)
dom = conn.createXML(open(xmlfile).read(), 0)
dom.create()
self.app.uri = uri
self.conn = conn
self.app.open(extra_opts=["--show-domain-console", vmname])
fn(self, *args, **kwargs)
finally:
self.app.stop()
if dom:
try:
self.app.stop()
except Exception:
pass
try:
dom.undefine()
dom.destroy()
except Exception:
pass
return wrapper
return wrap1
@ -32,6 +40,8 @@ class Console(uiutils.UITestCase):
Test live console connections with stub VMs
"""
conn = None
##############
# Test cases #
##############
@ -150,3 +160,69 @@ class Console(uiutils.UITestCase):
win.find("Virtual Machine", "menu").click()
win.find("Redirect USB", "menu item").click()
self.app.root.find("Select USB devices for redirection", "label")
def _testLiveHotplug(self, fname):
win = self.app.topwin
win.find("Details", "radio button").click()
# Add a scsi disk, importing the passed path
win.find("add-hardware", "push button").click()
addhw = self.app.root.find("Add New Virtual Hardware", "frame")
addhw.find("Storage", "table cell").click()
tab = addhw.find("storage-tab", None)
uiutils.check_in_loop(lambda: tab.showing)
tab.find("Select or create", "radio button").click()
tab.find("storage-entry").text = fname
tab.find("Bus type:", "combo box").click()
tab.find("SCSI", "menu item").click()
addhw.find("Finish", "push button").click()
# Hot unplug the disk
win.find("SCSI Disk 1", "table cell").click()
tab = win.find("disk-tab", None)
uiutils.check_in_loop(lambda: tab.showing)
self.assertTrue(tab.find("Storage format:", "text").text == "qcow2")
win.find("config-remove").click()
alert = self.app.root.find("vmm dialog", "alert")
alert.find_fuzzy("Are you sure you want to remove", "label")
alert.find("Yes", "push button").click()
# Change CDROM
win.find("IDE CDROM 1", "table cell").click()
tab = win.find("disk-tab", None)
uiutils.check_in_loop(lambda: tab.showing)
tab.find("Connect", "push button").click()
cm = self.app.root.find("Choose Media", "dialog")
cm.find("Image Location", "radio button").click()
cm.find("Location:", "text").text = fname
cm.find("OK", "push button").click()
self.assertTrue(tab.find("disk-source-path").text == fname)
tab.find("Disconnect", "push button").click()
self.assertTrue("-" in tab.find("disk-source-path").text)
@_vm_wrapper("uitests-hotplug")
def testLiveHotplug(self):
"""
Live test for basic hotplugging and media change, as well as
testing our auto-poolify magic
"""
import shutil
import tempfile
dname = tempfile.mkdtemp(prefix="uitests-tmp")
try:
fname = os.path.join(dname, "test.img")
os.system("qemu-img create -f qcow2 %s 1M > /dev/null" % fname)
os.system("chmod -R 777 %s" % dname)
self._testLiveHotplug(fname)
finally:
shutil.rmtree(dname)
poolname = os.path.basename(dname)
try:
pool = self.conn.storagePoolLookupByName(poolname)
pool.destroy()
pool.undefine()
except Exception:
logging.debug("Error cleaning up pool", exc_info=True)

View File

@ -0,0 +1,17 @@
<domain type="kvm">
<name>uitests-hotplug</name>
<memory>65536</memory>
<currentMemory>65536</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="x86_64">hvm</type>
<boot dev="hd"/>
</os>
<devices>
<disk type='file' device='cdrom'>
<target dev='hda' bus='ide'/>
</disk>
<controller type="scsi" model="virtio-scsi"/>
</devices>
</domain>