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
2019-06-13 01:36:14 +03:00
import os
2015-04-04 21:27:13 +03:00
import unittest
2018-09-07 03:28:05 +03:00
from virtinst import Guest
2015-04-04 21:27:13 +03:00
from virtinst import OSDB
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
class TestOSDB ( unittest . TestCase ) :
"""
Test osdict / OSDB
"""
def test_osdict_aliases_ro ( self ) :
aliases = getattr ( OSDB , " _aliases " )
if len ( aliases ) != 42 :
raise AssertionError ( _ ( " OSDB._aliases changed size. It "
" should never be extended, since it is only for back "
" compat with pre-libosinfo osdict.py " ) )
2019-06-09 17:40:26 +03:00
def test_list_os ( self ) :
OSDB . list_os ( )
2015-04-04 21:27:13 +03:00
def test_recommended_resources ( self ) :
2018-02-22 22:57:10 +03:00
conn = utils . URIs . open_testdefault_cached ( )
2018-09-07 03:28:05 +03:00
guest = Guest ( conn )
2019-05-12 01:05:59 +03:00
res = OSDB . lookup_os ( " generic " ) . get_recommended_resources ( )
self . assertEqual ( res . get_recommended_ram ( guest . os . arch ) , None )
2015-04-04 21:27:13 +03:00
2019-05-12 01:05:59 +03:00
res = OSDB . lookup_os ( " fedora21 " ) . get_recommended_resources ( )
self . assertEqual ( res . get_recommended_ncpus ( guest . os . arch ) , 2 )
2015-04-04 21:27:13 +03:00
2018-09-01 15:41:22 +03:00
def test_urldetct_matching_distros ( self ) :
2019-06-16 21:09:28 +03:00
# pylint: disable=protected-access
allstores = urldetect . _build_distro_list ( OSDB . lookup_os ( " generic " ) )
2018-09-01 15:41:22 +03:00
seen_distro = [ ]
for store in allstores :
for distro in store . matching_distros :
if distro in seen_distro :
raise RuntimeError ( " programming error: "
" store= %s has conflicting matching_distro= %s " %
( store . PRETTY_NAME , distro ) )
seen_distro . append ( distro )
2019-02-18 18:59:35 +03:00
def test_tree_url ( self ) :
f26 = OSDB . lookup_os ( " fedora26 " )
2019-09-06 19:06:08 +03:00
f29 = OSDB . lookup_os ( " fedora29 " )
2019-02-18 18:59:35 +03:00
winxp = OSDB . lookup_os ( " winxp " )
# Valid tree URL
assert " fedoraproject.org " in f26 . get_location ( " x86_64 " )
2019-09-06 19:06:08 +03:00
# Most generic tree URL
assert " Everything " in f29 . get_location ( " x86_64 " )
2019-09-11 19:19:09 +03:00
# Specific tree
assert " Server " in f29 . get_location ( " x86_64 " , " jeos " )
assert " Workstation " in f29 . get_location ( " x86_64 " , " desktop " )
2019-02-18 18:59:35 +03:00
# 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 " )
2019-06-13 01:36:14 +03:00
# Trigger an error path for code coverage
self . assertEqual ( OSDB . guess_os_by_tree ( os . getcwd ( ) ) , None )
def test_kernel_url ( self ) :
def _c ( name ) :
osobj = OSDB . lookup_os ( name )
if not osobj :
self . skipTest ( " osinfo-db doesn ' t have ' %s ' " % name )
return osobj . get_kernel_url_arg ( )
self . assertEqual ( _c ( " rhel7-unknown " ) , " inst.repo " )
self . assertEqual ( _c ( " rhel6-unknown " ) , " method " )
self . assertEqual ( _c ( " fedora-rawhide " ) , " inst.repo " )
self . assertEqual ( _c ( " fedora20 " ) , " inst.repo " )
self . assertEqual ( _c ( " generic " ) , None )
self . assertEqual ( _c ( " win10 " ) , None )
self . assertEqual ( _c ( " sle15 " ) , " install " )
def test_related_to ( self ) :
# pylint: disable=protected-access
win10 = OSDB . lookup_os ( " win10 " )
self . assertTrue ( win10 . _is_related_to ( " winxp " ) )
self . assertTrue ( win10 . _is_related_to ( " win10 " ) )
self . assertTrue ( win10 . _is_related_to ( " fedora26 " ) is False )
2019-08-07 00:54:54 +03:00
def test_drivers ( self ) :
win7 = OSDB . lookup_os ( " win7 " )
generic = OSDB . lookup_os ( " generic " )
self . assertFalse ( generic . supports_unattended_drivers ( " x86_64 " ) )
self . assertTrue ( win7 . supports_unattended_drivers ( " x86_64 " ) )
self . assertFalse ( win7 . supports_unattended_drivers ( " fakearch " ) )
self . assertTrue ( win7 . get_pre_installable_drivers_location ( " x86_64 " ) )
2019-10-03 13:57:42 +03:00
2020-02-02 17:28:29 +03:00
self . assertFalse (
OSDB . lookup_os ( " fedora10 " ) . supports_unattended_agents ( " x86_64 " ) )
2019-10-03 13:57:42 +03:00
# Just call this for code coverage. Values differ by osinfo-db version
win7 . get_post_installable_drivers_location ( " x86_64 " )
2020-01-27 18:13:03 +03:00
win10 = OSDB . lookup_os ( " win10 " )
win10 . get_post_installable_drivers_location ( " x86_64 " )
win10 . supports_unattended_agents ( " x86_64 " )