2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2020-08-28 11:48:00 -04:00
import unittest . mock
2015-09-14 12:53:02 -04:00
from tests . uitests import utils as uiutils
2015-09-09 09:49:45 -04:00
2018-01-09 10:01:56 -05:00
class VMMCLI ( uiutils . UITestCase ) :
2015-09-09 09:49:45 -04: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 09:48:56 -04:00
uiutils . check ( lambda : self . app . topwin . name == " New VM " )
2018-09-29 15:53:54 -04:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 09:49:45 -04:00
def testShowHost ( self ) :
self . app . open ( extra_opts = [ " --show-host-summary " ] )
2020-08-25 09:48:56 -04: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 15:53:54 -04:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 09:49:45 -04:00
def testShowDetails ( self ) :
2017-03-06 15:35:02 -05:00
self . app . open ( extra_opts = [ " --show-domain-editor " , " test-clone-simple " ] )
2015-09-09 09:49:45 -04:00
2020-08-25 09:48:56 -04: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 15:53:54 -04:00
self . app . topwin . keyCombo ( " <alt>F4 " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : self . app . is_running ( ) is False )
2015-09-09 09:49:45 -04:00
def testShowPerformance ( self ) :
self . app . open ( extra_opts = [ " --show-domain-performance " ,
2017-03-06 15:35:02 -05:00
" test-clone-simple " ] )
2015-09-09 09:49:45 -04:00
2020-08-25 09:48:56 -04: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 )
cpulabel = self . app . topwin . find_fuzzy ( " CPU usage " , " label " )
uiutils . check ( lambda : cpulabel . showing )
2015-09-09 09:49:45 -04:00
def testShowConsole ( self ) :
2017-03-06 15:35:02 -05:00
self . app . open ( extra_opts = [ " --show-domain-console " , " test-clone-simple " ] )
2015-09-09 09:49:45 -04:00
2020-08-25 09:48:56 -04: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-19 18:04:15 -05:00
2019-03-04 13:34:22 -05: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 12:55:10 -04:00
self . _click_alert_button ( " Are you sure " , " Yes " )
2019-03-04 13:34:22 -05:00
# Ensure app exits
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2019-03-04 13:34:22 -05:00
2018-09-29 15:53:54 -04:00
def testShowRemoteDBusConnect ( self ) :
2018-01-19 18:04:15 -05:00
"""
Test the remote app dbus connection
"""
self . app . open ( )
newapp = uiutils . VMMDogtailApp ( " test:///default " )
2018-09-04 13:16:34 -04:00
newapp . open ( check_already_running = False )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not newapp . is_running ( ) )
2018-01-19 18:04:15 -05:00
import dogtail . tree
vapps = [ a for a in dogtail . tree . root . applications ( ) if
a . name == " virt-manager " ]
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : len ( vapps ) == 1 )
2018-01-19 18:04:15 -05:00
self . app . topwin . find ( " test default " , " table cell " )
2018-01-21 14:34:35 -05:00
2018-03-17 16:48:30 -04:00
def testShowCLIError ( self ) :
2020-08-22 16:22:41 -04:00
# Unknown option
2018-01-21 14:34:35 -05:00
self . app . open ( extra_opts = [ " --idontexist " ] )
2020-08-21 12:55:10 -04:00
self . _click_alert_button ( " Unhandled command line " , " Close " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2018-03-17 16:48:30 -04:00
2020-08-22 16:22:41 -04:00
# Missing VM
self . app . open ( extra_opts = [ " --show-domain-delete " , " IDONTEXIST " ] )
self . _click_alert_button ( " does not have VM " , " Close " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2020-08-22 16:22:41 -04:00
# Bad URI
2018-03-17 16:48:30 -04:00
baduri = " fribfrobfroo "
self . app = uiutils . VMMDogtailApp ( baduri )
2020-08-21 12:55:10 -04:00
self . _click_alert_button ( baduri , " Close " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not self . app . is_running ( ) )
2020-08-22 16:22:41 -04:00
def testCLITraceLibvirt ( self ) :
2020-08-27 16:37:15 -04: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 11:48:00 -04:00
def testCLINoFirstRun ( self ) :
# Test a simple case of loading without any config override
2020-08-29 13:07:19 -04:00
self . app . open ( first_run = False , enable_libguestfs = None , use_uri = False )
2020-08-28 11:48:00 -04:00
self . sleep ( 2 )
uiutils . check ( lambda : self . app . topwin . showing )
def testCLINoFork ( self ) :
# Test app without forking
2020-08-29 13:07:19 -04:00
self . app . open ( first_run = False , enable_libguestfs = None ,
use_uri = False , no_fork = False )
2020-08-28 11:48:00 -04: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 ( )