uitests: Finish createconn.py coverage

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-08-24 16:55:42 -04:00
parent 35d4687237
commit fd5216c184
2 changed files with 74 additions and 27 deletions

View File

@ -36,23 +36,57 @@ class VMMConnect(uiutils.UITestCase):
host = win.find("Hostname", "text") host = win.find("Hostname", "text")
urilabel = win.find("uri-label", "label") urilabel = win.find("uri-label", "label")
urientry = win.find("uri-entry", "text") urientry = win.find("uri-entry", "text")
self.assertTrue(user.showing is host.showing is True) assert user.showing is host.showing is True
# Select all HV options
hvcombo = win.find_fuzzy("Hypervisor", "combo box")
def _click_hv(hvname):
hvcombo.click()
hvcombo.find_fuzzy(hvname, "menu item").click()
_click_hv("user session")
_click_hv("QEMU/KVM")
_click_hv("Xen")
_click_hv("Bhyve")
_click_hv("Virtuozzo")
_click_hv("LXC")
# Test a simple selection
win.find_fuzzy("Hypervisor", "combo box").click() win.find_fuzzy("Hypervisor", "combo box").click()
win.find_fuzzy("QEMU/KVM user session", "menu item").click() win.find_fuzzy("QEMU/KVM user session", "menu item").click()
self.assertTrue(user.showing is host.showing is False) assert user.showing is host.showing is False
self.assertTrue(urilabel.text == "qemu:///session") assert urilabel.text == "qemu:///session"
# Cancel the dialog
win.find_fuzzy("Cancel", "push button").click()
uiutils.check_in_loop(lambda: not win.showing)
# Reopen it, confirm content changed
self.app.root.find("File", "menu").click()
self.app.root.find("Add Connection...", "menu item").click()
win = self.app.root.find_fuzzy("Add Connection", "dialog")
assert ":///session" not in urilabel.text
# Relaunch the dialog, confirm it doesn't overwrite content
_click_hv("LXC")
uiutils.check_in_loop(lambda: "lxc" in urilabel.text)
self.app.root.find("File", "menu").click()
self.app.root.find("Add Connection...", "menu item").click()
uiutils.check_in_loop(lambda: win.active)
uiutils.check_in_loop(lambda: "lxc" in urilabel.text)
# Enter a failing URI, make sure error is raised, and we can # Enter a failing URI, make sure error is raised, and we can
# fall back to the dialog # fall back to the dialog
win.find_fuzzy("Hypervisor", "combo box").click() _click_hv("Xen")
win.find_fuzzy("Xen", "menu item").click()
remote.click() remote.click()
user.text = "fribuser" user.text = "fribuser"
connect.click()
self._click_alert_button("hostname is required", "OK")
fakeipv6 = "fe80::1"
host.text = fakeipv6
assert urilabel.text == "xen+ssh://fribuser@[%s]/" % fakeipv6
fakehost = "ix8khfyidontexistkdjur.com" fakehost = "ix8khfyidontexistkdjur.com"
host.text = fakehost + ":12345" host.text = fakehost + ":12345"
self.assertTrue( assert urilabel.text == "xen+ssh://fribuser@%s:12345/" % fakehost
urilabel.text == "xen+ssh://fribuser@%s:12345/" % fakehost)
connect.click() connect.click()
uiutils.check_in_loop(lambda: win.showing is True) uiutils.check_in_loop(lambda: win.showing is True)
@ -63,7 +97,7 @@ class VMMConnect(uiutils.UITestCase):
# Ensure dialog shows old contents for editing # Ensure dialog shows old contents for editing
uiutils.check_in_loop(lambda: win.showing) uiutils.check_in_loop(lambda: win.showing)
self.assertTrue(fakehost in host.text) assert fakehost in host.text
# This time say 'yes' # This time say 'yes'
connect.click() connect.click()
@ -79,8 +113,16 @@ class VMMConnect(uiutils.UITestCase):
self.app.root.find("File", "menu").click() self.app.root.find("File", "menu").click()
self.app.root.find("Add Connection...", "menu item").click() self.app.root.find("Add Connection...", "menu item").click()
win = self.app.root.find_fuzzy("Add Connection", "dialog") win = self.app.root.find_fuzzy("Add Connection", "dialog")
win.find_fuzzy("Hypervisor", "combo box").click() _click_hv("Custom URI")
win.find_fuzzy("Custom URI", "menu item").click() urientry.text = "test:///default"
connect.click()
# Do it again to make sure things don't explode
uiutils.check_in_loop(lambda: win.showing is False)
self.app.root.find("File", "menu").click()
self.app.root.find("Add Connection...", "menu item").click()
win = self.app.root.find_fuzzy("Add Connection", "dialog")
_click_hv("Custom URI")
urientry.text = "test:///default" urientry.text = "test:///default"
connect.click() connect.click()

