Testsuite: add new "make testraid" target for RAID-1 installation testing

(cherry picked from commit 462c5f80e086b1f5f74c564b3cb53df230b06d6b)
This commit is contained in:
Christian Poessinger 2021-12-09 10:17:25 +01:00
parent fcf34f734f
commit eeb90e20d9
2 changed files with 64 additions and 25 deletions

View File

@ -278,6 +278,11 @@ testd: checkiso
testc: checkiso
scripts/check-qemu-install --debug --configd --configtest build/live-image-amd64.hybrid.iso
.PHONY: testraid
.ONESHELL:
testraid: checkiso
scripts/check-qemu-install --debug --configd --raid --configtest build/live-image-amd64.hybrid.iso
.PHONY: clean
.ONESHELL:
clean:

View File

@ -65,6 +65,7 @@ parser.add_argument('--debug', help='Send all debug output to stdout',
action='store_true', default=False)
parser.add_argument('--logfile', help='Log to file')
parser.add_argument('--uefi', help='Boot using UEFI', action='store_true', default=False)
parser.add_argument('--raid', help='Perform a RAID-1 install', action='store_true', default=False)
parser.add_argument('--no-kvm', help='Disable use of kvm', action='store_true', default=False)
parser.add_argument('--configd', help='Execute testsuite with config daemon',
action='store_true', default=False)
@ -104,7 +105,7 @@ def get_half_cpus():
cpu /= 2
return int(cpu)
def get_qemu_cmd(name, enable_kvm, enable_uefi, disk_img, iso_img=None):
def get_qemu_cmd(name, enable_kvm, enable_uefi, disk_img, raid=None, iso_img=None):
kvm = "-enable-kvm"
cpu = "-cpu host"
if not enable_kvm:
@ -141,6 +142,9 @@ def get_qemu_cmd(name, enable_kvm, enable_uefi, disk_img, iso_img=None):
-nographic {cpu} {cdrom} {kvm} \
-drive format=raw,file={disk_img}'
if raid:
cmd += f' -drive format=raw,file={raid}'
return cmd
@ -187,19 +191,31 @@ else:
kvm=True
# Creating diskimage!!
if not os.path.isfile(args.disk):
log.info(f'Creating Disk image {args.disk}')
c = subprocess.check_output(['qemu-img', 'create', args.disk, '2G'])
log.debug(c.decode())
else:
log.info('Diskimage already exists, using the existing one')
diskname_raid = None
def gen_disk(name):
if not os.path.isfile(name):
log.info(f'Creating Disk image {name}')
c = subprocess.check_output(['qemu-img', 'create', name, '2G'])
log.debug(c.decode())
else:
log.info(f'Diskimage "{name}" already exists, using the existing one.')
if args.raid:
filename, ext = os.path.splitext(args.disk)
diskname_raid = f'{filename}_disk1{ext}'
# change primary diskname, too
args.disk = f'{filename}_disk0{ext}'
gen_disk(diskname_raid)
# must be called after the raid disk as args.disk name is altered in the RAID path
gen_disk(args.disk)
try:
#################################################
# Installing image to disk
#################################################
log.info('Installing system')
cmd = get_qemu_cmd('TESTVM', kvm, args.uefi, args.disk, args.iso)
cmd = get_qemu_cmd('TESTVM', kvm, args.uefi, args.disk, diskname_raid, args.iso)
log.debug(f'Executing command: {cmd}')
c = pexpect.spawn(cmd, logfile=stl)
@ -232,17 +248,26 @@ try:
c.sendline('install image')
c.expect('\nWould you like to continue?.*:')
c.sendline('yes')
log.info('Partitioning disk')
c.expect('\nPartition.*:')
c.sendline('')
c.expect('\nInstall the image on.*:')
c.sendline('')
c.expect(r'\nContinue\?.*:')
c.sendline('Yes')
c.expect('\nHow big of a root partition should I create?.*:')
c.sendline('')
log.info('Disk partitioned, installing')
c.expect('\nWhat would you like to name this image?.*:')
if args.raid:
c.expect('\nWould you like to configure RAID-1 mirroring on them?.*:')
c.sendline('yes')
# Erase all data on disks
c.expect('\nAre you sure you want to do this?.*:')
c.sendline('yes')
else:
log.info('Partitioning disk')
c.expect('\nPartition.*:')
c.sendline('')
c.expect('\nInstall the image on.*:')
c.sendline('')
c.expect(r'\nContinue\?.*:')
c.sendline('Yes')
c.expect('\nHow big of a root partition should I create?.*:')
c.sendline('')
log.info('Disk(s) partitioned, installing...')
c.expect('\nWhat would you like to name this image?.*:', timeout=300)
c.sendline('')
log.info('Copying files')
c.expect('\nWhich one should I copy to.*:', timeout=300)
@ -252,9 +277,12 @@ try:
c.sendline(default_user)
c.expect('\nRetype password for user.*:')
c.sendline(default_password)
c.expect('\nWhich drive should GRUB modify the boot partition on.*:')
c.sendline('')
c.expect(r'\nvyos@vyos:~\$')
if not args.raid:
c.expect('\nWhich drive should GRUB modify the boot partition on.*:')
c.sendline('')
c.expect(op_mode_prompt)
log.info('system installed, shutting down')
#################################################
@ -278,7 +306,7 @@ try:
# Booting installed system
#################################################
log.info('Booting installed system')
cmd = get_qemu_cmd('TESTVM', kvm, args.uefi, args.disk)
cmd = get_qemu_cmd('TESTVM', kvm, args.uefi, args.disk, diskname_raid)
log.debug(f'Executing command: {cmd}')
c = pexpect.spawn(cmd, logfile=stl)
@ -330,12 +358,16 @@ try:
c.sendline('show interfaces')
c.expect(r'vyos@vyos:~\$')
if args.raid:
c.sendline('cat /proc/mdstat')
c.expect(op_mode_prompt)
#################################################
# Executing test-suite
#################################################
# run default smoketest suite
if not args.configtest:
if not args.raid and not args.configtest:
log.info('Executing VyOS smoketests')
c.sendline('/usr/bin/vyos-smoketest')
i = c.expect(['\n +Invalid command:', '\n +Set failed',
@ -360,7 +392,7 @@ try:
raise Exception("Smoketest-failed, please look into debug output")
# else, run configtest suite
else:
elif not args.raid:
log.info('Generating a WireGuard default keypair')
c.sendline('generate wireguard default-keypair')
c.expect(r'vyos@vyos:~\$')
@ -462,6 +494,8 @@ if not args.keep:
log.info(f'Removing disk file: {args.disk}')
try:
os.remove(args.disk)
if diskname_raid:
os.remove(diskname_raid)
except Exception:
log.error('Exception while removing diskimage!')
log.error(traceback.format_exc())