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
2013-03-18 01:06:52 +04:00
import unittest
2013-08-09 04:47:17 +04:00
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-01-27 02:11:43 +03:00
DATADIR = " tests/data/capabilities "
2013-03-18 01:06:52 +04:00
class TestCapabilities ( unittest . TestCase ) :
2015-04-03 19:40:16 +03:00
def _buildCaps ( self , filename ) :
2020-01-27 02:11:43 +03:00
path = os . path . join ( DATADIR , filename )
2018-02-22 22:57:10 +03:00
conn = utils . URIs . open_testdefault_cached ( )
2017-05-05 21:19:54 +03:00
return Capabilities ( conn , open ( path ) . read ( ) )
2013-03-18 01:06:52 +04:00
def testCapsCPUFeaturesNewSyntax ( self ) :
2015-04-23 00:06:35 +03:00
filename = " test-qemu-with-kvm.xml "
2013-03-18 01:06:52 +04:00
host_feature_list = [ ' lahf_lm ' , ' xtpr ' , ' cx16 ' , ' tm2 ' , ' est ' , ' vmx ' ,
2015-04-03 19:40:16 +03:00
' ds_cpl ' , ' pbe ' , ' tm ' , ' ht ' , ' ss ' , ' acpi ' , ' ds ' ]
2013-03-18 01:06:52 +04:00
caps = self . _buildCaps ( filename )
2015-04-03 19:40:16 +03:00
for f in host_feature_list :
2018-06-12 18:17:33 +03:00
self . assertEqual (
f in [ feat . name for feat in caps . host . cpu . features ] , True )
2013-03-18 01:06:52 +04:00
2017-05-05 18:39:59 +03:00
self . assertEqual ( caps . host . cpu . model , " core2duo " )
self . assertEqual ( caps . host . cpu . vendor , " Intel " )
self . assertEqual ( caps . host . cpu . threads , 3 )
self . assertEqual ( caps . host . cpu . cores , 5 )
self . assertEqual ( caps . host . cpu . sockets , 7 )
2013-03-18 01:06:52 +04:00
def testCapsUtilFuncs ( self ) :
2015-04-23 00:06:35 +03:00
caps_with_kvm = self . _buildCaps ( " test-qemu-with-kvm.xml " )
caps_no_kvm = self . _buildCaps ( " test-qemu-no-kvm.xml " )
2018-06-12 18:17:33 +03:00
caps_empty = self . _buildCaps ( " test-empty.xml " )
2013-03-18 01:06:52 +04:00
2015-04-03 23:42:07 +03:00
def test_utils ( caps , has_guests , is_kvm ) :
2015-07-10 13:06:48 +03:00
if caps . guests :
2017-05-05 18:39:59 +03:00
self . assertEqual ( caps . guests [ 0 ] . has_install_options ( ) , has_guests )
self . assertEqual ( caps . guests [ 0 ] . is_kvm_available ( ) , is_kvm )
2015-04-03 23:39:47 +03:00
2015-04-23 00:06:35 +03:00
test_utils ( caps_empty , False , False )
test_utils ( caps_with_kvm , True , True )
test_utils ( caps_no_kvm , True , False )
2019-06-10 21:15:50 +03:00
# Small test for extra unittest coverage
with self . assertRaises ( ValueError ) :
caps_empty . guest_lookup ( os_type = " linux " )
2015-11-18 22:53:12 +03:00
def testCapsNuma ( self ) :
cells = self . _buildCaps ( " lxc.xml " ) . host . topology . cells
2017-05-05 18:39:59 +03:00
self . assertEqual ( len ( cells ) , 1 )
self . assertEqual ( len ( cells [ 0 ] . cpus ) , 8 )
self . assertEqual ( cells [ 0 ] . cpus [ 3 ] . id , ' 3 ' )
2015-11-18 22:53:12 +03:00
2015-04-23 00:06:35 +03:00
##############################
# domcapabilities.py testing #
##############################
2014-09-17 22:56:52 +04:00
def testDomainCapabilities ( self ) :
2020-01-27 02:11:43 +03:00
xml = open ( DATADIR + " /test-domcaps.xml " ) . read ( )
2018-02-22 22:57:10 +03:00
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
2014-09-17 22:56:52 +04:00
self . assertEqual ( caps . os . loader . supported , True )
2017-05-05 18:39:59 +03:00
self . assertEqual ( caps . os . loader . get_values ( ) ,
2014-09-17 22:56:52 +04:00
[ " /foo/bar " , " /tmp/my_path " ] )
2017-05-05 18:39:59 +03:00
self . assertEqual ( caps . os . loader . enum_names ( ) , [ " type " , " readonly " ] )
self . assertEqual ( caps . os . loader . get_enum ( " type " ) . get_values ( ) ,
2014-09-17 22:56:52 +04:00
[ " rom " , " pflash " ] )
2018-03-28 22:45:29 +03:00
def testDomainCapabilitiesx86 ( self ) :
2020-01-27 02:11:43 +03:00
xml = open ( DATADIR + " /kvm-x86_64-domcaps.xml " ) . read ( )
2018-03-28 22:45:29 +03:00
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
2018-10-04 19:22:22 +03:00
self . assertEqual ( caps . machine , " pc-i440fx-2.1 " )
self . assertEqual ( caps . arch , " x86_64 " )
self . assertEqual ( caps . domain , " kvm " )
self . assertEqual ( caps . path , " /bin/qemu-system-x86_64 " )
2018-03-28 22:45:29 +03:00
custom_mode = caps . cpu . get_mode ( " custom " )
self . assertTrue ( bool ( custom_mode ) )
cpu_model = custom_mode . get_model ( " Opteron_G4 " )
self . assertTrue ( bool ( cpu_model ) )
self . assertTrue ( cpu_model . usable )
2020-01-27 18:06:18 +03:00
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 " )
def testDomainCapabilitiesAArch64 ( self ) :
xml = open ( DATADIR + " /kvm-aarch64-domcaps.xml " ) . read ( )
caps = DomainCapabilities ( utils . URIs . open_testdriver_cached ( ) , xml )
assert " None " in caps . label_for_firmware_path ( None )