2014-02-06 15:12:12 +04:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2018-03-20 22:00:02 +03: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-09-28 22:42:37 +04:00
import os
import sys
_alldistros = { }
2016-06-18 01:41:50 +03:00
DEVFEDORA_URL = " http://dl.fedoraproject.org/pub/fedora/linux/development/ %s /Server/ %s /os/ "
2015-03-27 02:37:17 +03:00
FEDORA_URL = " http://dl.fedoraproject.org/pub/fedora/linux/releases/ %s /Server/ %s /os/ "
2013-09-28 22:42:37 +04:00
2018-10-09 21:18:36 +03:00
( WARN_RHEL5 ,
2018-10-09 22:40:46 +03:00
WARN_DEBIAN ,
WARN_FEDORA ) = range ( 1 , 4 )
2014-09-20 23:21:03 +04:00
2013-09-28 22:42:37 +04:00
def prompt ( ) :
sys . stdout . write ( " (press enter to continue) " )
2018-01-27 23:23:04 +03:00
sys . stdout . flush ( )
2013-09-28 22:42:37 +04:00
return sys . stdin . readline ( )
2020-01-27 02:11:43 +03:00
KSOLD = " tests/data/inject/old-kickstart.ks "
KSNEW = " tests/data/inject/new-kickstart.ks "
PRESEED = " tests/data/inject/preseed.cfg "
2018-10-09 22:40:46 +03:00
2013-09-28 22:42:37 +04:00
class Distro ( object ) :
2018-10-09 22:40:46 +03:00
def __init__ ( self , name , url , filename , warntype = WARN_FEDORA ) :
2013-09-28 22:42:37 +04:00
self . name = name
self . url = url
2014-09-20 23:21:03 +04:00
self . warntype = warntype
2018-10-09 22:40:46 +03:00
self . filename = filename
2013-09-28 22:42:37 +04:00
self . kernel = None
self . initrd = None
def _add ( * args , * * kwargs ) :
_d = Distro ( * args , * * kwargs )
_alldistros [ _d . name ] = _d
2022-03-01 22:14:06 +03:00
_add ( " centos5.11 " , " http://vault.centos.org/5.11/os/x86_64/ " ,
2018-10-09 22:40:46 +03:00
warntype = WARN_RHEL5 , filename = KSOLD )
2022-03-01 22:14:06 +03:00
_add ( " centos6.10 " , " http://vault.centos.org/6.10/os/x86_64 " ,
2018-10-09 22:40:46 +03:00
warntype = WARN_RHEL5 , filename = KSOLD )
2022-03-01 22:14:06 +03:00
_add ( " centos7latest " , " http://ftp.linux.ncsu.edu/pub/CentOS/7/os/x86_64/ " ,
2018-10-09 22:40:46 +03:00
filename = KSNEW )
2022-03-01 22:14:06 +03:00
_add ( " centos8stream " ,
" http://ftp.linux.ncsu.edu/pub/CentOS/8-stream/BaseOS/x86_64/os/ " ,
filename = KSNEW )
_add ( " fedora35 " , FEDORA_URL % ( " 29 " , " x86_64 " ) , filename = KSNEW )
_add ( " fedora36 " , DEVFEDORA_URL % ( " 35 " , " x86_64 " ) , filename = KSNEW )
_add ( " debian9 " ,
2018-10-09 22:40:46 +03:00
" http://ftp.us.debian.org/debian/dists/stretch/main/installer-amd64/ " ,
filename = PRESEED , warntype = WARN_DEBIAN )
2022-03-01 22:14:06 +03:00
_add ( " debian11 " ,
" http://ftp.us.debian.org/debian/dists/bullseye/main/installer-amd64/ " ,
filename = PRESEED , warntype = WARN_DEBIAN )
2013-09-28 22:42:37 +04:00
def _test_distro ( distro ) :
2014-09-20 23:21:03 +04:00
os . system ( " clear " )
2017-05-05 21:16:59 +03:00
print ( " \n " )
2018-10-09 21:18:36 +03:00
if distro . warntype == WARN_RHEL5 :
2017-05-05 21:16:59 +03:00
print ( " RHEL5, RHEL6, Fedora < 17: You ' ll get an error about a " )
print ( " bogus bootproto ITREADTHEKICKSTART. This means anaconda " )
print ( " read our busted kickstart. " )
2018-10-09 22:40:46 +03:00
elif distro . warntype == WARN_DEBIAN :
print ( " Debian: Won ' t ask any questions, will autoconfig network, "
" then print a big red text box about a bad mirror config. " )
elif distro . warntype == WARN_FEDORA :
2022-03-01 22:14:06 +03:00
print ( " RHEL, Fedora >= 17: Chokes on the bogus URI in the early " )
2017-05-05 21:16:59 +03:00
print ( " console screen when fetching the installer squashfs image. " )
2014-09-20 23:21:03 +04:00
2018-10-13 23:30:19 +03:00
os . environ . pop ( " VIRTINST_TEST_SUITE " , None )
os . environ [ " VIRTINST_INITRD_TEST " ] = " 1 "
2013-09-28 22:42:37 +04:00
2018-10-09 22:40:46 +03:00
if distro . warntype == WARN_DEBIAN :
append = " auto=true "
else :
2018-10-13 23:30:19 +03:00
append = " \" ks=file:/ %s \" " % os . path . basename ( distro . filename )
2018-10-15 02:06:06 +03:00
cmd = ( " ./virt-install --connect qemu:///system "
2018-10-13 23:30:19 +03:00
" --name __virtinst__test__initrd__ --ram 2048 "
" --transient --destroy-on-exit --disk none "
2019-06-12 23:56:37 +03:00
" --location %s --initrd-inject %s "
2022-08-04 22:06:17 +03:00
" --install kernel_args= %s ,kernel_args_overwrite=yes " %
2018-10-13 23:30:19 +03:00
( distro . url , distro . filename , append ) )
2017-05-05 21:16:59 +03:00
print ( " \n \n " + cmd )
2013-09-28 22:42:37 +04:00
os . system ( cmd )
2020-09-18 23:26:28 +03:00
def _print_intro ( ) :
print ( """
2013-09-28 22:42:37 +04:00
2018-10-13 23:30:19 +03:00
This is an interactive test suite .
We are going to launch various transient virt - installs , using initrd
injections , that will cause installs to quickly fail . Look for the
failure pattern to confirm that initrd injections are working as expected .
2013-09-28 22:42:37 +04:00
2017-05-05 21:16:59 +03:00
""" )
2020-09-18 23:26:28 +03:00
prompt ( )
2013-09-28 22:42:37 +04:00
2020-09-18 23:26:28 +03:00
def _build_testfunc ( dobj , do_setup ) :
def testfunc ( ) :
if do_setup :
_print_intro ( )
_test_distro ( dobj )
return testfunc
2013-09-28 22:42:37 +04:00
2020-09-18 23:26:28 +03:00
def _make_tests ( ) :
2013-09-28 22:42:37 +04:00
idx = 0
2016-06-18 01:41:50 +03:00
for dname , dobj in _alldistros . items ( ) :
2013-09-28 22:42:37 +04:00
idx + = 1
2022-03-01 22:14:06 +03:00
name = " testInitrd %.3d _ %s " % ( idx , dname )
2020-09-18 23:26:28 +03:00
do_setup = idx == 1
testfunc = _build_testfunc ( dobj , do_setup )
globals ( ) [ name ] = testfunc
2013-09-28 22:42:37 +04:00
_make_tests ( )