View File

@ -25,6 +25,25 @@ HV_VZ,
HV_CUSTOM) = range(7) HV_CUSTOM) = range(7)
def _default_uri(): # pragma: no cover
if os.path.exists('/var/lib/xen'):
if (os.path.exists('/dev/xen/evtchn') or
os.path.exists("/proc/xen")):
return 'xen:///'
if (os.path.exists("/usr/bin/qemu") or
os.path.exists("/usr/bin/qemu-kvm") or
os.path.exists("/usr/bin/kvm") or
os.path.exists("/usr/libexec/qemu-kvm") or
glob.glob("/usr/bin/qemu-system-*")):
return "qemu:///system"
if (os.path.exists("/usr/lib/libvirt/libvirt_lxc") or
os.path.exists("/usr/lib64/libvirt/libvirt_lxc")):
return "lxc:///"
return None
class vmmCreateConn(vmmGObjectUI): class vmmCreateConn(vmmGObjectUI):
@classmethod @classmethod
def get_instance(cls, parentobj): def get_instance(cls, parentobj):
@ -56,22 +75,7 @@ class vmmCreateConn(vmmGObjectUI):
@staticmethod @staticmethod
def default_uri(): def default_uri():
if os.path.exists('/var/lib/xen'): return _default_uri()
if (os.path.exists('/dev/xen/evtchn') or
os.path.exists("/proc/xen")):
return 'xen:///'
if (os.path.exists("/usr/bin/qemu") or
os.path.exists("/usr/bin/qemu-kvm") or
os.path.exists("/usr/bin/kvm") or
os.path.exists("/usr/libexec/qemu-kvm") or
glob.glob("/usr/bin/qemu-system-*")):
return "qemu:///system"
if (os.path.exists("/usr/lib/libvirt/libvirt_lxc") or
os.path.exists("/usr/lib64/libvirt/libvirt_lxc")):
return "lxc:///"
return None
def cancel(self, ignore1=None, ignore2=None): def cancel(self, ignore1=None, ignore2=None):
log.debug("Cancelling open connection") log.debug("Cancelling open connection")
@ -142,7 +146,7 @@ class vmmCreateConn(vmmGObjectUI):
default = self.default_uri() default = self.default_uri()
if not default or default.startswith("qemu"): if not default or default.startswith("qemu"):
uiutil.set_list_selection(self.widget("hypervisor"), HV_QEMU) uiutil.set_list_selection(self.widget("hypervisor"), HV_QEMU)
elif default.startswith("xen"): elif default.startswith("xen"): # pragma: no cover
uiutil.set_list_selection(self.widget("hypervisor"), HV_XEN) uiutil.set_list_selection(self.widget("hypervisor"), HV_XEN)
def hostname_changed(self, src_ignore): def hostname_changed(self, src_ignore):
@ -275,6 +279,7 @@ class vmmCreateConn(vmmGObjectUI):
conn = vmmConnectionManager.get_instance().add_conn(uri) conn = vmmConnectionManager.get_instance().add_conn(uri)
conn.set_autoconnect(auto) conn.set_autoconnect(auto)
if conn.is_active(): if conn.is_active():
self._conn_open_completed(conn, None)
return return
conn.connect_once("open-completed", self._conn_open_completed) conn.connect_once("open-completed", self._conn_open_completed)