diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-12-09 10:17:25 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-12-09 22:40:44 +0100 |
commit | 462c5f80e086b1f5f74c564b3cb53df230b06d6b (patch) | |
tree | eb4f95a35ada3c40669a95c24fe162bb399e9570 /scripts | |
parent | 2aa0166d87c9ebd024dc8aff950bfb11492f59ea (diff) | |
download | vyos-build-462c5f80e086b1f5f74c564b3cb53df230b06d6b.tar.gz vyos-build-462c5f80e086b1f5f74c564b3cb53df230b06d6b.zip |
Testsuite: add new "make testraid" target for RAID-1 installation testing
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/check-qemu-install | 84 |
1 files changed, 59 insertions, 25 deletions
diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index cd57a06f..3053a479 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -66,6 +66,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) @@ -110,7 +111,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: @@ -150,6 +151,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 @@ -196,12 +200,24 @@ 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) test_timeout = 3 *3600 # 3 hours (in seconds) try: @@ -209,7 +225,7 @@ 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) @@ -242,17 +258,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) @@ -262,9 +287,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(op_mode_prompt) + + 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') ################################################# @@ -288,7 +316,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) @@ -345,12 +373,16 @@ try: c.sendline('show interfaces') c.expect(op_mode_prompt) + 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: if args.no_interfaces: # remove interface tests as they consume a lot of time c.sendline('sudo rm -f /usr/libexec/vyos/tests/smoke/cli/test_interfaces_*') @@ -380,7 +412,7 @@ try: raise Exception("Smoketest-failed, please look into debug output") # else, run configtest suite - else: + elif not args.raid: log.info('Adding a legacy WireGuard default keypair for migrations') c.sendline('sudo mkdir -p /config/auth/wireguard/default') c.expect(op_mode_prompt) @@ -486,6 +518,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()) |