2014-02-06 12:12:12 +01:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2018-03-20 15:00:02 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-09-28 14:42:37 -04:00
import os
import sys
import unittest
_alldistros = { }
2016-06-17 18:41:50 -04:00
DEVFEDORA_URL = " http://dl.fedoraproject.org/pub/fedora/linux/development/ %s /Server/ %s /os/ "
2015-03-26 19:37:17 -04:00
FEDORA_URL = " http://dl.fedoraproject.org/pub/fedora/linux/releases/ %s /Server/ %s /os/ "
2013-09-28 14:42:37 -04:00
2018-10-09 14:18:36 -04:00
( WARN_RHEL5 ,
2018-10-09 15:40:46 -04:00
WARN_DEBIAN ,
WARN_FEDORA ) = range ( 1 , 4 )
2014-09-20 15:21:03 -04:00
2013-09-28 14:42:37 -04:00
def prompt ( ) :
sys . stdout . write ( " (press enter to continue) " )
2018-01-27 15:23:04 -05:00
sys . stdout . flush ( )
2013-09-28 14:42:37 -04:00
return sys . stdin . readline ( )
2020-01-26 18:11:43 -05:00
KSOLD = " tests/data/inject/old-kickstart.ks "
KSNEW = " tests/data/inject/new-kickstart.ks "
PRESEED = " tests/data/inject/preseed.cfg "
2018-10-09 15:40:46 -04:00
2013-09-28 14:42:37 -04:00
class Distro ( object ) :
2018-10-09 15:40:46 -04:00
def __init__ ( self , name , url , filename , warntype = WARN_FEDORA ) :
2013-09-28 14:42:37 -04:00
self . name = name
self . url = url
2014-09-20 15:21:03 -04:00
self . warntype = warntype
2018-10-09 15:40:46 -04:00
self . filename = filename
2013-09-28 14:42:37 -04:00
self . kernel = None
self . initrd = None
def _add ( * args , * * kwargs ) :
_d = Distro ( * args , * * kwargs )
_alldistros [ _d . name ] = _d
2017-06-07 12:40:46 -04:00
_add ( " centos-5.11 " , " http://vault.centos.org/5.11/os/x86_64/ " ,
2018-10-09 15:40:46 -04:00
warntype = WARN_RHEL5 , filename = KSOLD )
2014-09-20 15:21:03 -04:00
_add ( " centos-6-latest " , " http://ftp.linux.ncsu.edu/pub/CentOS/6/os/x86_64/ " ,
2018-10-09 15:40:46 -04:00
warntype = WARN_RHEL5 , filename = KSOLD )
2014-09-20 15:21:03 -04:00
_add ( " centos-7-latest " , " http://ftp.linux.ncsu.edu/pub/CentOS/7/os/x86_64/ " ,
2018-10-09 15:40:46 -04:00
filename = KSNEW )
2019-04-03 20:23:21 -04:00
_add ( " fedora-29 " , FEDORA_URL % ( " 29 " , " x86_64 " ) , filename = KSNEW )
_add ( " fedora-30 " , DEVFEDORA_URL % ( " 30 " , " x86_64 " ) , filename = KSNEW )
2018-10-09 15:40:46 -04:00
_add ( " debian-9 " ,
" http://ftp.us.debian.org/debian/dists/stretch/main/installer-amd64/ " ,
filename = PRESEED , warntype = WARN_DEBIAN )
2013-09-28 14:42:37 -04:00
def _test_distro ( distro ) :
2014-09-20 15:21:03 -04:00
os . system ( " clear " )
2017-05-05 14:16:59 -04:00
print ( " \n " )
2018-10-09 14:18:36 -04:00
if distro . warntype == WARN_RHEL5 :
2017-05-05 14:16:59 -04: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 15:40:46 -04: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 :
2017-05-05 14:16:59 -04:00
print ( " RHEL7, Fedora >= 17: Chokes on the bogus URI in the early " )
print ( " console screen when fetching the installer squashfs image. " )
2014-09-20 15:21:03 -04:00
2018-10-13 16:30:19 -04:00
os . environ . pop ( " VIRTINST_TEST_SUITE " , None )
os . environ [ " VIRTINST_INITRD_TEST " ] = " 1 "
2013-09-28 14:42:37 -04:00
2018-10-09 15:40:46 -04:00
if distro . warntype == WARN_DEBIAN :
append = " auto=true "
else :
2018-10-13 16:30:19 -04:00
append = " \" ks=file:/ %s \" " % os . path . basename ( distro . filename )
2018-10-14 19:06:06 -04:00
cmd = ( " ./virt-install --connect qemu:///system "
2018-10-13 16:30:19 -04:00
" --name __virtinst__test__initrd__ --ram 2048 "
" --transient --destroy-on-exit --disk none "
2019-06-12 16:56:37 -04:00
" --location %s --initrd-inject %s "
" --install kernel_args= %s ,kernel_args_overwrite=yes " %
2018-10-13 16:30:19 -04:00
( distro . url , distro . filename , append ) )
2017-05-05 14:16:59 -04:00
print ( " \n \n " + cmd )
2013-09-28 14:42:37 -04:00
os . system ( cmd )
_printinitrd = False
2018-10-13 17:54:07 -04:00
2013-09-28 14:42:37 -04:00
class InjectTests ( unittest . TestCase ) :
def setUp ( self ) :
global _printinitrd
if _printinitrd :
return
2017-05-05 14:16:59 -04:00
print ( """
2013-09-28 14:42:37 -04:00
2018-10-13 16:30:19 -04: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 14:42:37 -04:00
2017-05-05 14:16:59 -04:00
""" )
2013-09-28 14:42:37 -04:00
prompt ( )
_printinitrd = True
def _make_tests ( ) :
def _make_check_cb ( _d ) :
return lambda s : _test_distro ( _d )
idx = 0
2016-06-17 18:41:50 -04:00
for dname , dobj in _alldistros . items ( ) :
2013-09-28 14:42:37 -04:00
idx + = 1
2016-06-17 18:41:50 -04:00
setattr ( InjectTests , " testInitrd %.3d _ %s " %
( idx , dname . replace ( " - " , " _ " ) ) , _make_check_cb ( dobj ) )
2013-09-28 14:42:37 -04:00
_make_tests ( )