2014-02-06 15:12:12 +04:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
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.
2013-03-18 01:06:52 +04:00
import glob
import traceback
2013-07-12 23:16:29 +04:00
import unittest
2013-03-18 01:06:52 +04:00
import virtinst
2013-04-11 03:48:07 +04:00
from tests import utils
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2020-08-30 15:54:41 +03:00
DATADIR = utils . DATADIR + " /xmlparse/ "
2020-01-27 02:11:43 +03:00
2013-03-18 01:06:52 +04:00
def sanitize_file_xml ( xml ) :
# s/"/'/g from generated XML, matches what libxml dumps out
# This won't work all the time, but should be good enough for testing
return xml . replace ( " ' " , " \" " )
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
class XMLParseTest ( unittest . TestCase ) :
2018-02-22 22:57:10 +03:00
_kvmconn = None
@property
def conn ( self ) :
return utils . URIs . open_testdefault_cached ( )
@property
def kvmconn ( self ) :
if not self . _kvmconn :
self . _kvmconn = utils . URIs . open_kvm ( )
return self . _kvmconn
2013-03-18 01:06:52 +04:00
def _roundtrip_compare ( self , filename ) :
2017-05-05 21:19:54 +03:00
expectXML = sanitize_file_xml ( open ( filename ) . read ( ) )
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . conn , parsexml = expectXML )
2018-08-31 23:52:02 +03:00
actualXML = guest . get_xml ( )
2013-03-18 01:06:52 +04:00
utils . diff_compare ( actualXML , expect_out = expectXML )
2019-06-07 23:06:52 +03:00
def _alter_compare ( self , actualXML , outfile ) :
2013-03-18 01:06:52 +04:00
utils . diff_compare ( actualXML , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , actualXML )
2013-03-18 01:06:52 +04:00
def testRoundTrip ( self ) :
"""
Make sure parsing doesn ' t output different XML
"""
exclude = [ " misc-xml-escaping.xml " ]
failed = False
error = " "
for f in glob . glob ( " tests/xmlconfig-xml/*.xml " ) :
2013-04-12 00:32:00 +04:00
if [ e for e in exclude if f . endswith ( e ) ] :
2013-03-18 01:06:52 +04:00
continue
try :
self . _roundtrip_compare ( f )
except Exception :
failed = True
error + = " %s : \n %s \n " % ( f , " " . join ( traceback . format_exc ( ) ) )
if failed :
raise AssertionError ( " Roundtrip parse tests failed: \n %s " % error )
def _set_and_check ( self , obj , param , initval , * args ) :
"""
Check expected initial value obj . param == initval , then
set newval , and make sure it is returned properly
"""
2019-06-08 01:21:24 +03:00
curval = virtinst . xmlutil . get_prop_path ( obj , param )
2017-05-05 18:39:59 +03:00
self . assertEqual ( initval , curval )
2013-03-18 01:06:52 +04:00
for newval in args :
2019-06-08 01:21:24 +03:00
virtinst . xmlutil . set_prop_path ( obj , param , newval )
curval = virtinst . xmlutil . get_prop_path ( obj , param )
2017-05-05 18:39:59 +03:00
self . assertEqual ( newval , curval )
2013-03-18 01:06:52 +04:00
def _make_checker ( self , obj ) :
def check ( name , initval , * args ) :
return self . _set_and_check ( obj , name , initval , * args )
return check
2019-02-26 12:56:36 +03:00
def _gen_outfile_path ( self , basename ) :
"""
Returns relative path to the file containing the expected XML
output
"""
2020-01-27 02:11:43 +03:00
return DATADIR + " {!s} -out.xml " . format ( basename )
2019-02-26 12:56:36 +03:00
2013-07-12 17:19:28 +04:00
def _get_test_content ( self , basename , kvm = False ) :
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
2019-02-26 12:56:36 +03:00
outfile = self . _gen_outfile_path ( basename )
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( kvm and self . kvmconn or self . conn ,
2017-05-05 21:19:54 +03:00
parsexml = open ( infile ) . read ( ) )
2013-07-12 17:19:28 +04:00
return guest , outfile
2013-03-18 01:06:52 +04:00
def testAlterGuest ( self ) :
"""
Test changing Guest ( ) parameters after parsing
"""
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-guest " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest )
2020-01-27 19:44:52 +03:00
# Check specific vcpu_current behaviro
check ( " vcpus " , 5 , 10 )
assert guest . vcpu_current is None
check ( " vcpu_current " , None , 15 )
guest . vcpus = 12
assert guest . vcpu_current == 12
guest . vcpu_current = 10
2013-03-18 01:06:52 +04:00
check ( " name " , " TestGuest " , " change_name " )
2013-09-24 05:27:42 +04:00
check ( " id " , None , 1234 )
2013-03-18 01:06:52 +04:00
check ( " description " , None , " Hey desc changed& " )
2013-09-24 14:56:16 +04:00
check ( " title " , None , " Hey title changed! " )
2019-05-12 02:15:07 +03:00
check ( " vcpu_cpuset " , " 1-3 " , " 1-8,^6 " , " 1-5,15 " )
2019-05-11 20:34:21 +03:00
check ( " memory " , 409600 , 512000 )
check ( " currentMemory " , 204800 , 1024000 )
check ( " memory " , 1024000 , 2048000 )
2013-03-18 01:06:52 +04:00
check ( " uuid " , " 12345678-1234-1234-1234-123456789012 " ,
" 11111111-2222-3333-4444-555555555555 " )
check ( " emulator " , " /usr/lib/xen/bin/qemu-dm " , " /usr/binnnn/fooemu " )
2013-07-17 21:06:01 +04:00
check ( " type " , " kvm " , " test " )
check ( " bootloader " , None , " pygrub " )
2013-07-18 01:58:24 +04:00
check ( " on_poweroff " , " destroy " , " restart " )
check ( " on_reboot " , " restart " , " destroy " )
2017-02-21 17:27:56 +03:00
check ( " on_crash " , " destroy " , " restart " )
2015-10-07 13:50:13 +03:00
check ( " on_lockfailure " , " poweroff " , " restart " )
2013-03-18 01:06:52 +04:00
2018-09-13 00:10:54 +03:00
check = self . _make_checker ( guest . _metadata . libosinfo ) # pylint: disable=protected-access
2018-09-29 23:04:05 +03:00
check ( " os_id " , " http://fedoraproject.org/fedora/17 " )
2019-06-14 03:56:16 +03:00
guest . set_os_name ( " fedora10 " )
2018-10-01 02:12:19 +03:00
check ( " os_id " , " http://fedoraproject.org/fedora/10 " )
self . assertEqual ( guest . osinfo . name , " fedora10 " )
2018-09-29 23:04:05 +03:00
guest . set_os_name ( " generic " )
check ( " os_id " , None , " frib " )
self . assertEqual ( guest . osinfo . name , " generic " )
2018-09-13 00:10:54 +03:00
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . clock )
check ( " offset " , " utc " , " localtime " )
2018-02-08 01:27:56 +03:00
guest . clock . remove_child ( guest . clock . timers [ 0 ] )
2013-10-06 00:05:31 +04:00
check = self . _make_checker ( guest . clock . timers [ 0 ] )
check ( " name " , " pit " , " rtc " )
check ( " tickpolicy " , " delay " , " merge " )
2018-02-08 01:27:56 +03:00
timer = guest . clock . timers . add_new ( )
2013-10-06 00:05:31 +04:00
check = self . _make_checker ( timer )
check ( " name " , None , " hpet " )
check ( " present " , None , False )
2013-03-18 01:06:52 +04:00
2014-02-03 01:12:29 +04:00
check = self . _make_checker ( guest . pm )
check ( " suspend_to_mem " , False , True )
check ( " suspend_to_disk " , None , False )
2013-07-17 15:53:47 +04:00
check = self . _make_checker ( guest . os )
2013-03-18 01:06:52 +04:00
check ( " os_type " , " hvm " , " xen " )
check ( " arch " , " i686 " , None )
check ( " machine " , " foobar " , " pc-0.11 " )
check ( " loader " , None , " /foo/loader " )
check ( " init " , None , " /sbin/init " )
check ( " bootorder " , [ " hd " ] , [ " fd " ] )
check ( " enable_bootmenu " , None , False )
2013-09-04 19:57:26 +04:00
check ( " useserial " , None , True )
2013-03-18 01:06:52 +04:00
check ( " kernel " , None )
check ( " initrd " , None )
check ( " kernel_args " , None )
2014-06-01 01:15:03 +04:00
guest . os . set_initargs_string ( " foo ' bar baz ' frib " )
self . assertEqual ( [ i . val for i in guest . os . initargs ] ,
[ " foo " , " bar baz " , " frib " ] )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . features )
check ( " acpi " , True , False )
2013-09-27 23:35:27 +04:00
check ( " apic " , True , True )
check ( " eoi " , None , True )
check ( " pae " , False , False )
check ( " viridian " , False , True )
check ( " hap " , False , False )
check ( " privnet " , False , False )
check ( " hyperv_relaxed " , None , True )
check ( " hyperv_vapic " , False , None )
check ( " hyperv_spinlocks " , True , True )
check ( " hyperv_spinlocks_retries " , 12287 , 54321 )
2015-04-03 01:04:08 +03:00
check ( " vmport " , False , True )
2019-05-12 02:57:33 +03:00
check ( " vmcoreinfo " , None , True )
2015-09-08 13:03:04 +03:00
check ( " kvm_hidden " , None , True )
2015-10-01 10:07:42 +03:00
check ( " pvspinlock " , None , True )
2016-06-10 03:22:25 +03:00
check ( " gic_version " , None , False )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . cpu )
check ( " match " , " exact " , " strict " )
2019-03-14 12:48:21 +03:00
guest . cpu . set_model ( guest , " qemu64 " )
2019-03-14 12:46:02 +03:00
check ( " model " , " qemu64 " )
2013-03-18 01:06:52 +04:00
check ( " vendor " , " Intel " , " qemuvendor " )
2020-08-28 01:02:10 +03:00
check ( " topology.threads " , 2 , 1 )
check ( " topology.cores " , 5 , 3 )
guest . cpu . topology . sockets = 4.0
check ( " topology.sockets " , 4 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . cpu . features [ 0 ] )
2013-07-18 01:11:18 +04:00
check ( " name " , " x2apic " )
2013-03-18 01:06:52 +04:00
check ( " policy " , " force " , " disable " )
2013-09-11 02:32:10 +04:00
rmfeat = guest . cpu . features [ 3 ]
2018-02-08 01:27:56 +03:00
guest . cpu . remove_child ( rmfeat )
2018-08-31 23:52:02 +03:00
self . assertEqual ( rmfeat . get_xml ( ) ,
2013-09-19 21:48:28 +04:00
""" <feature name= " foo " policy= " bar " /> \n """ )
2013-03-18 01:06:52 +04:00
guest . cpu . add_feature ( " addfeature " )
check = self . _make_checker ( guest . numatune )
check ( " memory_mode " , " interleave " , " strict " , None )
check ( " memory_nodeset " , " 1-5,^3,7 " , " 2,4,6 " )
2014-02-25 06:02:31 +04:00
check = self . _make_checker ( guest . memtune )
check ( " hard_limit " , None , 1024 , 2048 )
check ( " soft_limit " , None , 100 , 200 )
check ( " swap_hard_limit " , None , 300 , 400 )
check ( " min_guarantee " , None , 400 , 500 )
2014-02-06 18:41:00 +04:00
check = self . _make_checker ( guest . blkiotune )
check ( " weight " , None , 100 , 200 )
2019-05-15 16:59:25 +03:00
check = self . _make_checker ( guest . blkiotune . devices . add_new ( ) )
check ( " weight " , None , 300 )
check ( " path " , None , " /home/1.img " )
2014-02-06 18:41:00 +04:00
2014-02-09 19:25:25 +04:00
check = self . _make_checker ( guest . idmap )
check ( " uid_start " , None , 0 )
check ( " uid_target " , None , 1000 )
check ( " uid_count " , None , 10 )
check ( " gid_start " , None , 0 )
check ( " gid_target " , None , 1000 )
check ( " gid_count " , None , 10 )
2014-06-04 06:08:05 +04:00
check = self . _make_checker ( guest . resource )
check ( " partition " , None , " /virtualmachines/production " )
2018-03-21 00:23:34 +03:00
check = self . _make_checker ( guest . devices . memballoon [ 0 ] )
2013-03-18 01:06:52 +04:00
check ( " model " , " virtio " , " none " )
2014-03-22 14:15:46 +04:00
check = self . _make_checker ( guest . memoryBacking )
check ( " hugepages " , False , True )
check ( " nosharepages " , False , True )
check ( " locked " , False , True )
2019-05-14 22:45:16 +03:00
page = guest . memoryBacking . pages . add_new ( )
check = self . _make_checker ( page )
check ( " size " , None , 1 )
check ( " unit " , None , " G " )
2020-01-27 19:44:52 +03:00
assert guest . is_full_os_container ( ) is False
2018-09-01 01:30:43 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2015-05-04 01:08:10 +03:00
def testSeclabel ( self ) :
guest , outfile = self . _get_test_content ( " change-seclabel " )
2016-06-12 18:09:15 +03:00
check = self . _make_checker ( guest . seclabels [ 0 ] )
2015-05-04 01:08:10 +03:00
check ( " type " , " static " , " none " )
check ( " model " , " selinux " , " apparmor " )
check ( " label " , " foolabel " , " barlabel " )
check ( " baselabel " , None , " baselabel " )
check ( " relabel " , None , False )
2016-06-12 18:09:15 +03:00
guest . remove_child ( guest . seclabels [ 1 ] )
2015-05-04 01:08:10 +03:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2015-05-04 01:08:10 +03:00
2013-03-18 01:06:52 +04:00
def testAlterMinimalGuest ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-minimal-guest " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . features )
check ( " acpi " , False , True )
check ( " pae " , False )
self . assertTrue (
2018-08-31 23:52:02 +03:00
guest . features . get_xml ( ) . startswith ( " <features " ) )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . clock )
check ( " offset " , None , " utc " )
2018-08-31 23:52:02 +03:00
self . assertTrue ( guest . clock . get_xml ( ) . startswith ( " <clock " ) )
2013-03-18 01:06:52 +04:00
2018-03-20 22:10:04 +03:00
seclabel = virtinst . DomainSeclabel ( guest . conn )
2015-05-04 01:08:10 +03:00
guest . add_child ( seclabel )
seclabel . model = " testSecurity "
seclabel . type = " static "
seclabel . label = " frob "
2013-03-18 01:06:52 +04:00
self . assertTrue (
2018-08-31 23:52:02 +03:00
guest . seclabels [ 0 ] . get_xml ( ) . startswith ( " <seclabel " ) )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . cpu )
2019-03-14 12:46:02 +03:00
check ( " model " , None )
2019-03-14 12:48:21 +03:00
guest . cpu . set_model ( guest , " foobar " )
2019-03-14 12:46:02 +03:00
check ( " model " , " foobar " )
2015-03-27 00:08:15 +03:00
check ( " model_fallback " , None , " allow " )
2020-08-28 01:02:10 +03:00
check ( " topology.cores " , None , 4 )
2013-03-18 01:06:52 +04:00
guest . cpu . add_feature ( " x2apic " , " forbid " )
guest . cpu . set_topology_defaults ( guest . vcpus )
2018-08-31 23:52:02 +03:00
self . assertTrue ( guest . cpu . get_xml ( ) . startswith ( " <cpu " ) )
2018-03-21 21:42:50 +03:00
self . assertEqual ( guest . cpu . get_xml_id ( ) , " ./cpu " )
self . assertEqual ( guest . cpu . get_xml_idx ( ) , 0 )
self . assertEqual ( guest . get_xml_id ( ) , " . " )
self . assertEqual ( guest . get_xml_idx ( ) , 0 )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . assertTrue ( guest . os . get_xml ( ) . startswith ( " <os " ) )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterBootMulti ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-boot-multi " )
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
check = self . _make_checker ( guest . os )
2013-03-18 01:06:52 +04:00
check ( " bootorder " , [ ' hd ' , ' fd ' , ' cdrom ' , ' network ' ] , [ " cdrom " ] )
check ( " enable_bootmenu " , False , True )
2014-09-23 22:25:14 +04:00
check ( " kernel " , None , " /foo.img " )
check ( " initrd " , None , " /bar.img " )
2013-08-17 03:25:26 +04:00
check ( " dtb " , None , " /baz.dtb " )
2013-03-18 01:06:52 +04:00
check ( " kernel_args " , None , " ks=foo.ks " )
2019-06-09 23:39:15 +03:00
guest . os . set_initargs_string ( " foo bar " )
guest . os . set_initargs_string ( " baz wibble " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterBootKernel ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-boot-kernel " )
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
check = self . _make_checker ( guest . os )
2013-03-18 01:06:52 +04:00
check ( " bootorder " , [ ] , [ " network " , " hd " , " fd " ] )
check ( " enable_bootmenu " , None )
check ( " kernel " , " /boot/vmlinuz " , None )
check ( " initrd " , " /boot/initrd " , None )
check ( " kernel_args " , " location " , None )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2014-09-11 20:39:24 +04:00
def testAlterBootUEFI ( self ) :
guest , outfile = self . _get_test_content ( " change-boot-uefi " )
check = self . _make_checker ( guest . os )
check ( " bootorder " , [ ] , [ " network " , " hd " , " fd " ] )
check ( " loader_ro " , None , True )
check ( " loader_type " , None , " pflash " )
check ( " nvram " , None , " /tmp/nvram_store " )
check ( " nvram_template " , None , " /tmp/template " )
check ( " loader " , None , " OVMF_CODE.fd " )
check ( " kernel " , " /boot/vmlinuz " , None )
check ( " initrd " , " /boot/initrd " , None )
check ( " kernel_args " , " location " , None )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2014-09-11 20:39:24 +04:00
2013-04-11 09:45:46 +04:00
def testAlterCpuMode ( self ) :
2020-01-27 16:59:02 +03:00
xml = open ( DATADIR + " change-cpumode-in.xml " ) . read ( )
outfile = DATADIR + " change-cpumode-out.xml "
conn = utils . URIs . openconn ( utils . URIs . kvm_q35 )
guest = virtinst . Guest ( conn , xml )
2013-04-11 09:45:46 +04:00
check = self . _make_checker ( guest . cpu )
2020-01-27 16:59:02 +03:00
guest . cpu . model = " foo "
2019-03-14 14:03:53 +03:00
check ( " mode " , " host-passthrough " )
2019-04-10 21:36:31 +03:00
guest . cpu . check_security_features ( guest )
check ( " secure " , False )
2019-03-14 14:03:53 +03:00
guest . cpu . set_special_mode ( guest , " host-model " )
check ( " mode " , " host-model " )
2019-04-10 21:36:31 +03:00
guest . cpu . check_security_features ( guest )
check ( " secure " , False )
2019-03-14 12:48:21 +03:00
guest . cpu . set_model ( guest , " qemu64 " )
2019-03-14 12:46:02 +03:00
check ( " model " , " qemu64 " )
2019-04-10 21:36:31 +03:00
guest . cpu . check_security_features ( guest )
check ( " secure " , False )
2013-04-11 09:45:46 +04:00
2020-01-27 16:59:02 +03:00
# Test actually filling in security values, and removing them
guest . cpu . secure = True
guest . cpu . set_model ( guest , " Skylake-Client-IBRS " )
guest . cpu . check_security_features ( guest )
check ( " secure " , True )
guest . cpu . set_model ( guest , " EPYC-IBPB " )
guest . cpu . check_security_features ( guest )
check ( " secure " , True )
guest . cpu . secure = False
guest . cpu . set_model ( guest , " Skylake-Client-IBRS " )
guest . cpu . check_security_features ( guest )
check ( " secure " , False )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-04-11 09:45:46 +04:00
2020-01-27 16:59:02 +03:00
# Hits a codepath when domcaps don't provide the needed info
guest = virtinst . Guest ( self . conn , xml )
guest . cpu . check_security_features ( guest )
assert guest . cpu . secure is False
2013-03-18 01:06:52 +04:00
def testAlterDisk ( self ) :
"""
2018-03-20 19:18:35 +03:00
Test changing DeviceDisk ( ) parameters after parsing
2013-03-18 01:06:52 +04:00
"""
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-disk " )
2013-03-18 01:06:52 +04:00
2014-12-07 04:36:12 +03:00
def _get_disk ( target ) :
2018-03-21 00:23:34 +03:00
for disk in guest . devices . disk :
2014-12-07 04:36:12 +03:00
if disk . target == target :
return disk
disk = _get_disk ( " hda " )
check = self . _make_checker ( disk )
2019-07-04 01:26:57 +03:00
check ( " path " , " /tmp/test.img " , " /dev/foo/null " )
2014-12-07 04:36:12 +03:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
check ( " driver_name " , None , " test " )
check ( " driver_type " , None , " raw " )
check ( " serial " , " WD-WMAP9A966149 " , " frob " )
2019-05-17 18:26:02 +03:00
check ( " wwn " , None , " 123456789abcdefa " )
2013-10-04 05:38:58 +04:00
check ( " bus " , " ide " , " usb " )
check ( " removable " , None , False , True )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 1 ]
2016-06-12 18:09:15 +03:00
check = self . _make_checker ( disk . seclabels [ 1 ] )
2015-09-05 21:40:45 +03:00
check ( " model " , " dac " )
2016-06-12 00:43:18 +03:00
check ( " relabel " , None , True )
check ( " label " , None , " foo-my-label " )
2015-09-05 21:40:45 +03:00
2014-12-07 04:36:12 +03:00
disk = _get_disk ( " hdc " )
check = self . _make_checker ( disk )
2013-07-15 01:54:01 +04:00
check ( " type " , " block " , " dir " , " file " , " block " )
2013-09-26 16:47:01 +04:00
check ( " path " , " /dev/null " , None )
2014-12-07 04:36:12 +03:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
check ( " device " , " cdrom " , " floppy " )
check ( " read_only " , True , False )
2013-07-14 17:15:24 +04:00
check ( " target " , " hdc " , " fde " )
check ( " bus " , " ide " , " fdc " )
2013-03-18 01:06:52 +04:00
check ( " error_policy " , " stop " , None )
2015-03-13 16:38:20 +03:00
disk = _get_disk ( " hdd " )
check = self . _make_checker ( disk )
check ( " type " , " block " )
check ( " device " , " lun " )
check ( " sgio " , None , " unfiltered " )
2019-05-20 14:43:34 +03:00
check ( " rawio " , None , " yes " )
2015-03-13 16:38:20 +03:00
2014-12-07 02:33:11 +03:00
disk = _get_disk ( " sda " )
check = self . _make_checker ( disk )
2014-12-09 17:20:18 +03:00
check ( " path " , None , " http://[1:2:3:4:5:6:7:8]:1122/my/file " )
2014-12-07 02:33:11 +03:00
disk . sync_path_props ( )
2014-12-07 04:36:12 +03:00
disk = _get_disk ( " fda " )
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/default-pool/default-vol " )
2014-12-07 04:36:12 +03:00
disk . sync_path_props ( )
2014-12-05 00:30:18 +03:00
check ( " startup_policy " , None , " optional " )
2013-03-18 01:06:52 +04:00
check ( " shareable " , False , True )
check ( " driver_cache " , None , " writeback " )
check ( " driver_io " , None , " threads " )
check ( " driver_io " , " threads " , " native " )
2014-04-29 18:29:33 +04:00
check ( " driver_discard " , None , " unmap " )
2018-08-24 02:40:18 +03:00
check ( " driver_detect_zeroes " , None , " unmap " )
2013-07-12 18:49:15 +04:00
check ( " iotune_ris " , 1 , 0 )
check ( " iotune_rbs " , 2 , 0 )
check ( " iotune_wis " , 3 , 0 )
check ( " iotune_wbs " , 4 , 0 )
2013-07-14 05:49:32 +04:00
check ( " iotune_tis " , None , 5 )
check ( " iotune_tbs " , None , 6 )
2014-12-07 04:36:12 +03:00
check = self . _make_checker ( disk . boot )
2014-02-09 22:36:12 +04:00
check ( " order " , None , 7 , None )
2013-03-18 01:06:52 +04:00
2014-12-07 04:36:12 +03:00
disk = _get_disk ( " vdb " )
check = self . _make_checker ( disk )
2014-12-05 00:30:18 +03:00
check ( " source_pool " , " defaultPool " , " anotherPool " )
2014-12-07 02:33:11 +03:00
check ( " source_volume " , " foobar " , " newvol " )
disk = _get_disk ( " vdc " )
check = self . _make_checker ( disk )
check ( " source_protocol " , " rbd " , " gluster " )
check ( " source_name " , " pool/image " , " new-val/vol " )
check ( " source_host_name " , " mon1.example.org " , " diff.example.org " )
check ( " source_host_port " , 6321 , 1234 )
check ( " path " , " gluster://diff.example.org:1234/new-val/vol " )
disk = _get_disk ( " vdd " )
check = self . _make_checker ( disk )
check ( " source_protocol " , " nbd " )
check ( " source_host_transport " , " unix " )
check ( " source_host_socket " , " /var/run/nbdsock " )
check ( " path " , " nbd+unix:///var/run/nbdsock " )
2014-09-26 17:24:34 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2019-02-26 12:56:38 +03:00
def testAlterDevicesBootorder ( self ) :
basename = " change-devices-bootorder "
guest , outfile = self . _get_test_content ( basename )
disk_1 = guest . devices . disk [ 0 ]
disk_2 = guest . devices . disk [ 1 ]
disk_3 = guest . devices . disk [ 2 ]
disk_4 = guest . devices . disk [ 3 ]
iface_1 = guest . devices . interface [ 0 ]
iface_2 = guest . devices . interface [ 1 ]
redirdev_1 = guest . devices . redirdev [ 0 ]
self . assertEqual ( guest . os . bootorder , [ ' hd ' ] )
self . assertEqual ( disk_1 . boot . order , None )
self . assertEqual ( disk_2 . boot . order , 10 )
self . assertEqual ( disk_3 . boot . order , 10 )
self . assertEqual ( disk_4 . boot . order , 1 )
self . assertEqual ( iface_1 . boot . order , 2 )
self . assertEqual ( iface_2 . boot . order , None )
self . assertEqual ( redirdev_1 . boot . order , 3 )
guest . reorder_boot_order ( disk_1 , 1 )
self . assertEqual ( guest . os . bootorder , [ ] )
self . assertEqual ( disk_1 . boot . order , 1 )
self . assertEqual ( disk_2 . boot . order , 10 )
self . assertEqual ( disk_3 . boot . order , 10 )
# verify that the used algorithm preserves the order of
# records with equal boot indices
self . assertIs ( disk_2 , guest . devices . disk [ 1 ] )
self . assertIs ( disk_3 , guest . devices . disk [ 2 ] )
self . assertEqual ( disk_4 . boot . order , 2 )
self . assertEqual ( iface_1 . boot . order , 3 )
self . assertEqual ( iface_2 . boot . order , None )
self . assertEqual ( redirdev_1 . boot . order , 4 )
try :
self . _alter_compare ( guest . get_xml ( ) , outfile )
except RuntimeError as error :
self . assertIn ( " unsupported configuration " , str ( error ) )
guest . reorder_boot_order ( disk_2 , 10 )
self . assertEqual ( disk_2 . boot . order , 10 )
self . assertEqual ( disk_3 . boot . order , 11 )
self . assertIs ( disk_2 , guest . devices . disk [ 1 ] )
self . assertIs ( disk_3 , guest . devices . disk [ 2 ] )
outfile = self . _gen_outfile_path ( " change-devices-bootorder-fixed " )
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testSingleDisk ( self ) :
2013-09-19 21:48:28 +04:00
xml = ( """ <disk type= " file " device= " disk " ><source file= " /a.img " /> \n """
""" <target dev= " hda " bus= " ide " /></disk> \n """ )
2018-03-20 19:18:35 +03:00
d = virtinst . DeviceDisk ( self . conn , parsexml = xml )
2013-03-18 01:06:52 +04:00
self . _set_and_check ( d , " target " , " hda " , " hdb " )
2018-08-31 23:52:02 +03:00
self . assertEqual ( xml . replace ( " hda " , " hdb " ) , d . get_xml ( ) )
2013-03-18 01:06:52 +04:00
def testAlterChars ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-chars " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
serial1 = guest . devices . serial [ 0 ]
serial2 = guest . devices . serial [ 1 ]
parallel1 = guest . devices . parallel [ 0 ]
parallel2 = guest . devices . parallel [ 1 ]
console1 = guest . devices . console [ 0 ]
console2 = guest . devices . console [ 1 ]
channel1 = guest . devices . channel [ 0 ]
channel2 = guest . devices . channel [ 1 ]
channel3 = guest . devices . channel [ 2 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( serial1 )
2013-07-16 17:14:37 +04:00
check ( " type " , " null " , " udp " )
2019-05-13 21:23:27 +03:00
check ( " source.bind_host " , None , " example.com " )
check ( " source.bind_service " , None , 66 )
check ( " source.connect_host " , None , " example.com.uk " )
check ( " source.connect_service " , None , 77 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( serial2 )
2013-07-16 17:14:37 +04:00
check ( " type " , " tcp " )
2019-05-13 22:14:25 +03:00
check ( " source.protocol " , " telnet " , " raw " )
2019-05-13 21:23:27 +03:00
check ( " source.mode " , " bind " , " connect " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( parallel1 )
2019-05-13 21:23:27 +03:00
check ( " source.mode " , " bind " )
check ( " source.path " , " /tmp/foobar " , None )
2013-07-16 17:14:37 +04:00
check ( " type " , " unix " , " pty " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( parallel2 )
2013-07-16 17:14:37 +04:00
check ( " type " , " udp " )
2019-05-13 21:23:27 +03:00
check ( " source.bind_service " , 1111 , 1357 )
check ( " source.bind_host " , " my.bind.host " , " my.foo.host " )
check ( " source.connect_service " , 2222 , 7777 )
check ( " source.connect_host " , " my.source.host " , " source.foo.host " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( console1 )
2013-07-16 17:14:37 +04:00
check ( " type " , " pty " )
2013-03-18 01:06:52 +04:00
check ( " target_type " , None )
check = self . _make_checker ( console2 )
2013-07-16 17:14:37 +04:00
check ( " type " , " file " )
2019-05-13 21:23:27 +03:00
check ( " source.path " , " /tmp/foo.img " , None )
check ( " source.path " , None , " /root/foo " )
2013-03-18 01:06:52 +04:00
check ( " target_type " , " virtio " )
2018-07-04 11:10:38 +03:00
check ( " target_state " , None , " connected " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( channel1 )
2013-07-16 17:14:37 +04:00
check ( " type " , " pty " )
check ( " target_type " , " virtio " , " bar " , " virtio " )
2013-03-18 01:06:52 +04:00
check ( " target_name " , " foo.bar.frob " , " test.changed " )
check = self . _make_checker ( channel2 )
2013-07-16 17:14:37 +04:00
check ( " type " , " unix " , " foo " , " unix " )
2013-03-18 01:06:52 +04:00
check ( " target_type " , " guestfwd " )
check ( " target_address " , " 1.2.3.4 " , " 5.6.7.8 " )
2013-07-16 17:14:37 +04:00
check ( " target_port " , 4567 , 1199 )
2013-03-18 01:06:52 +04:00
2014-03-25 18:42:32 +04:00
check = self . _make_checker ( channel3 )
check ( " type " , " spiceport " )
2019-05-13 21:23:27 +03:00
check ( " source.channel " , " org.spice-space.webdav.0 " , " test.1 " )
2014-03-25 18:42:32 +04:00
check ( " target_type " , " virtio " )
check ( " target_name " , " org.spice-space.webdav.0 " , " test.2 " )
2018-03-21 21:42:50 +03:00
self . assertEqual ( channel3 . get_xml_id ( ) , " ./devices/channel[3] " )
self . assertEqual ( channel3 . get_xml_idx ( ) , 2 )
2014-03-25 18:42:32 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterControllers ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-controllers " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . controller [ 0 ]
dev2 = guest . devices . controller [ 1 ]
dev3 = guest . devices . controller [ 2 ]
dev4 = guest . devices . controller [ 3 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , " ide " )
2013-07-16 05:52:18 +04:00
check ( " index " , 3 , 1 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 )
check ( " type " , " virtio-serial " )
2013-07-16 05:52:18 +04:00
check ( " index " , 0 , 7 )
check ( " ports " , 32 , 5 )
check ( " vectors " , 17 , None )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev3 )
check ( " type " , " scsi " )
2013-07-16 05:52:18 +04:00
check ( " index " , 1 , 2 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev4 )
2013-07-16 05:52:18 +04:00
check ( " type " , " usb " , " foo " , " usb " )
check ( " index " , 3 , 9 )
check ( " model " , " ich9-ehci1 " , " ich9-uhci1 " )
check ( " master_startport " , 4 , 2 )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterNics ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-nics " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . interface [ 0 ]
dev2 = guest . devices . interface [ 1 ]
dev3 = guest . devices . interface [ 2 ]
dev4 = guest . devices . interface [ 3 ]
dev5 = guest . devices . interface [ 4 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , " user " )
2019-04-17 17:07:35 +03:00
check ( " model " , None , " vmxnet3 " )
2013-09-24 18:00:01 +04:00
check ( " source " , None , None , )
2013-03-18 01:06:52 +04:00
check ( " macaddr " , " 22:11:11:11:11:11 " , " AA:AA:AA:AA:AA:AA " )
2013-08-28 19:36:25 +04:00
check ( " filterref " , None , " foo " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 )
2013-09-24 18:00:01 +04:00
check ( " source " , " default " , None )
2013-03-18 01:06:52 +04:00
check ( " type " , " network " , " bridge " )
2013-09-24 18:00:01 +04:00
check ( " source " , None , " newbr0 " )
2013-03-18 01:06:52 +04:00
check ( " model " , " e1000 " , " virtio " )
check = self . _make_checker ( dev3 )
check ( " type " , " bridge " )
2013-09-24 18:00:01 +04:00
check ( " source " , " foobr0 " , " newfoo0 " )
2013-03-18 01:06:52 +04:00
check ( " macaddr " , " 22:22:22:22:22:22 " )
check ( " target_dev " , None , " test1 " )
check = self . _make_checker ( dev4 )
check ( " type " , " ethernet " )
check ( " target_dev " , " nic02 " , " nic03 " )
check ( " target_dev " , " nic03 " , None )
check = self . _make_checker ( dev5 )
check ( " type " , " direct " )
2013-09-24 18:00:01 +04:00
check ( " source " , " eth0.1 " )
2013-03-18 01:06:52 +04:00
check ( " source_mode " , " vepa " , " bridge " )
2014-05-31 22:30:07 +04:00
check ( " portgroup " , None , " sales " )
2014-02-01 16:48:04 +04:00
check ( " driver_name " , None , " vhost " )
check ( " driver_queues " , None , 5 )
2013-03-18 01:06:52 +04:00
virtualport = dev5 . virtualport
check = self . _make_checker ( virtualport )
2013-07-15 21:08:58 +04:00
check ( " type " , " 802.1Qbg " , " foo " , " 802.1Qbg " )
check ( " managerid " , 12 , 11 )
check ( " typeid " , 1193046 , 1193047 )
check ( " typeidversion " , 1 , 2 )
2013-03-18 01:06:52 +04:00
check ( " instanceid " , " 09b11c53-8b5c-4eeb-8f00-d84eaa0aaa3b " ,
" 09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterInputs ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-inputs " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . input [ 0 ]
dev2 = guest . devices . input [ 1 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , " mouse " , " tablet " )
check ( " bus " , " ps2 " , " usb " )
check = self . _make_checker ( dev2 )
check ( " type " , " tablet " , " mouse " )
check ( " bus " , " usb " , " xen " )
check ( " bus " , " xen " , " usb " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterGraphics ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-graphics " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . graphics [ 0 ]
dev2 = guest . devices . graphics [ 1 ]
dev3 = guest . devices . graphics [ 2 ]
dev4 = guest . devices . graphics [ 3 ]
dev5 = guest . devices . graphics [ 4 ]
dev6 = guest . devices . graphics [ 5 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , " vnc " )
check ( " passwd " , " foobar " , " newpass " )
check ( " port " , 100 , 6000 )
check ( " listen " , " 0.0.0.0 " , " 1.2.3.4 " )
2013-07-16 02:53:53 +04:00
check ( " keymap " , None , " en-us " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 )
2014-02-06 15:12:12 +04:00
check ( " type " , " vnc " )
2013-03-18 01:06:52 +04:00
check ( " xauth " , " /tmp/.Xauthority " , " fooauth " )
check ( " display " , " 1:2 " , " 6:1 " )
check = self . _make_checker ( dev3 )
2013-07-16 02:53:53 +04:00
check ( " type " , " rdp " , " vnc " )
2014-01-29 17:18:01 +04:00
check ( " listen " , " 1.1.2.3 " , None )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev4 )
check ( " type " , " vnc " )
check ( " port " , - 1 )
check ( " socket " , " /tmp/foobar " , " /var/lib/libvirt/socket/foo " )
check = self . _make_checker ( dev5 )
2013-07-16 02:53:53 +04:00
check ( " autoport " , True , False )
2014-01-29 17:18:01 +04:00
check = self . _make_checker ( dev5 . listens [ 0 ] )
2020-01-27 19:44:52 +03:00
dev5 . listens [ 0 ] . type = " none "
assert guest . has_listen_none ( ) is True
check ( " type " , " none " , " foo " , " network " )
2014-01-29 17:18:01 +04:00
check ( " network " , " Bobsnetwork " , " mynewnet " )
2013-07-16 02:53:53 +04:00
2014-01-29 17:18:01 +04:00
check = self . _make_checker ( dev6 . listens [ 0 ] )
check ( " type " , " address " )
check ( " address " , " 0.0.0.0 " )
2013-07-16 02:53:53 +04:00
check = self . _make_checker ( dev6 )
2013-03-18 01:06:52 +04:00
check ( " type " , " spice " )
check ( " passwd " , " foobar " , " newpass " )
2014-01-29 18:52:49 +04:00
check ( " connected " , None , " disconnect " )
2013-03-18 01:06:52 +04:00
check ( " port " , 100 , 6000 )
check ( " tlsPort " , 101 , 6001 )
check ( " listen " , " 0.0.0.0 " , " 1.2.3.4 " )
check ( " channel_inputs_mode " , " insecure " , " secure " )
check ( " channel_main_mode " , " secure " , " any " )
check ( " channel_record_mode " , " any " , " insecure " )
2013-07-16 02:53:53 +04:00
check ( " channel_display_mode " , " any " , " secure " )
check ( " channel_cursor_mode " , " any " , " any " )
check ( " channel_playback_mode " , " any " , " insecure " )
2013-03-18 01:06:52 +04:00
check ( " passwdValidTo " , " 2010-04-09T15:51:00 " , " 2011-01-07T19:08:00 " )
2014-02-28 02:43:59 +04:00
check ( " defaultMode " , None , " secure " )
2015-04-11 23:56:27 +03:00
check ( " image_compression " , None , " auto_glz " )
check ( " streaming_mode " , None , " filter " )
check ( " clipboard_copypaste " , None , True )
check ( " mouse_mode " , None , " client " )
check ( " filetransfer_enable " , None , False )
2016-03-04 14:31:51 +03:00
check ( " gl " , None , True )
2017-02-21 16:01:00 +03:00
check ( " rendernode " , None , " /dev/dri/foo " )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterVideos ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-videos " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . video [ 0 ]
dev2 = guest . devices . video [ 1 ]
dev3 = guest . devices . video [ 2 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
2013-07-15 19:07:40 +04:00
check ( " model " , " vmvga " , " vga " )
check ( " vram " , None , 1000 )
check ( " heads " , None , 1 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 )
2013-07-15 19:07:40 +04:00
check ( " model " , " cirrus " , " vmvga " )
check ( " vram " , 10240 , None )
check ( " heads " , 3 , 5 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev3 )
2013-07-15 19:07:40 +04:00
check ( " model " , " cirrus " , " cirrus " , " qxl " )
check ( " ram " , None , 100 )
2014-12-01 17:56:29 +03:00
check ( " vgamem " , None , 8192 )
2016-03-04 14:31:52 +03:00
check ( " accel3d " , None , True )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterHostdevs ( self ) :
2020-01-27 02:11:43 +03:00
infile = DATADIR + " change-hostdevs-in.xml "
outfile = DATADIR + " change-hostdevs-out.xml "
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . conn ,
2017-05-05 21:19:54 +03:00
parsexml = open ( infile ) . read ( ) )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . hostdev [ 0 ]
dev2 = guest . devices . hostdev [ 1 ]
dev3 = guest . devices . hostdev [ 2 ]
dev4 = guest . devices . hostdev [ 3 ]
2018-06-15 12:29:34 +03:00
dev5 = guest . devices . hostdev [ 4 ]
2018-06-15 12:29:35 +03:00
dev6 = guest . devices . hostdev [ 5 ]
2018-06-15 12:29:36 +03:00
dev7 = guest . devices . hostdev [ 6 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
2013-07-16 01:45:43 +04:00
check ( " type " , " usb " , " foo " , " usb " )
2013-03-18 01:06:52 +04:00
check ( " managed " , True , False )
check ( " mode " , " subsystem " , None )
check ( " vendor " , " 0x4321 " , " 0x1111 " )
check ( " product " , " 0x1234 " , " 0x2222 " )
check ( " bus " , None , " 1 " )
check ( " device " , None , " 2 " )
check = self . _make_checker ( dev2 )
check ( " type " , " usb " )
check ( " managed " , False , True )
check ( " mode " , " capabilities " , " subsystem " )
check ( " bus " , " 0x12 " , " 0x56 " )
check ( " device " , " 0x34 " , " 0x78 " )
check = self . _make_checker ( dev3 )
check ( " type " , " pci " )
check ( " managed " , True , True )
2013-04-08 12:39:59 +04:00
check ( " mode " , " subsystem " , " subsystem " )
2013-03-18 01:06:52 +04:00
check ( " domain " , " 0x0 " , " 0x4 " )
check ( " bus " , " 0x1 " , " 0x5 " )
check ( " slot " , " 0x2 " , " 0x6 " )
check ( " function " , " 0x3 " , " 0x7 " )
2014-01-15 03:09:21 +04:00
check ( " driver_name " , None , " vfio " )
2014-02-10 23:24:22 +04:00
check ( " rom_bar " , None , True )
2013-03-18 01:06:52 +04:00
2015-04-11 22:52:42 +03:00
check = self . _make_checker ( dev4 )
check ( " type " , " scsi " )
check ( " scsi_adapter " , " scsi_host0 " , " foo " )
check ( " scsi_bus " , 0 , 1 )
check ( " scsi_target " , 0 , 2 )
check ( " scsi_unit " , 0 , 3 )
2018-06-15 12:29:34 +03:00
check = self . _make_checker ( dev5 )
check ( " type " , " net " )
check ( " net_interface " , " wlan0 " , " eth0 " )
2018-06-15 12:29:35 +03:00
check = self . _make_checker ( dev6 )
check ( " type " , " misc " )
check ( " misc_char " , " /dev/net/tun " , " /dev/null " )
2018-06-15 12:29:36 +03:00
check = self . _make_checker ( dev7 )
check ( " type " , " storage " )
check ( " storage_block " , " /dev/sdf " , " /dev/fd0 " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterWatchdogs ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-watchdogs " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . watchdog [ 0 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " model " , " ib700 " , " i6300esb " )
check ( " action " , " none " , " poweroff " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2020-09-10 20:06:41 +03:00
def _testAlterFilesystems ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-filesystems " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . filesystem [ 0 ]
dev2 = guest . devices . filesystem [ 1 ]
dev3 = guest . devices . filesystem [ 2 ]
dev4 = guest . devices . filesystem [ 3 ]
dev5 = guest . devices . filesystem [ 4 ]
dev6 = guest . devices . filesystem [ 5 ]
dev7 = guest . devices . filesystem [ 6 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , None , " mount " )
2015-09-21 03:15:34 +03:00
check ( " accessmode " , None , " passthrough " )
2020-09-10 20:06:41 +03:00
check ( " driver_type " , " handle " , None )
check ( " driver_wrpolicy " , None , None )
2013-03-18 01:06:52 +04:00
check ( " source " , " /foo/bar " , " /new/path " )
check ( " target " , " /bar/baz " , " /new/target " )
check = self . _make_checker ( dev2 )
check ( " type " , " template " )
2015-09-21 03:15:34 +03:00
check ( " accessmode " , None , " mapped " )
2013-03-18 01:06:52 +04:00
check ( " source " , " template_fedora " , " template_new " )
check ( " target " , " /bar/baz " )
check = self . _make_checker ( dev3 )
check ( " type " , " mount " , None )
2015-09-21 03:15:34 +03:00
check ( " accessmode " , " squash " , None )
2020-09-10 20:06:41 +03:00
check ( " driver_type " , " path " , " handle " )
check ( " driver_wrpolicy " , " immediate " , None )
2013-03-18 01:06:52 +04:00
check ( " readonly " , False , True )
check = self . _make_checker ( dev4 )
check ( " type " , " mount " , None )
2015-09-21 03:15:34 +03:00
check ( " accessmode " , " mapped " , None )
2020-09-10 20:06:41 +03:00
check ( " driver_type " , " path " , " handle " )
check ( " driver_wrpolicy " , None , " immediate " )
2013-03-18 01:06:52 +04:00
check ( " readonly " , False , True )
2014-01-21 13:05:28 +04:00
check = self . _make_checker ( dev5 )
check ( " type " , " ram " )
check ( " source " , " 1024 " , 123 )
2020-09-10 20:06:41 +03:00
check ( " source_units " , " MB " , " KiB " )
2014-01-21 13:05:28 +04:00
check = self . _make_checker ( dev6 )
check ( " source " , " /foo/bar " , " /dev/new " )
check ( " readonly " , False , True )
2017-06-19 11:18:47 +03:00
check ( " type " , " block " , " file " )
2014-01-21 13:05:28 +04:00
2014-01-21 13:05:29 +04:00
check = self . _make_checker ( dev7 )
check ( " type " , " file " )
2015-09-21 03:15:34 +03:00
check ( " accessmode " , " passthrough " , None )
2020-09-10 20:06:41 +03:00
check ( " driver_type " , " nbd " , " loop " )
check ( " driver_format " , " qcow " , " raw " )
2014-01-21 13:05:29 +04:00
check ( " source " , " /foo/bar.img " , " /foo/bar.raw " )
check ( " readonly " , False , True )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterSounds ( self ) :
2020-01-27 02:11:43 +03:00
infile = DATADIR + " change-sounds-in.xml "
outfile = DATADIR + " change-sounds-out.xml "
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . conn ,
2017-05-05 21:19:54 +03:00
parsexml = open ( infile ) . read ( ) )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . sound [ 0 ]
dev2 = guest . devices . sound [ 1 ]
dev3 = guest . devices . sound [ 2 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " model " , " sb16 " , " ac97 " )
check = self . _make_checker ( dev2 )
check ( " model " , " es1370 " , " es1370 " )
check = self . _make_checker ( dev3 )
check ( " model " , " ac97 " , " sb16 " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterAddr ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-addr " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . disk [ 0 ]
dev2 = guest . devices . controller [ 0 ]
dev3 = guest . devices . channel [ 0 ]
dev4 = guest . devices . disk [ 1 ]
dev5 = guest . devices . memory [ 0 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 . address )
check ( " type " , " drive " , " pci " )
check ( " type " , " pci " , " drive " )
2013-07-15 17:49:46 +04:00
check ( " controller " , 3 , 1 )
check ( " bus " , 5 , 4 )
2018-02-14 23:35:53 +03:00
check ( " target " , None , 7 )
2013-07-15 17:49:46 +04:00
check ( " unit " , 33 , 32 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 . alias )
check ( " name " , " foo2 " , None )
check = self . _make_checker ( dev2 . address )
2013-07-15 17:49:46 +04:00
dev2 . address . domain = " 0x0010 "
self . assertEqual ( dev2 . address . domain , 16 )
2013-03-18 01:06:52 +04:00
check ( " type " , " pci " )
2013-07-15 17:49:46 +04:00
check ( " domain " , 16 , 1 )
check ( " bus " , 0 , 4 )
check ( " slot " , 4 , 10 )
check ( " function " , 7 , 6 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 . alias )
check ( " name " , None , " frob " )
check = self . _make_checker ( dev3 . address )
check ( " type " , " virtio-serial " )
2013-07-15 17:49:46 +04:00
check ( " controller " , 0 )
check ( " bus " , 0 )
check ( " port " , 2 , 4 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev3 . alias )
check ( " name " , " channel0 " , " channel1 " )
2013-07-15 17:49:46 +04:00
dev4 . address . clear ( )
2018-02-14 23:35:53 +03:00
check = self . _make_checker ( dev5 . address )
check ( " type " , " dimm " )
check ( " slot " , 0 , 2 )
check ( " base " , None , " 0x1000 " )
# Need to remove this since the testdriver doesn't support
# memory devices?
guest . remove_device ( dev5 )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterSmartCard ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-smartcard " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . smartcard [ 0 ]
dev2 = guest . devices . smartcard [ 1 ]
2019-05-13 22:10:38 +03:00
dev3 = guest . devices . smartcard [ 2 ]
dev4 = guest . devices . smartcard [ 3 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
check ( " type " , None , " tcp " )
check = self . _make_checker ( dev2 )
check ( " mode " , " passthrough " , " host " )
check ( " type " , " spicevmc " , None )
2019-05-13 22:10:38 +03:00
check = self . _make_checker ( dev3 )
check ( " type " , " tcp " )
check ( " source.host " , " 127.0.0.1 " )
check ( " source.service " , 2001 )
2019-05-13 22:14:25 +03:00
check ( " source.protocol " , " raw " , " telnet " )
2019-05-13 22:10:38 +03:00
check = self . _make_checker ( dev4 )
check ( " type " , " unix " )
check ( " source.path " , " /tmp/smartcard.sock " )
check ( " source.mode " , " bind " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterRedirdev ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-redirdev " )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . redirdev [ 0 ]
dev2 = guest . devices . redirdev [ 1 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev1 )
2013-07-15 20:57:37 +04:00
check ( " bus " , " usb " , " baz " , " usb " )
2019-05-13 21:59:33 +03:00
check ( " source.host " , " foo " , " bar " )
check ( " source.service " , 12 , 42 )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( dev2 )
2013-07-15 20:57:37 +04:00
check ( " type " , " tcp " , " spicevmc " )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2013-06-26 05:45:06 +04:00
def testAlterTPM ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-tpm " )
2013-06-26 05:45:06 +04:00
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . tpm [ 0 ]
2013-06-26 05:45:06 +04:00
check = self . _make_checker ( dev1 )
2013-07-15 20:18:23 +04:00
check ( " type " , " passthrough " , " foo " , " passthrough " )
2018-06-09 00:42:40 +03:00
check ( " model " , " tpm-tis " , " tpm-crb " , " tpm-tis " )
2013-07-15 20:18:23 +04:00
check ( " device_path " , " /dev/tpm0 " , " frob " )
2013-06-26 05:45:06 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-06-26 05:45:06 +04:00
2013-09-18 17:29:28 +04:00
def testAlterRNG_EGD ( self ) :
guest , outfile = self . _get_test_content ( " change-rng-egd " )
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . rng [ 0 ]
2013-09-18 17:29:28 +04:00
check = self . _make_checker ( dev1 )
2019-05-13 21:42:50 +03:00
check ( " backend_model " , " egd " )
2013-10-25 19:13:26 +04:00
check ( " backend_type " , " udp " , " udp " )
2013-09-18 17:29:28 +04:00
2019-05-13 21:42:50 +03:00
check ( " source.connect_host " , " 1.2.3.4 " , " 1.2.3.5 " )
check ( " source.connect_service " , 1234 , 1235 )
check ( " source.bind_host " , None , None )
check ( " source.bind_service " , 1233 , 1236 )
2013-09-18 17:29:28 +04:00
check ( " rate_bytes " , " 1234 " , " 4321 " )
check ( " rate_period " , " 2000 " , " 2001 " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-09-18 17:29:28 +04:00
def testAlterRNG_Random ( self ) :
guest , outfile = self . _get_test_content ( " change-rng-random " )
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . rng [ 0 ]
2013-09-18 17:29:28 +04:00
check = self . _make_checker ( dev1 )
2019-05-13 21:42:50 +03:00
check ( " backend_model " , " random " , " random " )
2013-09-18 17:29:28 +04:00
check ( " model " , " virtio " , " virtio " )
check ( " device " , " /dev/random " , " /dev/hwrng " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-09-18 17:29:28 +04:00
2014-01-10 13:37:54 +04:00
def testPanicDevice ( self ) :
guest , outfile = self . _get_test_content ( " change-panic-device " )
2018-03-21 00:23:34 +03:00
dev1 = guest . devices . panic [ 0 ]
2014-01-10 13:37:54 +04:00
check = self . _make_checker ( dev1 )
2019-05-12 16:18:36 +03:00
check ( " address.type " , " isa " , None , " isa " )
check ( " address.iobase " , " 0x505 " , None , " 0x506 " )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2014-01-10 13:37:54 +04:00
2018-02-19 23:14:27 +03:00
def testQEMUXMLNS ( self ) :
basename = " change-xmlns-qemu "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . kvmconn , parsexml = open ( infile ) . read ( ) )
2018-02-19 23:14:27 +03:00
check = self . _make_checker ( guest . xmlns_qemu . args [ 0 ] )
check ( " value " , " -somearg " , " -somenewarg " )
check = self . _make_checker ( guest . xmlns_qemu . args [ 1 ] )
check ( " value " , " bar,baz=wib wob " , " testval " )
guest . xmlns_qemu . args . add_new ( ) . value = " additional-arg "
2018-02-26 22:56:24 +03:00
arg0 = guest . xmlns_qemu . args [ 0 ]
2018-02-19 23:14:27 +03:00
guest . xmlns_qemu . remove_child ( guest . xmlns_qemu . args [ 0 ] )
2018-08-31 23:52:02 +03:00
self . assertEqual ( arg0 . get_xml ( ) ,
2018-02-26 22:56:24 +03:00
" <qemu:arg xmlns:qemu= \" http://libvirt.org/schemas/domain/qemu/1.0 \" value= \" -somenewarg \" /> \n " )
2018-02-19 23:14:27 +03:00
check = self . _make_checker ( guest . xmlns_qemu . envs [ 0 ] )
check ( " name " , " SOMEENV " )
check ( " value " , " foo=bar baz,foo " )
env = guest . xmlns_qemu . envs . add_new ( )
env . name = " DISPLAY "
env . value = " 1:2 "
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2018-02-19 23:14:27 +03:00
2013-03-18 01:06:52 +04:00
def testAddRemoveDevices ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " add-devices " )
2013-03-18 01:06:52 +04:00
2017-10-26 12:58:13 +03:00
# Basic removal of existing device
2018-03-21 00:23:34 +03:00
rmdev = guest . devices . disk [ 2 ]
2013-03-18 01:06:52 +04:00
guest . remove_device ( rmdev )
2017-10-26 12:58:13 +03:00
# Basic device add
2018-09-02 00:34:32 +03:00
d = virtinst . DeviceWatchdog ( self . conn )
d . set_defaults ( guest )
guest . add_device ( d )
2017-10-26 12:58:13 +03:00
# Test adding device with child properties (address value)
2018-03-20 19:18:35 +03:00
adddev = virtinst . DeviceInterface ( self . conn )
2013-07-15 22:14:05 +04:00
adddev . type = " network "
2013-09-24 18:00:01 +04:00
adddev . source = " default "
2013-07-15 22:14:05 +04:00
adddev . macaddr = " 1A:2A:3A:4A:5A:6A "
2020-01-25 21:36:17 +03:00
adddev . address . type = " spapr-vio "
2018-09-02 00:34:32 +03:00
adddev . set_defaults ( guest )
2013-07-15 22:14:05 +04:00
2017-10-26 12:58:13 +03:00
# Test adding and removing the same device
2013-07-24 22:37:07 +04:00
guest . add_device ( adddev )
2013-03-18 01:06:52 +04:00
guest . remove_device ( adddev )
guest . add_device ( adddev )
2017-10-26 12:58:13 +03:00
# Test adding device built from parsed XML
2018-03-20 19:18:35 +03:00
guest . add_device ( virtinst . DeviceSound ( self . conn ,
2013-09-10 03:45:19 +04:00
parsexml = """ <sound model= ' pcspk ' /> """ ) )
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testChangeKVMMedia ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-media " , kvm = True )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 0 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/default-pool/default-vol " )
2013-07-25 20:34:37 +04:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 1 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/default-pool/default-vol " )
check ( " path " , " /dev/default-pool/default-vol " , " /dev/disk-pool/diskvol1 " )
2013-07-25 20:34:37 +04:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 2 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/disk-pool/diskvol1 " )
2013-07-25 20:34:37 +04:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 3 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/default-pool/default-vol " )
2013-07-25 20:34:37 +04:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
2018-03-21 00:23:34 +03:00
disk = guest . devices . disk [ 4 ]
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( disk )
2013-07-26 06:06:28 +04:00
check ( " path " , None , " /dev/disk-pool/diskvol1 " )
2013-07-25 20:34:37 +04:00
disk . sync_path_props ( )
2013-03-18 01:06:52 +04:00
2018-08-31 23:52:02 +03:00
self . _alter_compare ( guest . get_xml ( ) , outfile )
2013-03-18 01:06:52 +04:00
2020-01-27 19:44:52 +03:00
def testGuestBootorder ( self ) :
guest , outfile = self . _get_test_content ( " bootorder " , kvm = True )
self . assertEqual ( guest . get_boot_order ( ) , [ ' ./devices/disk[1] ' ] )
self . assertEqual ( guest . get_boot_order ( legacy = True ) , [ ' hd ' ] )
legacy_order = [ ' hd ' , ' fd ' , ' cdrom ' , ' network ' ]
dev_order = [ ' ./devices/disk[1] ' ,
' ./devices/disk[3] ' ,
' ./devices/disk[2] ' ,
' ./devices/interface[1] ' ]
guest . set_boot_order ( legacy_order , legacy = True )
self . assertEqual ( guest . get_boot_order ( ) , dev_order )
self . assertEqual ( guest . get_boot_order ( legacy = True ) , legacy_order )
guest . set_boot_order ( dev_order )
self . assertEqual ( guest . get_boot_order ( ) , dev_order )
self . assertEqual ( guest . get_boot_order ( legacy = True ) , [ ] )
self . _alter_compare ( guest . get_xml ( ) , outfile )
2020-01-29 04:03:38 +03:00
def testDiskChangeBus ( self ) :
guest , outfile = self . _get_test_content ( " disk-change-bus " )
disk = guest . devices . disk [ 0 ]
# Same bus is a no-op
origxml = disk . get_xml ( )
disk . change_bus ( guest , " virtio " )
assert origxml == disk . get_xml ( )
disk . change_bus ( guest , " ide " )
disk = guest . devices . disk [ 2 ]
disk . change_bus ( guest , " scsi " )
self . _alter_compare ( guest . get_xml ( ) , outfile )
2020-01-27 19:44:52 +03:00
##################
# Snapshot tests #
##################
2013-08-06 01:20:35 +04:00
def testChangeSnapshot ( self ) :
basename = " change-snapshot "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
snap = virtinst . DomainSnapshot ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-08-06 01:20:35 +04:00
check = self . _make_checker ( snap )
check ( " name " , " offline-root-child1 " , " name-foo " )
check ( " state " , " shutoff " , " somestate " )
check ( " description " , " offline desk " , " foo \n newline \n indent " )
check ( " parent " , " offline-root " , " newparent " )
check ( " creationTime " , 1375905916 , 1234 )
2013-10-01 01:53:55 +04:00
check ( " memory_type " , " no " , " internal " )
check = self . _make_checker ( snap . disks [ 0 ] )
check ( " name " , " hda " , " hdb " )
check ( " snapshot " , " internal " , " no " )
2013-08-06 01:20:35 +04:00
2018-08-31 23:52:02 +03:00
utils . diff_compare ( snap . get_xml ( ) , outfile )
2013-07-12 17:19:28 +04:00
2013-09-10 01:14:16 +04:00
2013-09-20 04:18:12 +04:00
#################
# Storage tests #
#################
def testFSPool ( self ) :
basename = " pool-fs "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s .xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
pool = virtinst . StoragePool ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-20 04:18:12 +04:00
check = self . _make_checker ( pool )
check ( " type " , " fs " , " dir " )
check ( " name " , " pool-fs " , " foo-new " )
check ( " uuid " , " 10211510-2115-1021-1510-211510211510 " ,
" 10211510-2115-1021-1510-211510211999 " )
check ( " capacity " , 984373075968 , 200000 )
check ( " allocation " , 756681687040 , 150000 )
check ( " available " , 227691388928 , 50000 )
check ( " format " , " auto " , " ext3 " )
check ( " source_path " , " /some/source/path " , " /dev/foo/bar " )
check ( " target_path " , " /some/target/path " , " /mnt/my/foo " )
check ( " source_name " , None , " fooname " )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( pool . get_xml ( ) , outfile )
utils . test_create ( self . conn , pool . get_xml ( ) , " storagePoolDefineXML " )
2013-09-20 04:18:12 +04:00
def testISCSIPool ( self ) :
basename = " pool-iscsi "
2020-08-30 15:54:41 +03:00
infile = utils . DATADIR + " /storage/ %s .xml " % basename
2020-01-27 02:11:43 +03:00
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
pool = virtinst . StoragePool ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-20 04:18:12 +04:00
check = self . _make_checker ( pool )
check ( " iqn " , " foo.bar.baz.iqn " , " my.iqn " )
2014-12-10 00:05:02 +03:00
check = self . _make_checker ( pool . hosts [ 0 ] )
check ( " name " , " some.random.hostname " , " my.host " )
2013-09-20 04:18:12 +04:00
2018-08-31 23:52:02 +03:00
utils . diff_compare ( pool . get_xml ( ) , outfile )
utils . test_create ( self . conn , pool . get_xml ( ) , " storagePoolDefineXML " )
2013-09-20 04:18:12 +04:00
2014-02-12 13:39:50 +04:00
def testGlusterPool ( self ) :
basename = " pool-gluster "
2020-08-30 15:54:41 +03:00
infile = utils . DATADIR + " /storage/ %s .xml " % basename
2020-01-27 02:11:43 +03:00
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
pool = virtinst . StoragePool ( self . conn , parsexml = open ( infile ) . read ( ) )
2014-02-12 13:39:50 +04:00
check = self . _make_checker ( pool )
2014-12-10 00:05:02 +03:00
check ( " source_path " , " /some/source/path " , " /foo " )
check = self . _make_checker ( pool . hosts [ 0 ] )
check ( " name " , " some.random.hostname " , " my.host " )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( pool . get_xml ( ) , outfile )
utils . test_create ( self . conn , pool . get_xml ( ) , " storagePoolDefineXML " )
2014-12-10 00:05:02 +03:00
def testRBDPool ( self ) :
basename = " pool-rbd "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s .xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
pool = virtinst . StoragePool ( self . conn , parsexml = open ( infile ) . read ( ) )
2014-12-10 00:05:02 +03:00
check = self . _make_checker ( pool . hosts [ 0 ] )
check ( " name " , " ceph-mon-1.example.com " )
check ( " port " , 6789 , 1234 )
check = self . _make_checker ( pool . hosts [ 1 ] )
check ( " name " , " ceph-mon-2.example.com " , " foo.bar " )
check ( " port " , 6789 )
check = self . _make_checker ( pool . hosts [ 2 ] )
check ( " name " , " ceph-mon-3.example.com " )
check ( " port " , 6789 , 1000 )
2018-02-08 01:27:56 +03:00
hostobj = pool . hosts . add_new ( )
hostobj . name = " frobber "
hostobj . port = " 5555 "
2014-02-12 13:39:50 +04:00
2018-08-31 23:52:02 +03:00
utils . diff_compare ( pool . get_xml ( ) , outfile )
utils . test_create ( self . conn , pool . get_xml ( ) , " storagePoolDefineXML " )
2014-02-12 13:39:50 +04:00
2013-09-20 04:18:12 +04:00
def testVol ( self ) :
basename = " pool-dir-vol "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
vol = virtinst . StorageVolume ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-20 04:18:12 +04:00
check = self . _make_checker ( vol )
2014-12-10 00:05:02 +03:00
check ( " type " , None , " file " )
2013-12-05 18:17:12 +04:00
check ( " key " , None , " fookey " )
2013-09-20 04:18:12 +04:00
check ( " capacity " , 10737418240 , 2000 )
check ( " allocation " , 5368709120 , 1000 )
check ( " format " , " raw " , " qcow2 " )
check ( " target_path " , None , " /foo/bar " )
2013-09-29 03:11:27 +04:00
check ( " backing_store " , " /foo/bar/baz " , " /my/backing " )
2014-02-03 23:52:23 +04:00
check ( " lazy_refcounts " , False , True )
2013-09-20 04:18:12 +04:00
check = self . _make_checker ( vol . permissions )
check ( " mode " , " 0700 " , " 0744 " )
check ( " owner " , " 10736 " , " 10000 " )
check ( " group " , " 10736 " , " 10000 " )
check ( " label " , None , " foo.label " )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( vol . get_xml ( ) , outfile )
2013-09-20 04:18:12 +04:00
2013-09-21 04:40:07 +04:00
###################
# <network> tests #
###################
def testNetMulti ( self ) :
basename = " network-multi "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
net = virtinst . Network ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-21 04:40:07 +04:00
check = self . _make_checker ( net )
check ( " name " , " ipv6_multirange " , " new-foo " )
check ( " uuid " , " 41b4afe4-87bb-8087-6724-5e208a2d483a " ,
" 41b4afe4-87bb-8087-6724-5e208a2d1111 " )
check ( " bridge " , " virbr3 " , " virbr3new " )
check ( " stp " , True , False )
check ( " delay " , 0 , 2 )
check ( " domain_name " , " net7 " , " newdom " )
check ( " ipv6 " , None , True )
check ( " macaddr " , None , " 52:54:00:69:eb:FF " )
2017-03-23 18:06:56 +03:00
check ( " virtualport_type " , None , " openvswitch " )
2013-09-21 04:40:07 +04:00
2017-05-05 18:39:59 +03:00
self . assertEqual ( len ( net . portgroups ) , 2 )
2014-05-31 22:20:56 +04:00
check = self . _make_checker ( net . portgroups [ 0 ] )
check ( " name " , " engineering " , " foo " )
check ( " default " , True , False )
2013-09-21 04:40:07 +04:00
self . assertEqual ( len ( net . ips ) , 4 )
check = self . _make_checker ( net . ips [ 0 ] )
check ( " address " , " 192.168.7.1 " , " 192.168.8.1 " )
check ( " netmask " , " 255.255.255.0 " , " 255.255.254.0 " )
2019-06-09 23:39:15 +03:00
self . assertEqual ( net . can_pxe ( ) , False )
2013-09-21 04:40:07 +04:00
check ( " tftp " , None , " /var/lib/tftproot " )
check ( " bootp_file " , None , " pxeboot.img " )
check ( " bootp_server " , None , " 1.2.3.4 " )
2019-06-09 23:39:15 +03:00
self . assertEqual ( net . can_pxe ( ) , True )
check = self . _make_checker ( net . forward )
check ( " mode " , " nat " , " route " )
check ( " dev " , None , " eth22 " )
self . assertEqual ( net . can_pxe ( ) , True )
2013-09-21 04:40:07 +04:00
check = self . _make_checker ( net . ips [ 0 ] . ranges [ 0 ] )
check ( " start " , " 192.168.7.128 " , " 192.168.8.128 " )
check ( " end " , " 192.168.7.254 " , " 192.168.8.254 " )
check = self . _make_checker ( net . ips [ 0 ] . hosts [ 1 ] )
check ( " macaddr " , " 52:54:00:69:eb:91 " , " 52:54:00:69:eb:92 " )
check ( " name " , " badbob " , " newname " )
check ( " ip " , " 192.168.7.3 " , " 192.168.8.3 " )
check = self . _make_checker ( net . ips [ 1 ] )
check ( " family " , " ipv6 " , " ipv6 " )
check ( " prefix " , 64 , 63 )
2018-02-08 01:27:56 +03:00
r = net . routes . add_new ( )
2013-09-23 21:21:35 +04:00
r . family = " ipv4 "
r . address = " 192.168.8.0 "
r . prefix = " 24 "
r . gateway = " 192.168.8.10 "
check = self . _make_checker ( r )
2013-09-23 17:10:43 +04:00
check ( " netmask " , None , " foo " , None )
2013-09-21 04:40:07 +04:00
2018-08-31 23:52:02 +03:00
utils . diff_compare ( net . get_xml ( ) , outfile )
utils . test_create ( self . conn , net . get_xml ( ) , " networkDefineXML " )
2013-09-20 04:18:12 +04:00
2017-05-03 18:56:31 +03:00
def testNetOpen ( self ) :
basename = " network-open "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
net = virtinst . Network ( self . conn , parsexml = open ( infile ) . read ( ) )
2017-05-03 18:56:31 +03:00
check = self . _make_checker ( net )
check ( " name " , " open " , " new-foo " )
check ( " domain_name " , " open " , " newdom " )
check = self . _make_checker ( net . forward )
check ( " mode " , " open " )
check ( " dev " , None )
self . assertEqual ( len ( net . ips ) , 1 )
check = self . _make_checker ( net . ips [ 0 ] )
check ( " address " , " 192.168.100.1 " , " 192.168.101.1 " )
check ( " netmask " , " 255.255.255.0 " , " 255.255.254.0 " )
check = self . _make_checker ( net . ips [ 0 ] . ranges [ 0 ] )
check ( " start " , " 192.168.100.128 " , " 192.168.101.128 " )
check ( " end " , " 192.168.100.254 " , " 192.168.101.254 " )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( net . get_xml ( ) , outfile )
utils . test_create ( self . conn , net . get_xml ( ) , " networkDefineXML " )
2017-05-03 18:56:31 +03:00
2017-03-31 15:12:00 +03:00
def testNetVfPool ( self ) :
basename = " network-vf-pool "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
net = virtinst . Network ( self . conn , parsexml = open ( infile ) . read ( ) )
2017-03-31 15:12:00 +03:00
check = self . _make_checker ( net )
check ( " name " , " passthrough " , " new-foo " )
check = self . _make_checker ( net . forward )
check ( " mode " , " hostdev " )
check ( " managed " , " yes " )
2017-09-22 14:39:09 +03:00
check = self . _make_checker ( net . forward . pf [ 0 ] )
2017-03-31 15:12:00 +03:00
check ( " dev " , " eth3 " )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( net . get_xml ( ) , outfile )
utils . test_create ( self . conn , net . get_xml ( ) , " networkDefineXML " )
2017-03-31 15:12:00 +03:00
2013-09-20 04:18:12 +04:00
2013-09-10 01:14:16 +04:00
##############
# Misc tests #
##############
2014-01-25 23:57:10 +04:00
def testCPUUnknownClear ( self ) :
# Make sure .clear() even removes XML elements we don't know about
basename = " clear-cpu-unknown-vals "
2020-01-27 02:11:43 +03:00
infile = DATADIR + " %s -in.xml " % basename
outfile = DATADIR + " %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . kvmconn , parsexml = open ( infile ) . read ( ) )
2014-01-25 23:57:10 +04:00
2018-10-14 00:47:31 +03:00
guest . cpu . copy_host_cpu ( guest )
2014-01-25 23:57:10 +04:00
guest . cpu . clear ( )
2018-08-31 23:52:02 +03:00
utils . diff_compare ( guest . get_xml ( ) , outfile )
2014-01-25 23:57:10 +04:00
2018-02-20 18:10:08 +03:00
def testDomainRoundtrip ( self ) :
# Make sure our XML engine doesn't mangle non-libvirt XML bits
2020-01-27 02:11:43 +03:00
infile = DATADIR + " domain-roundtrip.xml "
outfile = DATADIR + " domain-roundtrip.xml "
2018-02-22 22:57:10 +03:00
guest = virtinst . Guest ( self . conn , parsexml = open ( infile ) . read ( ) )
2018-02-20 18:10:08 +03:00
2018-08-31 23:52:02 +03:00
utils . diff_compare ( guest . get_xml ( ) , outfile )
2019-05-11 00:47:54 +03:00
def testYesNoUnexpectedParse ( self ) :
# Make sure that if we see an unexpected yes/no or on/off value,
# we just return it to the user and don't error. Libvirt could
# change our assumptions and we shouldn't be too restrictive
xml = ( " <hostdev managed= ' foo ' > \n <rom bar= ' wibble ' /> \n "
" <source><address bus= ' hello ' /></source> \n </hostdev> " )
dev = virtinst . DeviceHostdev ( self . conn , parsexml = xml )
self . assertEqual ( dev . managed , " foo " )
self . assertEqual ( dev . rom_bar , " wibble " )
self . assertEqual ( dev . scsi_bus , " hello " )
dev . managed = " test1 "
dev . rom_bar = " test2 "
self . assertEqual ( dev . managed , " test1 " )
self . assertEqual ( dev . rom_bar , " test2 " )
2019-06-14 20:04:56 +03:00
with self . assertRaises ( ValueError ) :
2019-05-11 00:47:54 +03:00
dev . scsi_bus = " goodbye "
2019-05-08 20:02:35 +03:00
2019-06-10 01:16:51 +03:00
def testXMLCoverage ( self ) :
2019-06-14 20:04:56 +03:00
with self . assertRaises ( RuntimeError ) as cm :
2019-06-10 01:16:51 +03:00
# Ensure we validate root element
2019-05-08 20:02:35 +03:00
virtinst . DeviceDisk ( self . conn , parsexml = " <foo/> " )
2019-06-14 20:04:56 +03:00
self . assertTrue ( " ' foo ' " in str ( cm . exception ) )
2019-05-09 01:59:12 +03:00
2019-06-14 20:04:56 +03:00
with self . assertRaises ( Exception ) as cm :
2019-06-10 01:16:51 +03:00
# Ensure we validate root element
virtinst . DeviceDisk ( self . conn , parsexml = - 1 )
2019-06-14 20:04:56 +03:00
self . assertTrue ( " xmlParseDoc " in str ( cm . exception ) )
2019-06-10 01:16:51 +03:00
2020-07-18 01:58:00 +03:00
from virtinst import xmlutil
with self . assertRaises ( xmlutil . DevError ) :
raise xmlutil . DevError ( " for coverage " )
2019-06-10 01:16:51 +03:00
2019-06-14 20:04:56 +03:00
with self . assertRaises ( ValueError ) :
2019-06-10 01:16:51 +03:00
virtinst . DeviceDisk . validate_generic_name ( " objtype " , None )
2019-06-14 20:04:56 +03:00
with self . assertRaises ( ValueError ) :
2019-06-10 01:16:51 +03:00
virtinst . DeviceDisk . validate_generic_name ( " objtype " , " foo bar " )
# Test property __repr__ for code coverage
assert str ( virtinst . DeviceDisk . address )
assert str ( virtinst . DeviceDisk . driver_cache )
2019-05-09 01:59:12 +03:00
def testReplaceChildParse ( self ) :
2020-01-27 02:11:43 +03:00
buildfile = DATADIR + " replace-child-build.xml "
parsefile = DATADIR + " replace-child-parse.xml "
2019-05-09 01:59:12 +03:00
def mkdisk ( target ) :
disk = virtinst . DeviceDisk ( self . conn )
disk . device = " cdrom "
disk . bus = " scsi "
disk . target = target
return disk
guest = virtinst . Guest ( self . conn )
guest . add_device ( mkdisk ( " sda " ) )
guest . add_device ( mkdisk ( " sdb " ) )
guest . add_device ( mkdisk ( " sdc " ) )
guest . add_device ( mkdisk ( " sdd " ) )
guest . add_device ( mkdisk ( " sde " ) )
guest . add_device ( mkdisk ( " sdf " ) )
guest . devices . replace_child ( guest . devices . disk [ 2 ] , mkdisk ( " sdz " ) )
guest . set_defaults ( guest )
utils . diff_compare ( guest . get_xml ( ) , buildfile )
guest = virtinst . Guest ( self . conn , parsexml = guest . get_xml ( ) )
newdisk = virtinst . DeviceDisk ( self . conn ,
parsexml = mkdisk ( " sdw " ) . get_xml ( ) )
guest . devices . replace_child ( guest . devices . disk [ 4 ] , newdisk )
utils . diff_compare ( guest . get_xml ( ) , parsefile )
2019-05-24 01:13:24 +03:00
2020-01-29 15:30:51 +03:00
def testDiskBackend ( self ) :
# Test that calling validate() on parsed disk XML doesn't attempt
# to verify the path exists. Assume it's a working config
2019-05-24 01:13:24 +03:00
xml = ( " <disk type= ' file ' device= ' disk ' > "
" <source file= ' /A/B/C/D/NOPE ' /> "
" </disk> " )
disk = virtinst . DeviceDisk ( self . conn , parsexml = xml )
disk . validate ( )
disk . is_size_conflict ( )
disk . build_storage ( None )
2020-01-29 14:18:15 +03:00
self . assertTrue ( getattr ( disk , " _storage_backend " ) . is_stub ( ) )
2019-05-24 01:13:24 +03:00
2020-01-29 15:30:51 +03:00
# Stub backend coverage testing
backend = getattr ( disk , " _storage_backend " )
assert disk . get_parent_pool ( ) is None
assert disk . get_vol_object ( ) is None
assert disk . get_vol_install ( ) is None
assert disk . get_size ( ) == 0
assert backend . get_vol_xml ( ) is None
assert backend . get_dev_type ( ) == " file "
assert backend . get_driver_type ( ) is None
assert backend . get_parent_pool ( ) is None
2019-05-24 01:13:24 +03:00
disk . set_backend_for_existing_path ( )
2020-01-29 14:18:15 +03:00
self . assertFalse ( getattr ( disk , " _storage_backend " ) . is_stub ( ) )
2019-06-14 20:04:56 +03:00
with self . assertRaises ( ValueError ) :
2019-05-24 01:13:24 +03:00
disk . validate ( )
2020-01-27 15:38:53 +03:00
2020-09-04 20:07:02 +03:00
# Ensure set_backend_for_existing_path resolves a path
# to its existing storage volume
xml = ( " <disk type= ' file ' device= ' disk ' > "
" <source file= ' /dev/default-pool/default-vol ' /> "
" </disk> " )
conn = utils . URIs . open_testdriver_cached ( )
disk = virtinst . DeviceDisk ( conn , parsexml = xml )
disk . set_backend_for_existing_path ( )
assert disk . get_vol_object ( )
# Verify set_backend_for_existing_path doesn't error
# for a variety of disks
dom = conn . lookupByName ( " test-many-devices " )
guest = virtinst . Guest ( conn , parsexml = dom . XMLDesc ( 0 ) )
for disk in guest . devices . disk :
disk . set_backend_for_existing_path ( )
2020-01-27 15:38:53 +03:00
def testGuestXMLDeviceMatch ( self ) :
"""
Test Guest . find_device and Device . compare_device
"""
uri = utils . URIs . test_suite
conn = utils . URIs . openconn ( uri )
dom = conn . lookupByName ( " test-for-virtxml " )
xml = dom . XMLDesc ( 0 )
guest = virtinst . Guest ( conn , xml )
guest2 = virtinst . Guest ( conn , xml )
# Assert id matching works
diskdev = guest . devices . disk [ 0 ]
assert guest . find_device ( diskdev ) == diskdev
# Assert type checking correct returns False
ifacedev = guest . devices . interface [ 0 ]
assert ifacedev . compare_device ( diskdev , 0 ) is False
2020-01-27 19:44:52 +03:00
# find_device should fail here
nodev = virtinst . DeviceWatchdog ( conn )
assert guest . find_device ( nodev ) is None
2020-01-27 15:38:53 +03:00
# Ensure parsed XML devices match correctly
for srcdev in guest . devices . get_all ( ) :
devxml = srcdev . get_xml ( )
newdev = srcdev . __class__ ( conn , devxml )
if srcdev != guest . find_device ( newdev ) :
raise AssertionError ( " guest.find_device failed for dev= %s " %
newdev )
# Ensure devices from another parsed XML doc compare correctly
for srcdev in guest . devices . get_all ( ) :
if not guest2 . find_device ( srcdev ) :
raise AssertionError ( " guest.find_device failed for dev= %s " %
srcdev )
2020-01-27 16:02:19 +03:00
def testControllerAttachedDevices ( self ) :
"""
Test DeviceController . get_attached_devices
"""
xml = open ( DATADIR + " controller-attached-devices.xml " ) . read ( )
guest = virtinst . Guest ( self . conn , xml )
# virtio-serial path
controller = [ c for c in guest . devices . controller if
c . type == " virtio-serial " ] [ 0 ]
devs = controller . get_attached_devices ( guest )
assert len ( devs ) == 4
assert devs [ - 1 ] . DEVICE_TYPE == " console "
# disk path
controller = [ c for c in guest . devices . controller if
c . type == " sata " ] [ 0 ]
devs = controller . get_attached_devices ( guest )
assert len ( devs ) == 1
assert devs [ - 1 ] . device == " cdrom "
# Little test for DeviceAddress.pretty_desc
assert devs [ - 1 ] . address . pretty_desc ( ) == " 0:0:0:3 "
2020-01-27 16:59:02 +03:00
def testCPUHostModelOnly ( self ) :
"""
Hit the validation paths for default HOST_MODEL_ONLY
"""
guest = virtinst . Guest ( self . kvmconn )
guest . x86_cpu_default = guest . cpu . SPECIAL_MODE_HOST_MODEL_ONLY
guest . set_defaults ( guest )
assert guest . cpu . model == " Opteron_G4 "
# pylint: disable=protected-access
guest . cpu . model = " idontexist "
guest . cpu . _validate_default_host_model_only ( guest )
assert guest . cpu . model is None