2014-02-06 15:12:12 +04:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2013-10-28 00:59:47 +04:00
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2013-03-18 01:06:52 +04:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
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
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 )
2013-04-11 18:44:27 +04:00
actualXML = guest . get_xml_config ( )
2013-03-18 01:06:52 +04:00
utils . diff_compare ( actualXML , expect_out = expectXML )
2015-04-03 01:04:04 +03:00
def _alter_compare ( self , actualXML , outfile , support_check = None ) :
2013-03-18 01:06:52 +04:00
utils . diff_compare ( actualXML , outfile )
2018-02-22 22:57:10 +03:00
if ( support_check and not self . conn . check_support ( support_check ) ) :
2015-04-03 01:04:04 +03:00
return
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
"""
curval = getattr ( 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 :
setattr ( obj , param , newval )
curval = getattr ( 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
2013-07-12 17:19:28 +04:00
def _get_test_content ( self , basename , kvm = False ) :
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %s -out.xml " % 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 )
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! " )
2013-07-18 01:58:24 +04:00
check ( " vcpus " , 5 , 12 )
check ( " curvcpus " , None , 10 )
2013-03-18 01:06:52 +04:00
check ( " cpuset " , " 1-3 " , " 1-8,^6 " , " 1-5,15 " )
2013-07-14 07:07:01 +04:00
check ( " maxmemory " , 409600 , 512000 )
check ( " memory " , 204800 , 1024000 )
check ( " maxmemory " , 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
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 )
2018-02-22 14:34:21 +03:00
check ( " vmcoreinfo " , False , 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 " )
check ( " model " , " footest " , " qemu64 " )
check ( " vendor " , " Intel " , " qemuvendor " )
check ( " threads " , 2 , 1 )
check ( " cores " , 5 , 3 )
2013-07-25 23:27:42 +04:00
guest . cpu . sockets = 4.0
check ( " 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 )
2017-05-05 18:39:59 +03:00
self . assertEqual ( rmfeat . get_xml_config ( ) ,
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 )
check ( " device_weight " , None , 300 )
check ( " device_path " , None , " /home/1.img " )
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 " )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . get_devices ( " memballoon " ) [ 0 ] )
check ( " model " , " virtio " , " none " )
2014-03-22 14:15:46 +04:00
check = self . _make_checker ( guest . memoryBacking )
check ( " hugepages " , False , True )
2014-07-30 10:34:03 +04:00
check ( " page_size " , None , 1 )
check ( " page_unit " , None , " G " )
check ( " page_nodeset " , None , " 1,5-8 " )
2014-03-22 14:15:46 +04:00
check ( " nosharepages " , False , True )
check ( " locked " , False , True )
2015-04-03 01:04:04 +03:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile ,
2018-02-22 14:34:21 +03:00
support_check = [ self . conn . SUPPORT_CONN_VMPORT ,
self . conn . SUPPORT_CONN_VMCOREINFO ] )
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 ( " imagelabel " , " imagelabel " , " fooimage " )
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
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
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 (
guest . features . get_xml_config ( ) . startswith ( " <features " ) )
check = self . _make_checker ( guest . clock )
check ( " offset " , None , " utc " )
self . assertTrue ( guest . clock . get_xml_config ( ) . startswith ( " <clock " ) )
2015-05-04 01:08:10 +03:00
seclabel = virtinst . Seclabel ( guest . conn )
guest . add_child ( seclabel )
seclabel . model = " testSecurity "
seclabel . type = " static "
seclabel . label = " frob "
2013-03-18 01:06:52 +04:00
self . assertTrue (
2016-06-12 18:09:15 +03:00
guest . seclabels [ 0 ] . get_xml_config ( ) . startswith ( " <seclabel " ) )
2013-03-18 01:06:52 +04:00
check = self . _make_checker ( guest . cpu )
check ( " model " , None , " foobar " )
2015-03-27 00:08:15 +03:00
check ( " model_fallback " , None , " allow " )
2013-03-18 01:06:52 +04:00
check ( " cores " , None , 4 )
guest . cpu . add_feature ( " x2apic " , " forbid " )
guest . cpu . set_topology_defaults ( guest . vcpus )
self . assertTrue ( guest . cpu . get_xml_config ( ) . startswith ( " <cpu " ) )
2013-07-17 15:53:47 +04:00
self . assertTrue ( guest . os . get_xml_config ( ) . startswith ( " <os " ) )
2013-03-18 01:06:52 +04:00
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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 " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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 )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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 )
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-04-11 09:45:46 +04:00
def testAlterCpuMode ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " change-cpumode " )
2013-04-11 09:45:46 +04:00
check = self . _make_checker ( guest . cpu )
check ( " mode " , " host-passthrough " , " custom " )
check ( " mode " , " custom " , " host-model " )
# mode will be "custom"
check ( " model " , None , " qemu64 " )
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
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 ) :
for disk in guest . get_devices ( " disk " ) :
if disk . target == target :
return disk
disk = _get_disk ( " hda " )
check = self . _make_checker ( disk )
2013-09-26 16:47:01 +04:00
check ( " path " , " /tmp/test.img " , " /dev/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 " )
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
2015-09-05 21:40:45 +03:00
disk = guest . get_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 " )
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 " )
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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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 " )
2017-05-05 18:39:59 +03:00
self . assertEqual ( xml . replace ( " hda " , " hdb " ) , d . get_xml_config ( ) )
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
serial1 = guest . get_devices ( " serial " ) [ 0 ]
serial2 = guest . get_devices ( " serial " ) [ 1 ]
parallel1 = guest . get_devices ( " parallel " ) [ 0 ]
parallel2 = guest . get_devices ( " parallel " ) [ 1 ]
console1 = guest . get_devices ( " console " ) [ 0 ]
console2 = guest . get_devices ( " console " ) [ 1 ]
channel1 = guest . get_devices ( " channel " ) [ 0 ]
channel2 = guest . get_devices ( " channel " ) [ 1 ]
2014-03-25 18:42:32 +04:00
channel3 = guest . get_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 " )
check ( " bind_host " , None , " example.com " )
check ( " bind_port " , None , 66 )
check ( " source_host " , None , " example.com.uk " )
check ( " source_port " , 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 " )
2013-03-18 01:06:52 +04:00
check ( " protocol " , " telnet " , " raw " )
check ( " source_mode " , " bind " , " connect " )
check = self . _make_checker ( parallel1 )
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 " )
check ( " bind_port " , 1111 , 1357 )
2013-03-18 01:06:52 +04:00
check ( " bind_host " , " my.bind.host " , " my.foo.host " )
2013-07-16 17:14:37 +04:00
check ( " source_port " , 2222 , 7777 )
2013-03-18 01:06:52 +04:00
check ( " source_host " , " my.source.host " , " source.foo.host " )
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 " )
2013-03-18 01:06:52 +04:00
check ( " source_path " , " /tmp/foo.img " , None )
check ( " source_path " , None , " /root/foo " )
check ( " target_type " , " virtio " )
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 " )
check ( " source_channel " , " org.spice-space.webdav.0 " , " test.1 " )
check ( " target_type " , " virtio " )
check ( " target_name " , " org.spice-space.webdav.0 " , " test.2 " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " controller " ) [ 0 ]
dev2 = guest . get_devices ( " controller " ) [ 1 ]
dev3 = guest . get_devices ( " controller " ) [ 2 ]
dev4 = guest . get_devices ( " controller " ) [ 3 ]
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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " interface " ) [ 0 ]
dev2 = guest . get_devices ( " interface " ) [ 1 ]
dev3 = guest . get_devices ( " interface " ) [ 2 ]
dev4 = guest . get_devices ( " interface " ) [ 3 ]
dev5 = guest . get_devices ( " interface " ) [ 4 ]
check = self . _make_checker ( dev1 )
check ( " type " , " user " )
check ( " model " , None , " testmodel " )
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 " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " input " ) [ 0 ]
dev2 = guest . get_devices ( " input " ) [ 1 ]
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 " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " graphics " ) [ 0 ]
dev2 = guest . get_devices ( " graphics " ) [ 1 ]
dev3 = guest . get_devices ( " graphics " ) [ 2 ]
dev4 = guest . get_devices ( " graphics " ) [ 3 ]
dev5 = guest . get_devices ( " graphics " ) [ 4 ]
2013-07-16 02:53:53 +04:00
dev6 = guest . get_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 ] )
check ( " type " , " network " , " foo " , " network " )
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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " video " ) [ 0 ]
dev2 = guest . get_devices ( " video " ) [ 1 ]
dev3 = guest . get_devices ( " video " ) [ 2 ]
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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterHostdevs ( self ) :
infile = " tests/xmlparse-xml/change-hostdevs-in.xml "
outfile = " tests/xmlparse-xml/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
dev1 = guest . get_devices ( " hostdev " ) [ 0 ]
dev2 = guest . get_devices ( " hostdev " ) [ 1 ]
dev3 = guest . get_devices ( " hostdev " ) [ 2 ]
2015-04-11 22:52:42 +03:00
dev4 = guest . get_devices ( " hostdev " ) [ 3 ]
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 )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " watchdog " ) [ 0 ]
check = self . _make_checker ( dev1 )
check ( " model " , " ib700 " , " i6300esb " )
check ( " action " , " none " , " poweroff " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04: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
2013-07-12 17:19:28 +04:00
dev1 = guest . get_devices ( " filesystem " ) [ 0 ]
dev2 = guest . get_devices ( " filesystem " ) [ 1 ]
dev3 = guest . get_devices ( " filesystem " ) [ 2 ]
dev4 = guest . get_devices ( " filesystem " ) [ 3 ]
2014-01-21 13:05:28 +04:00
dev5 = guest . get_devices ( " filesystem " ) [ 4 ]
dev6 = guest . get_devices ( " filesystem " ) [ 5 ]
2014-01-21 13:05:29 +04:00
dev7 = guest . get_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 " )
2013-03-18 01:06:52 +04:00
check ( " driver " , " handle " , None )
check ( " wrpolicy " , None , None )
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 )
2013-03-18 01:06:52 +04:00
check ( " driver " , " path " , " handle " )
check ( " wrpolicy " , " immediate " , None )
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 )
2013-03-18 01:06:52 +04:00
check ( " driver " , " path " , " handle " )
check ( " wrpolicy " , None , " immediate " )
check ( " readonly " , False , True )
2014-01-21 13:05:28 +04:00
check = self . _make_checker ( dev5 )
check ( " type " , " ram " )
check ( " source " , " 1024 " , 123 )
check ( " units " , " MB " , " KiB " )
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 )
2014-01-21 13:05:29 +04:00
check ( " driver " , " nbd " , " loop " )
check ( " format " , " qcow " , " raw " )
check ( " source " , " /foo/bar.img " , " /foo/bar.raw " )
check ( " readonly " , False , True )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testAlterSounds ( self ) :
infile = " tests/xmlparse-xml/change-sounds-in.xml "
outfile = " tests/xmlparse-xml/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
dev1 = guest . get_devices ( " sound " ) [ 0 ]
dev2 = guest . get_devices ( " sound " ) [ 1 ]
dev3 = guest . get_devices ( " sound " ) [ 2 ]
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 " )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " disk " ) [ 0 ]
dev2 = guest . get_devices ( " controller " ) [ 0 ]
dev3 = guest . get_devices ( " channel " ) [ 0 ]
2013-07-15 17:49:46 +04:00
dev4 = guest . get_devices ( " disk " ) [ 1 ]
2018-02-14 23:35:53 +03:00
dev5 = guest . get_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 )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " smartcard " ) [ 0 ]
dev2 = guest . get_devices ( " smartcard " ) [ 1 ]
check = self . _make_checker ( dev1 )
check ( " type " , None , " tcp " )
check = self . _make_checker ( dev2 )
check ( " mode " , " passthrough " , " host " )
check ( " type " , " spicevmc " , None )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " redirdev " ) [ 0 ]
dev2 = guest . get_devices ( " redirdev " ) [ 1 ]
check = self . _make_checker ( dev1 )
2013-07-15 20:57:37 +04:00
check ( " bus " , " usb " , " baz " , " usb " )
2013-03-18 01:06:52 +04:00
check ( " host " , " foo " , " bar " )
2013-07-15 20:57:37 +04:00
check ( " 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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
dev1 = guest . get_devices ( " tpm " ) [ 0 ]
check = self . _make_checker ( dev1 )
2013-07-15 20:18:23 +04:00
check ( " type " , " passthrough " , " foo " , " passthrough " )
2013-06-26 05:45:06 +04:00
check ( " model " , " tpm-tis " , " tpm-tis " )
2013-07-15 20:18:23 +04:00
check ( " device_path " , " /dev/tpm0 " , " frob " )
2013-06-26 05:45:06 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-09-18 17:29:28 +04:00
def testAlterRNG_EGD ( self ) :
guest , outfile = self . _get_test_content ( " change-rng-egd " )
dev1 = guest . get_devices ( " rng " ) [ 0 ]
check = self . _make_checker ( dev1 )
check ( " type " , " egd " )
2013-10-25 19:13:26 +04:00
check ( " backend_type " , " udp " , " udp " )
2013-09-18 17:29:28 +04:00
2013-10-25 19:13:26 +04:00
check ( " connect_host " , " 1.2.3.4 " , " 1.2.3.5 " )
check ( " connect_service " , " 1234 " , " 1235 " )
check ( " bind_host " , None , None )
check ( " bind_service " , " 1233 " , " 1236 " )
2013-09-18 17:29:28 +04:00
check ( " rate_bytes " , " 1234 " , " 4321 " )
check ( " rate_period " , " 2000 " , " 2001 " )
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
def testAlterRNG_Random ( self ) :
guest , outfile = self . _get_test_content ( " change-rng-random " )
dev1 = guest . get_devices ( " rng " ) [ 0 ]
check = self . _make_checker ( dev1 )
check ( " type " , " random " , " random " )
check ( " model " , " virtio " , " virtio " )
check ( " device " , " /dev/random " , " /dev/hwrng " )
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04:00
def testConsoleCompat ( self ) :
2013-07-12 17:19:28 +04:00
guest , outfile = self . _get_test_content ( " console-compat " )
2013-03-18 01:06:52 +04:00
dev1 = guest . get_devices ( " console " ) [ 0 ]
check = self . _make_checker ( dev1 )
check ( " source_path " , " /dev/pts/4 " )
2013-09-24 17:25:05 +04:00
check ( " _tty " , " /dev/pts/4 " , " foo " , " /dev/pts/4 " )
2013-03-18 01:06:52 +04:00
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04:00
2014-01-10 13:37:54 +04:00
def testPanicDevice ( self ) :
guest , outfile = self . _get_test_content ( " change-panic-device " )
dev1 = guest . get_devices ( " panic " ) [ 0 ]
check = self . _make_checker ( dev1 )
2014-01-14 07:45:36 +04:00
check ( " type " , " isa " , None , " isa " )
check ( " iobase " , " 0x505 " , None , " 0x506 " )
2014-01-10 13:37:54 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2018-02-19 23:14:27 +03:00
def testQEMUXMLNS ( self ) :
basename = " change-xmlns-qemu "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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-02-26 22:56:24 +03:00
self . assertEqual ( arg0 . get_xml_config ( ) ,
" <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 "
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
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
2013-03-18 01:06:52 +04:00
rmdev = guest . get_devices ( " disk " ) [ 2 ]
guest . remove_device ( rmdev )
2017-10-26 12:58:13 +03:00
# Basic device add
2018-03-20 19:18:35 +03:00
guest . add_device ( virtinst . DeviceWatchdog ( self . conn ) )
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 "
2014-01-28 04:54:41 +04:00
adddev . address . set_addrstr ( " spapr-vio " )
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 ' /> """ ) )
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , 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
disk = guest . get_devices ( " disk " ) [ 0 ]
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
disk = guest . get_devices ( " disk " ) [ 1 ]
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
disk = guest . get_devices ( " disk " ) [ 2 ]
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
disk = guest . get_devices ( " disk " ) [ 3 ]
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
disk = guest . get_devices ( " disk " ) [ 4 ]
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
2013-04-11 18:44:27 +04:00
self . _alter_compare ( guest . get_xml_config ( ) , outfile )
2013-03-18 01:06:52 +04:00
2013-08-06 01:20:35 +04:00
def testChangeSnapshot ( self ) :
basename = " change-snapshot "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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
utils . diff_compare ( snap . get_xml_config ( ) , outfile )
2013-07-12 17:19:28 +04:00
2013-09-10 01:14:16 +04:00
###################
# Interface tests #
###################
def testInterfaceBridgeIP ( self ) :
basename = " test-bridge-ip "
infile = " tests/interface-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/interface- %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
iface = virtinst . Interface ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-10 01:14:16 +04:00
2017-05-05 18:39:59 +03:00
self . assertEqual ( len ( iface . protocols ) , 2 )
self . assertEqual ( len ( iface . interfaces ) , 3 )
2013-09-10 01:14:16 +04:00
check = self . _make_checker ( iface )
check ( " type " , " bridge " , " foo " , " bridge " )
check ( " name " , " test-bridge-ip " , " foo-new " )
check ( " stp " , None , True )
check ( " delay " , None , 2 )
check = self . _make_checker ( iface . protocols [ 0 ] )
check ( " family " , " ipv4 " , " foo " , " ipv4 " )
check ( " dhcp_peerdns " , True , False )
check ( " gateway " , " 1.2.3.4 " , " 5.5.5.5 " )
2017-05-05 18:39:59 +03:00
self . assertEqual ( iface . protocols [ 0 ] . ips [ 1 ] . address , " 255.255.255.0 " )
2013-09-10 01:14:16 +04:00
check = self . _make_checker ( iface . protocols [ 1 ] )
check ( " dhcp " , True , False )
check ( " autoconf " , True , False )
check = self . _make_checker ( iface . protocols [ 1 ] . ips [ 1 ] )
2014-03-31 18:25:36 +04:00
check ( " address " , " fe80::215:58ff:fe6e:5 " , " 2002:: " )
2013-09-10 01:14:16 +04:00
check ( " prefix " , 64 , 38 )
# Remove a child interface, verify it's data remains intact
child_iface = iface . interfaces [ 1 ]
iface . remove_interface ( child_iface )
check = self . _make_checker ( child_iface )
check ( " name " , " bond-brbond " )
2017-05-05 18:39:59 +03:00
self . assertEqual ( len ( child_iface . interfaces ) , 2 )
2013-09-10 01:14:16 +04:00
utils . diff_compare ( iface . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , iface . get_xml_config ( ) , " interfaceDefineXML " )
2013-09-10 01:14:16 +04:00
def testInterfaceBondArp ( self ) :
basename = " test-bond-arp "
infile = " tests/interface-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/interface- %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
iface = virtinst . Interface ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-10 01:14:16 +04:00
check = self . _make_checker ( iface )
check ( " start_mode " , " onboot " , " hotplug " )
check ( " macaddr " , " AA:AA:AA:AA:AA:AA " , " AA:AA:AA:11:AA:AA " )
check ( " mtu " , 1501 , 1234 )
check ( " bond_mode " , None , " active-backup " )
check ( " arp_interval " , 100 , 234 )
check ( " arp_target " , " 192.168.100.200 " , " 1.2.3.4 " )
check ( " arp_validate_mode " , " backup " , " active " )
utils . diff_compare ( iface . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , iface . get_xml_config ( ) , " interfaceDefineXML " )
2013-09-10 01:14:16 +04:00
def testInterfaceBondMii ( self ) :
basename = " test-bond-mii "
infile = " tests/interface-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/interface- %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
iface = virtinst . Interface ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-10 01:14:16 +04:00
check = self . _make_checker ( iface )
check ( " mii_frequency " , 123 , 111 )
check ( " mii_downdelay " , 34 , 22 )
check ( " mii_updelay " , 12 , 33 )
check ( " mii_carrier_mode " , " netif " , " ioctl " )
utils . diff_compare ( iface . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , iface . get_xml_config ( ) , " interfaceDefineXML " )
2013-09-10 01:14:16 +04:00
def testInterfaceVLAN ( self ) :
basename = " test-vlan "
infile = " tests/interface-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/interface- %s -out.xml " % basename
2018-02-22 22:57:10 +03:00
iface = virtinst . Interface ( self . conn , parsexml = open ( infile ) . read ( ) )
2013-09-10 01:14:16 +04:00
check = self . _make_checker ( iface )
check ( " tag " , 123 , 456 )
check ( " parent_interface " , " eth2 " , " foonew " )
utils . diff_compare ( iface . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , iface . get_xml_config ( ) , " interfaceDefineXML " )
2013-09-10 01:14:16 +04:00
2013-09-20 04:18:12 +04:00
#################
# Storage tests #
#################
def testFSPool ( self ) :
basename = " pool-fs "
infile = " tests/xmlparse-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/ %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 " )
utils . diff_compare ( pool . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , pool . get_xml_config ( ) , " storagePoolDefineXML " )
2013-09-20 04:18:12 +04:00
def testISCSIPool ( self ) :
basename = " pool-iscsi "
infile = " tests/storage-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/ %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
utils . diff_compare ( pool . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , pool . get_xml_config ( ) , " storagePoolDefineXML " )
2013-09-20 04:18:12 +04:00
2014-02-12 13:39:50 +04:00
def testGlusterPool ( self ) :
2018-02-22 22:57:10 +03:00
if not self . conn . check_support ( self . conn . SUPPORT_CONN_POOL_GLUSTERFS ) :
2014-03-06 20:29:23 +04:00
raise unittest . SkipTest ( " Gluster pools not supported with this "
" libvirt version. " )
2014-02-12 13:39:50 +04:00
basename = " pool-gluster "
infile = " tests/storage-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/ %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 " )
utils . diff_compare ( pool . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , pool . get_xml_config ( ) , " storagePoolDefineXML " )
2014-12-10 00:05:02 +03:00
def testRBDPool ( self ) :
basename = " pool-rbd "
infile = " tests/xmlparse-xml/ %s .xml " % basename
outfile = " tests/xmlparse-xml/ %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
utils . diff_compare ( pool . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , pool . get_xml_config ( ) , " storagePoolDefineXML " )
2014-02-12 13:39:50 +04:00
2013-09-20 04:18:12 +04:00
def testVol ( self ) :
basename = " pool-dir-vol "
2013-09-29 03:11:27 +04:00
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
2013-09-20 04:18:12 +04:00
outfile = " tests/xmlparse-xml/ %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 " )
utils . diff_compare ( vol . get_xml_config ( ) , outfile )
2013-09-21 04:40:07 +04:00
###################
# <network> tests #
###################
def testNetMulti ( self ) :
basename = " network-multi "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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
check = self . _make_checker ( net . forward )
check ( " mode " , " nat " , " route " )
check ( " dev " , None , " eth22 " )
2014-06-25 14:27:00 +04:00
check = self . _make_checker ( net . bandwidth )
check ( " inbound_average " , " 1000 " , " 3000 " )
check ( " inbound_peak " , " 5000 " , " 4000 " )
check ( " inbound_burst " , " 5120 " , " 5220 " )
check ( " inbound_floor " , None , None )
check ( " outbound_average " , " 1000 " , " 2000 " )
check ( " outbound_peak " , " 5000 " , " 3000 " )
check ( " outbound_burst " , " 5120 " , " 5120 " )
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 " )
check ( " tftp " , None , " /var/lib/tftproot " )
check ( " bootp_file " , None , " pxeboot.img " )
check ( " bootp_server " , None , " 1.2.3.4 " )
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
utils . diff_compare ( net . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , net . get_xml_config ( ) , " networkDefineXML " )
2013-09-20 04:18:12 +04:00
2017-05-03 18:56:31 +03:00
def testNetOpen ( self ) :
basename = " network-open "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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 " )
utils . diff_compare ( net . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , net . get_xml_config ( ) , " networkDefineXML " )
2017-05-03 18:56:31 +03:00
2017-03-31 15:12:00 +03:00
def testNetVfPool ( self ) :
basename = " network-vf-pool "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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 " )
2017-09-22 14:39:09 +03:00
check = self . _make_checker ( net . forward . vfs [ 0 ] )
check ( " type " , " pci " )
check ( " domain " , 0x0000 )
check ( " bus " , 0x03 )
check ( " slot " , 0x10 )
check ( " function " , 0x0 )
2017-03-31 15:12:00 +03:00
utils . diff_compare ( net . get_xml_config ( ) , outfile )
2018-02-22 22:57:10 +03:00
utils . test_create ( self . conn , net . get_xml_config ( ) , " 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 "
infile = " tests/xmlparse-xml/ %s -in.xml " % basename
outfile = " tests/xmlparse-xml/ %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
2015-07-14 18:48:12 +03:00
guest . cpu . copy_host_cpu ( )
2014-01-25 23:57:10 +04:00
guest . cpu . clear ( )
utils . diff_compare ( guest . get_xml_config ( ) , outfile )
2018-02-20 18:10:08 +03:00
def testDomainRoundtrip ( self ) :
# Make sure our XML engine doesn't mangle non-libvirt XML bits
infile = " tests/xmlparse-xml/domain-roundtrip.xml "
outfile = " tests/xmlparse-xml/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
utils . diff_compare ( guest . get_xml_config ( ) , outfile )
2013-07-12 23:16:29 +04:00
2013-03-18 01:06:52 +04:00
if __name__ == " __main__ " :
unittest . main ( )