2014-03-12 15:36:17 +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
2013-08-09 04:47:17 +04:00
import os
2020-09-17 21:33:17 +03:00
import pytest
2014-03-13 15:52:51 +04:00
from tests import utils
2013-03-18 01:06:52 +04:00
2015-04-03 19:40:16 +03:00
from virtinst import Capabilities
from virtinst import DomainCapabilities
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
2020-08-30 15:54:41 +03:00
DATADIR = utils . DATADIR + " /capabilities "
2020-01-27 02:11:43 +03:00
2020-09-18 23:26:28 +03:00
def _buildCaps ( filename ) :
path = os . path . join ( DATADIR , filename )
conn = utils . URIs . open_testdefault_cached ( )
return Capabilities ( conn , open ( path ) . read ( ) )
def testCapsCPUFeaturesNewSyntax ( ) :
filename = " test-qemu-with-kvm.xml "
host_feature_list = [ ' lahf_lm ' , ' xtpr ' , ' cx16 ' , ' tm2 ' , ' est ' , ' vmx ' ,
' ds_cpl ' , ' pbe ' , ' tm ' , ' ht ' , ' ss ' , ' acpi ' , ' ds ' ]
caps = _buildCaps ( filename )
for f in host_feature_list :
assert f in [ feat . name for feat in caps . host . cpu . features ]
assert caps . host . cpu . model == " core2duo "
assert caps . host . cpu . vendor == " Intel "
assert caps . host . cpu . topology . threads == 3
assert caps . host . cpu . topology . cores == 5
assert caps . host . cpu . topology . sockets == 7
def testCapsUtilFuncs ( ) :
caps_with_kvm = _buildCaps ( " test-qemu-with-kvm.xml " )
caps_no_kvm = _buildCaps ( " test-qemu-no-kvm.xml " )
caps_empty = _buildCaps ( " test-empty.xml " )
def test_utils ( caps , has_guests , is_kvm ) :
assert caps . has_install_options ( ) == has_guests
if caps . guests :
assert caps . guests [ 0 ] . is_kvm_available ( ) == is_kvm
test_utils ( caps_empty , False , False )
test_utils ( caps_with_kvm , True , True )
test_utils ( caps_no_kvm , True , False )
# Small test for extra coverage
with pytest . raises ( ValueError , match = r " .*virtualization type ' xen ' .* " ) :
caps_empty . guest_lookup ( os_type = " linux " )
with pytest . raises ( ValueError , match = r " .*not support any.* " ) :
caps_empty . guest_lookup ( )
def testCapsNuma ( ) :
cells = _buildCaps ( " lxc.xml " ) . host . topology . cells
assert len ( cells ) == 1
assert len ( cells [ 0 ] . cpus ) == 8
assert cells [ 0 ] . cpus [ 3 ] . id == ' 3 '
##############################
# domcapabilities.py testing #
##############################
def testDomainCapabilities ( ) :
xml = open ( DATADIR + " /test-domcaps.xml " ) . read ( )
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
assert caps . os . loader . supported is True
assert caps . os . loader . get_values ( ) == [ " /foo/bar " , " /tmp/my_path " ]
assert caps . os . loader . enum_names ( ) == [ " type " , " readonly " ]
assert caps . os . loader . get_enum ( " type " ) . get_values ( ) == [
" rom " , " pflash " ]
2020-09-28 20:44:34 +03:00
assert caps . os . loader . get_enum ( " idontexist " ) . get_values ( ) == [ ]
2020-09-18 23:26:28 +03:00
def testDomainCapabilitiesx86 ( ) :
xml = open ( DATADIR + " /kvm-x86_64-domcaps.xml " ) . read ( )
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
2022-01-24 21:53:23 +03:00
assert caps . machine == " pc-i440fx-6.1 "
2020-09-18 23:26:28 +03:00
assert caps . arch == " x86_64 "
assert caps . domain == " kvm "
2022-01-24 21:53:23 +03:00
assert caps . path == " /usr/bin/qemu-system-x86_64 "
2020-09-18 23:26:28 +03:00
custom_mode = caps . cpu . get_mode ( " custom " )
assert bool ( custom_mode )
cpu_model = custom_mode . get_model ( " Opteron_G4 " )
assert bool ( cpu_model )
assert cpu_model . usable
models = caps . get_cpu_models ( )
assert len ( models ) > 10
assert " SandyBridge " in models
assert caps . label_for_firmware_path ( None ) == " BIOS "
assert " Custom: " in caps . label_for_firmware_path ( " /foobar " )
assert " UEFI " in caps . label_for_firmware_path ( " OVMF " )
2021-10-14 16:18:17 +03:00
assert caps . supports_filesystem_virtiofs ( )
assert caps . supports_memorybacking_memfd ( )
2020-09-18 23:26:28 +03:00
def testDomainCapabilitiesAArch64 ( ) :
xml = open ( DATADIR + " /kvm-aarch64-domcaps.xml " ) . read ( )
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
2022-01-26 21:08:55 +03:00
assert " Default " in caps . label_for_firmware_path ( None )
2021-10-14 16:18:17 +03:00
assert not caps . supports_filesystem_virtiofs ( )
assert not caps . supports_memorybacking_memfd ( )