2015-04-04 21:27:13 +03:00
# Copyright (C) 2013 Red Hat, Inc.
#
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.
2015-04-04 21:27:13 +03:00
2020-09-18 23:26:28 +03:00
import pytest
2015-04-04 21:27:13 +03:00
2018-09-07 03:28:05 +03:00
from virtinst import Guest
2015-04-04 21:27:13 +03:00
from virtinst import OSDB
2020-07-18 01:58:00 +03:00
from virtinst import xmlutil
2019-06-17 04:34:47 +03:00
from virtinst . install import urldetect
2015-04-04 21:27:13 +03:00
from tests import utils
2020-09-18 23:26:28 +03:00
##################
# Test osdict.py #
##################
def test_list_os ( ) :
OSDB . list_os ( )
def test_recommended_resources ( ) :
conn = utils . URIs . open_testdefault_cached ( )
guest = Guest ( conn )
res = OSDB . lookup_os ( " generic " ) . get_recommended_resources ( )
assert res . get_recommended_ram ( guest . os . arch ) is None
res = OSDB . lookup_os ( " fedora21 " ) . get_recommended_resources ( )
assert res . get_recommended_ncpus ( guest . os . arch ) == 2
def test_urldetct_matching_distros ( ) :
# pylint: disable=protected-access
allstores = urldetect . _build_distro_list ( OSDB . lookup_os ( " generic " ) )
seen_distro = [ ]
for store in allstores :
for distro in store . matching_distros :
if distro in seen_distro :
raise xmlutil . DevError (
" store= %s has conflicting matching_distro= %s " %
( store . PRETTY_NAME , distro ) )
seen_distro . append ( distro )
def test_tree_url ( ) :
f26 = OSDB . lookup_os ( " fedora26 " )
f29 = OSDB . lookup_os ( " fedora29 " )
winxp = OSDB . lookup_os ( " winxp " )
# Valid tree URL
assert " fedoraproject.org " in f26 . get_location ( " x86_64 " )
# Most generic tree URL
assert " Everything " in f29 . get_location ( " x86_64 " )
# Specific tree
assert " Server " in f29 . get_location ( " x86_64 " , " jeos " )
assert " Workstation " in f29 . get_location ( " x86_64 " , " desktop " )
# Has tree URLs, but none for arch
try :
f26 . get_location ( " ia64 " )
raise AssertionError ( " Expected failure " )
except RuntimeError as e :
assert " ia64 " in str ( e )
# Has no tree URLs
try :
winxp . get_location ( " x86_64 " )
raise AssertionError ( " Expected failure " )
except RuntimeError as e :
assert str ( e ) . endswith ( " URL location " )
# Trigger an error path for code coverage
assert OSDB . guess_os_by_tree ( utils . TESTDIR ) is None
def test_kernel_url ( ) :
def _c ( name ) :
osobj = OSDB . lookup_os ( name )
if not osobj :
pytest . skip ( " osinfo-db doesn ' t have ' %s ' " % name )
return osobj . get_kernel_url_arg ( )
assert _c ( " rhel7-unknown " ) == " inst.repo "
assert _c ( " rhel6-unknown " ) == " method "
assert _c ( " fedora-rawhide " ) == " inst.repo "
assert _c ( " fedora20 " ) == " inst.repo "
assert _c ( " generic " ) is None
assert _c ( " win10 " ) is None
assert _c ( " sle15 " ) == " install "
def test_related_to ( ) :
# pylint: disable=protected-access
win10 = OSDB . lookup_os ( " win10 " )
assert win10 . _is_related_to ( " winxp " ) is True
assert win10 . _is_related_to ( " win10 " ) is True
assert win10 . _is_related_to ( " fedora26 " ) is False
def test_drivers ( ) :
win7 = OSDB . lookup_os ( " win7 " )
generic = OSDB . lookup_os ( " generic " )
assert generic . supports_unattended_drivers ( " x86_64 " ) is False
assert win7 . supports_unattended_drivers ( " x86_64 " ) is True
assert win7 . supports_unattended_drivers ( " fakearch " ) is False
assert win7 . get_pre_installable_drivers_location ( " x86_64 " )