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-27 16:37:15 -04:00
from tests import utils
2018-01-19 18:41:00 -05:00
from tests . uitests import utils as uiutils
class Manager ( uiutils . UITestCase ) :
"""
UI tests for manager window , and basic VM lifecycle stuff
"""
##############
# Test cases #
##############
def _testVMLifecycle ( self ) :
"""
2020-08-24 16:03:00 -04:00
Basic VM lifecycle test , shared between standard and no - events
2018-01-19 18:41:00 -05:00
testing
"""
manager = self . app . topwin
shutdown = manager . find ( " Shut Down " , " push button " )
pause = manager . find ( " Pause " , " toggle button " )
run = manager . find ( " Run " , " push button " )
force = manager . find ( " Force Off " , " menu item " )
smenu = manager . find ( " Menu " , " toggle button " )
save = manager . find ( " Save " , " menu item " )
c = manager . find ( " test-many-devices " , " table cell " )
c . click ( )
smenu . click ( )
force . click ( )
2020-08-21 12:55:10 -04:00
self . _click_alert_button ( " Are you sure you want " , " Yes " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : run . sensitive , timeout = 5 )
2018-01-19 18:41:00 -05:00
run . click ( )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not run . sensitive , timeout = 5 )
2018-01-19 18:41:00 -05:00
pause . click ( )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : pause . checked , timeout = 5 )
2020-08-26 07:25:37 -04:00
pause . click ( )
uiutils . check ( lambda : not pause . checked , timeout = 5 )
2018-01-19 18:41:00 -05:00
smenu . click ( )
save . click ( )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : run . sensitive , timeout = 5 )
uiutils . check ( lambda : " Saved " in c . text )
2018-01-19 18:41:00 -05:00
run . click ( )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : shutdown . sensitive , timeout = 5 )
2018-01-19 18:41:00 -05:00
def testVMLifecycle ( self ) :
2020-08-27 16:37:15 -04:00
# qemu hits some different domain code paths for setTime
self . app . uri = utils . URIs . kvm
2018-01-19 18:41:00 -05:00
self . _testVMLifecycle ( )
def testVMNoEventsLifecycle ( self ) :
2020-08-24 16:03:00 -04:00
self . app . open ( extra_opts = [ " --test-options=no-events " ] )
2018-01-19 18:41:00 -05:00
# Change preferences timeout to 1 second
self . app . root . find ( " Edit " , " menu " ) . click ( )
self . app . root . find ( " Preferences " , " menu item " ) . click ( )
win = self . app . root . find_fuzzy ( " Preferences " , " frame " )
win . find ( " Polling " , " page tab " ) . click ( )
2020-08-27 12:23:14 -04:00
win . find ( " cpu-poll " ) . set_text ( " 1 " )
2018-01-19 18:41:00 -05:00
win . find ( " Close " , " push button " ) . click ( )
self . _testVMLifecycle ( )
2020-08-26 13:13:36 -04:00
def testVMLifecycleExtra ( self ) :
"""
Test vmmenu lifecycle options
"""
self . app . open ( keyfile = " confirm-all.ini " )
manager = self . app . topwin
2020-08-27 12:39:20 -04:00
run = manager . find ( " Run " , " push button " )
shutdown = manager . find ( " Shut Down " , " push button " )
pause = manager . find ( " Pause " , " toggle button " )
2020-08-26 13:13:36 -04:00
def confirm_is_running ( ) :
uiutils . check ( lambda : not run . sensitive )
def confirm_is_shutdown ( ) :
uiutils . check ( lambda : not shutdown . sensitive )
def confirm_is_paused ( ) :
uiutils . check ( lambda : pause . checked )
def confirm_not_paused ( ) :
uiutils . check ( lambda : not pause . checked )
def test_action ( action , shutdown = True , confirm = True ) :
def _select ( ) :
2020-08-27 12:39:20 -04:00
cell = manager . find ( " test \n " , " table cell " )
2020-08-26 13:13:36 -04:00
cell . click ( button = 3 )
menu = self . app . root . find ( " vm-action-menu " )
uiutils . check ( lambda : menu . onscreen )
if shutdown :
smenu = menu . find ( " Shut Down " , " menu " )
2020-08-27 12:39:20 -04:00
smenu . point ( )
2020-08-26 13:13:36 -04:00
uiutils . check ( lambda : smenu . onscreen )
item = smenu . find ( action , " menu item " )
else :
item = menu . find ( action , " menu item " )
uiutils . check ( lambda : item . onscreen )
2020-08-27 12:39:20 -04:00
item . point ( )
self . sleep ( .3 )
2020-08-26 13:13:36 -04:00
item . click ( )
_select ( )
if confirm :
self . _click_alert_button ( " Are you sure " , " No " )
_select ( )
self . _click_alert_button ( " Are you sure " , " Yes " )
test_action ( " Force Reset " )
confirm_is_running ( )
test_action ( " Reboot " )
confirm_is_running ( )
test_action ( " Shut Down " )
confirm_is_shutdown ( )
test_action ( " Run " , shutdown = False , confirm = False )
confirm_is_running ( )
test_action ( " Force Off " )
confirm_is_shutdown ( )
test_action ( " Run " , shutdown = False , confirm = False )
confirm_is_running ( )
test_action ( " Pause " , shutdown = False )
confirm_is_paused ( )
test_action ( " Resume " , shutdown = False , confirm = False )
confirm_not_paused ( )
test_action ( " Save " )
confirm_is_shutdown ( )
test_action ( " Restore " , shutdown = False , confirm = False )
confirm_is_running ( )
2020-08-27 16:37:15 -04:00
def testManagerSaveCancelError ( self ) :
2020-08-26 13:13:36 -04:00
"""
Test managed save special behavior
"""
self . app . open ( extra_opts = [ " --test-options=test-managed-save " ] )
manager = self . app . topwin
run = manager . find ( " Run " , " push button " )
smenu = manager . find ( " Menu " , " toggle button " )
save = manager . find ( " Save " , " menu item " )
c = manager . find ( " test-many-devices " , " table cell " )
c . click ( )
# Save it, attempt a cancel operation
smenu . click ( )
save . click ( )
progwin = self . app . root . find ( " Saving Virtual Machine " , " frame " )
# Attempt cancel which will fail, then find the error message
progwin . find ( " Cancel " , " push button " ) . click ( )
progwin . find ( " Error cancelling save job " )
uiutils . check ( lambda : not progwin . showing , timeout = 5 )
uiutils . check ( lambda : run . sensitive )
# Restore will fail and offer to remove managed save
run . click ( )
self . _click_alert_button ( " remove the saved state " , " No " )
uiutils . check ( lambda : run . sensitive )
run . click ( )
self . _click_alert_button ( " remove the saved state " , " Yes " )
uiutils . check ( lambda : not run . sensitive )
2020-08-27 16:37:15 -04:00
def testManagerQEMUSetTime ( self ) :
"""
Fake qemu setTime behavior for code coverage
"""
self . app . uri = utils . URIs . kvm
manager = self . app . topwin
run = manager . find ( " Run " , " push button " )
smenu = manager . find ( " Menu " , " toggle button " )
save = manager . find ( " Save " , " menu item " )
c = manager . find ( " test alternate devs title " , " table cell " )
c . click ( )
# Save -> resume -> save
smenu . click ( )
save . click ( )
uiutils . check ( lambda : run . sensitive )
self . sleep ( 1 )
run . click ( )
uiutils . check ( lambda : not run . sensitive )
self . sleep ( 1 )
smenu . click ( )
save . click ( )
uiutils . check ( lambda : run . sensitive )
self . sleep ( 1 )
2020-08-26 13:26:08 -04:00
def testManagerVMRunFail ( self ) :
# Force VM startup to fail so we can test the error path
self . app . open ( extra_opts = [ " --test-options=test-vm-run-fail " ] )
manager = self . app . topwin
c = manager . find ( " test-clone-simple " , " table cell " )
c . click ( )
manager . find ( " Run " , " push button " ) . click ( )
self . _click_alert_button ( " fake error " , " Close " )
2018-01-19 18:41:00 -05:00
def testManagerColumns ( self ) :
# Enable all stat options
2020-08-26 07:25:37 -04:00
# Need to expand the window size so all columns are onscreen
self . app . open ( keyfile = " winsize.ini " )
2018-01-19 18:41:00 -05:00
self . app . root . find ( " Edit " , " menu " ) . click ( )
self . app . root . find ( " Preferences " , " menu item " ) . click ( )
win = self . app . root . find_fuzzy ( " Preferences " , " frame " )
win . find ( " Polling " , " page tab " ) . click ( )
win . find_fuzzy ( " Poll Disk " , " check " ) . click ( )
win . find_fuzzy ( " Poll Network " , " check " ) . click ( )
win . find_fuzzy ( " Poll Memory " , " check " ) . click ( )
win . find ( " Close " , " push button " ) . click ( )
manager = self . app . topwin
2020-08-26 07:25:37 -04:00
def _test_sort ( name ) :
col = manager . find ( name , " table column header " )
uiutils . check ( lambda : col . onscreen )
# Trigger sorting
col . click ( )
col . click ( )
def _click_column_menu ( name ) :
manager . find ( " View " , " menu " ) . click ( )
menu = manager . find ( " Graph " , " menu " )
menu . point ( )
menu . find_fuzzy ( name , " check menu item " ) . click ( )
def _test_column ( name ) :
_click_column_menu ( name )
_test_sort ( name )
_test_sort ( " Name " )
_click_column_menu ( " Guest CPU " )
_click_column_menu ( " Guest CPU " )
_test_sort ( " CPU usage " )
_test_column ( " Host CPU " )
_test_column ( " Memory " )
_test_column ( " Disk I/O " )
_test_column ( " Network I/O " )
def testManagerWindowReposition ( self ) :
"""
Restore previous position when window is reopened
"""
manager = self . app . topwin
host = self . _open_host_window ( " Storage " )
2020-08-27 16:37:15 -04:00
fmenu = host . find ( " File " , " menu " )
fmenu . click ( )
fmenu . find ( " View Manager " , " menu item " ) . click ( )
uiutils . check ( lambda : manager . active )
2020-08-26 07:25:37 -04:00
# Double click title to maximize
manager . click_title ( )
manager . click_title ( )
newx = manager . position [ 0 ]
newy = manager . position [ 1 ]
manager . keyCombo ( " <alt>F4 " )
host . click_title ( )
host . find ( " File " , " menu " ) . click ( )
host . find ( " View Manager " , " menu item " ) . click ( )
uiutils . check ( lambda : manager . showing )
assert manager . position == ( newx , newy )
2018-03-17 19:42:19 -04:00
def testManagerWindowCleanup ( self ) :
"""
Open migrate , clone , delete , newvm , details , host windows , close the
connection , make sure they all disappear
"""
def _drag ( win ) :
"""
Drag a window so it ' s not obscuring the manager window
"""
2019-06-13 13:50:13 -04:00
uiutils . drag ( win , 1000 , 1000 )
2018-03-17 19:42:19 -04:00
manager = self . app . topwin
# Open migrate dialog
c = manager . find ( " test-many-devices " , " table cell " )
c . click ( button = 3 )
self . app . root . find ( " Migrate... " , " menu item " ) . click ( )
migrate = self . app . root . find ( " Migrate the virtual machine " , " frame " )
_drag ( migrate )
# Open clone dialog
c = manager . find ( " test-clone " , " table cell " )
2020-08-26 07:25:37 -04:00
c . click ( )
self . pressKey ( " Menu " )
2018-03-17 19:42:19 -04:00
self . app . root . find ( " Clone... " , " menu item " ) . click ( )
clone = self . app . root . find ( " Clone Virtual Machine " , " frame " )
_drag ( clone )
# Open delete dialog
c . click ( )
manager . find ( " Edit " , " menu " ) . click ( )
manager . find ( " Delete " , " menu item " ) . click ( )
delete = self . app . root . find_fuzzy ( " Delete " , " frame " )
_drag ( delete )
# Open NewVM
self . app . root . find ( " New " , " push button " ) . click ( )
create = self . app . root . find ( " New VM " , " frame " )
_drag ( create )
# Open host
2020-08-26 07:25:37 -04:00
c = manager . find_fuzzy ( " testdriver.xml " , " table cell " )
c . doubleClick ( )
host = self . app . root . find_fuzzy ( " Connection Details " , " frame " )
2018-03-17 19:42:19 -04:00
_drag ( host )
# Open details
details = self . _open_details_window ( " test-many-devices " )
_drag ( details )
# Close the connection
2020-08-25 08:47:11 -04:00
self . sleep ( 1 )
manager . click ( )
2018-03-17 19:42:19 -04:00
c = manager . find_fuzzy ( " testdriver.xml " , " table cell " )
2020-08-25 08:47:11 -04:00
c . click ( )
2018-03-17 19:42:19 -04:00
c . click ( button = 3 )
self . app . root . find ( " conn-disconnect " , " menu item " ) . click ( )
# Ensure all those windows aren't showing
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not migrate . showing )
uiutils . check ( lambda : not clone . showing )
uiutils . check ( lambda : not create . showing )
uiutils . check ( lambda : not details . showing )
uiutils . check ( lambda : not delete . showing )
2018-03-17 19:42:19 -04:00
# Delete the connection, ensure the host dialog disappears
c = manager . find_fuzzy ( " testdriver.xml " , " table cell " )
c . click ( button = 3 )
self . app . root . find ( " conn-delete " , " menu item " ) . click ( )
2020-08-21 12:55:10 -04:00
self . _click_alert_button ( " will remove the connection " , " Yes " )
2020-08-25 09:48:56 -04:00
uiutils . check ( lambda : not host . showing )
2018-10-07 13:26:13 -04:00
def testManagerDefaultStartup ( self ) :
self . app . open ( use_uri = False )
manager = self . app . topwin
errlabel = manager . find ( " error-label " )
2020-08-25 09:48:56 -04:00
uiutils . check (
2018-10-07 13:26:13 -04:00
lambda : " Checking for virtualization " in errlabel . text )
2020-08-25 09:48:56 -04:00
uiutils . check (
2018-10-07 13:26:13 -04:00
lambda : " File->Add Connection " in errlabel . text )
2020-08-25 09:48:56 -04:00
uiutils . check (
2020-07-13 13:07:06 -04:00
lambda : " appropriate QEMU/KVM " in errlabel . text )
2020-08-26 07:25:37 -04:00
manager . find ( " File " , " menu " ) . click ( )
manager . find ( " Quit " , " menu item " ) . click ( )
def testManagerConnOpenFail ( self ) :
self . app . open ( keyfile = " baduri.ini " )
manager = self . app . topwin
manager . find_fuzzy ( " bad uri " , " table cell " ) . doubleClick ( )
uiutils . check ( lambda : not manager . active )
self . _click_alert_button ( " Unable to connect " , " Close " )
uiutils . check ( lambda : manager . active )