2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2020-08-28 18:48:00 +03:00
import unittest . mock
2015-09-14 19:53:02 +03:00
from tests . uitests import utils as uiutils
2015-09-09 16:49:45 +03:00
2018-01-09 18:01:56 +03:00
class VMMCLI ( uiutils . UITestCase ) :
2015-09-09 16:49:45 +03:00
"""
UI tests for virt - manager ' s command line --show options
"""
##############
# Test cases #
##############
def testShowNewVM ( self ) :
self . app . open ( extra_opts = [ " --show-domain-creator " ] )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : self . app . topwin . name == " New VM " )
2018-09-29 22:53:54 +03:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 16:49:45 +03:00
def testShowHost ( self ) :
self . app . open ( extra_opts = [ " --show-host-summary " ] )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : self . app . topwin . name == " test testdriver.xml Connection Details " )
nametext = self . app . topwin . find_fuzzy ( " Name: " , " text " )
uiutils . check ( lambda : nametext . text == " test testdriver.xml " )
2018-09-29 22:53:54 +03:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 16:49:45 +03:00
def testShowDetails ( self ) :
2017-03-06 23:35:02 +03:00
self . app . open ( extra_opts = [ " --show-domain-editor " , " test-clone-simple " ] )
2015-09-09 16:49:45 +03:00
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : " test-clone-simple on " in self . app . topwin . name )
rlabel = self . app . topwin . find_fuzzy ( " Guest is not running " , " label " )
uiutils . check ( lambda : not rlabel . showing )
addhw = self . app . topwin . find_fuzzy ( " add-hardware " , " button " )
uiutils . check ( lambda : addhw . showing )
2018-09-29 22:53:54 +03:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 16:49:45 +03:00
def testShowPerformance ( self ) :
2020-08-29 19:34:36 +03:00
domid = " 1 "
self . app . open ( extra_opts = [ " --show-domain-performance " , domid ] )
2015-09-09 16:49:45 +03:00
2020-08-29 19:34:36 +03:00
uiutils . check ( lambda : " test on " in self . app . topwin . name )
2020-08-25 16:48:56 +03:00
cpulabel = self . app . topwin . find_fuzzy ( " CPU usage " , " label " )
uiutils . check ( lambda : cpulabel . showing )
2015-09-09 16:49:45 +03:00
def testShowConsole ( self ) :
2020-08-29 19:34:36 +03:00
# UUID of test-clone-simple
uuid = " 12345678-1234-ffff-1234-12345678ffff "
self . app . open ( extra_opts = [ " --show-domain-console " , uuid ] )
2015-09-09 16:49:45 +03:00
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : " test-clone-simple on " in self . app . topwin . name )
rlabel = self . app . topwin . find_fuzzy ( " Guest is not running " , " label " )
uiutils . check ( lambda : rlabel . showing )
addhw = self . app . topwin . find_fuzzy ( " add-hardware " , " button " )
uiutils . check ( lambda : not addhw . showing )
2018-01-20 02:04:15 +03:00
2019-03-04 21:34:22 +03:00
def testShowDelete ( self ) :
self . app . open (
extra_opts = [ " --show-domain-delete " , " test-clone " ] ,
window_name = " Delete " )
# Ensure details opened too
self . app . root . find ( " test-clone on " , " frame " ,
check_active = False )
delete = self . app . topwin
delete . find_fuzzy ( " Delete " , " button " ) . click ( )
2020-08-21 19:55:10 +03:00
self . _click_alert_button ( " Are you sure " , " Yes " )
2019-03-04 21:34:22 +03:00
# Ensure app exits
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2019-03-04 21:34:22 +03:00
2018-09-29 22:53:54 +03:00
def testShowRemoteDBusConnect ( self ) :
2018-01-20 02:04:15 +03:00
"""
Test the remote app dbus connection
"""
self . app . open ( )
2020-08-29 19:34:36 +03:00
uiutils . check ( lambda : " testdriver " in self . app . topwin . fmt_nodes ( ) )
uiutils . check ( lambda : " test default " not in self . app . topwin . fmt_nodes ( ) )
def _run_remote ( opts ) :
newapp = uiutils . VMMDogtailApp ( " test:///default " )
newapp . open ( check_already_running = False ,
extra_opts = opts )
uiutils . check ( lambda : not newapp . is_running ( ) )
import dogtail . tree
vapps = [ a for a in dogtail . tree . root . applications ( ) if
a . name == " virt-manager " ]
uiutils . check ( lambda : len ( vapps ) == 1 )
# Ensure connection showed up
self . app . topwin . find ( " test default " , " table cell " )
_run_remote ( [ ] )
# Run remote again to trigger engine.py code when a connection
# is already there and connected
_run_remote ( [ " --show-domain-console=test " ] )
2018-01-21 22:34:35 +03:00
2018-03-17 23:48:30 +03:00
def testShowCLIError ( self ) :
2020-08-22 23:22:41 +03:00
# Unknown option
2018-01-21 22:34:35 +03:00
self . app . open ( extra_opts = [ " --idontexist " ] )
2020-08-21 19:55:10 +03:00
self . _click_alert_button ( " Unhandled command line " , " Close " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2018-03-17 23:48:30 +03:00
2020-08-22 23:22:41 +03:00
# Missing VM
self . app . open ( extra_opts = [ " --show-domain-delete " , " IDONTEXIST " ] )
self . _click_alert_button ( " does not have VM " , " Close " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2020-08-22 23:22:41 +03:00
# Bad URI
2018-03-17 23:48:30 +03:00
baduri = " fribfrobfroo "
self . app = uiutils . VMMDogtailApp ( baduri )
2020-08-21 19:55:10 +03:00
self . _click_alert_button ( baduri , " Close " )
2020-08-25 16:48:56 +03:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2020-08-22 23:22:41 +03:00
2020-08-29 19:34:36 +03:00
def testCLIFirstRunURIGood ( self ) :
# Emulate first run with a URI that will succeed
self . app . open ( use_uri = False , firstrun_uri = " test:///default " )
self . app . root . find ( " test default " , " table cell " )
def testCLIFirstRunURIBad ( self ) :
# Emulate first run with a URI that will succeed
self . app . open ( use_uri = False , firstrun_uri = " bad:///uri " )
self . app . topwin . find ( " bad uri " , " table cell " )
self . _click_alert_button ( " bad:///uri " , " Close " )
2020-08-22 23:22:41 +03:00
def testCLITraceLibvirt ( self ) :
2020-08-27 23:37:15 +03:00
# Just test this for code coverage
self . app . open ( keyfile = " allstats.ini " ,
extra_opts = [ " --trace-libvirt=mainloop " ] )
# Give it a little time to work
self . sleep ( 2 )
uiutils . check ( lambda : self . app . topwin . active )
def testCLILeakDebug ( self ) :
# Just test this for code coverage
self . app . open ( keyfile = " allstats.ini " ,
extra_opts = [ " --test-options=leak-debug " ] )
self . sleep ( 2 )
# Give it a little time to work
uiutils . check ( lambda : self . app . topwin . active )
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-28 18:48:00 +03:00
def testCLINoFirstRun ( self ) :
# Test a simple case of loading without any config override
2020-08-29 20:07:19 +03:00
self . app . open ( first_run = False , enable_libguestfs = None , use_uri = False )
2020-08-28 18:48:00 +03:00
self . sleep ( 2 )
uiutils . check ( lambda : self . app . topwin . showing )
def testCLINoFork ( self ) :
# Test app without forking
2020-08-29 20:07:19 +03:00
self . app . open ( first_run = False , enable_libguestfs = None ,
use_uri = False , no_fork = False )
2020-08-28 18:48:00 +03:00
assert self . app . wait_for_exit ( ) is True
uiutils . check ( lambda : self . app . topwin . showing )
self . app . topwin . keyCombo ( " <alt>F4 " )
def testCLIGTKArgs ( self ) :
# Ensure gtk arg passthrough works
self . app . open ( extra_opts = [ " --gtk-debug=misc " ] )
uiutils . check ( lambda : self . app . topwin . showing )
self . app . topwin . keyCombo ( " <alt>F4 " )
@unittest.mock.patch.dict ( ' os.environ ' , { " DISPLAY " : " " } )
def testCLINoDisplay ( self ) :
# Ensure missing display exits
self . app . open ( will_fail = True )
self . app . wait_for_exit ( )