diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/check-qemu-install | 122 |
1 files changed, 60 insertions, 62 deletions
diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index 5c297792..086a1f8d 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -43,7 +43,8 @@ import traceback import logging import re -from io import BytesIO, StringIO +from io import BytesIO +from io import StringIO from datetime import datetime EXCEPTION = 0 @@ -170,33 +171,33 @@ else: output = sys.stdout.buffer if not os.path.isfile(args.iso): - log.error("Unable to find iso image to install") + log.error('Unable to find iso image to install') sys.exit(1) if args.no_kvm: - log.error("KVM forced off by command line") + log.error('KVM forced off by command line') kvm=False -elif not os.path.exists("/dev/kvm"): - log.error("KVM is not enabled on host, proceeding with software emulation") +elif not os.path.exists('/dev/kvm'): + log.error('KVM not enabled on host, proceeding with software emulation') kvm=False else: kvm=True # Creating diskimage!! if not os.path.isfile(args.disk): - log.info("Creating Disk image {}".format(args.disk)) - c = subprocess.check_output(["qemu-img", "create", args.disk, "2G"]) + 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") + log.info('Diskimage already exists, using the existing one') try: ################################################# # Installing image to disk ################################################# - log.info("Installing system") - cmd = get_qemu_cmd("TESTVM", kvm, args.disk, args.iso) - log.debug("Executing command: {}".format(cmd)) + log.info('Installing system') + cmd = get_qemu_cmd('TESTVM', kvm, args.disk, args.iso) + log.debug('Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) ################################################# @@ -206,7 +207,7 @@ try: c.expect('Automatic boot in', timeout=10) c.sendline('') except pexpect.TIMEOUT: - log.warning("Did not find grub countdown window, ignoring") + log.warning('Did not find GRUB countdown window, ignoring') log.info('Waiting for login prompt') c.expect('[Ll]ogin:', timeout=300) @@ -219,11 +220,11 @@ try: ################################################# # Installing into VyOS system ################################################# - log.info("Starting installer") + log.info('Starting installer') c.sendline('install image') c.expect('\nWould you like to continue?.*:') c.sendline('yes') - log.info("Partitioning disk") + log.info('Partitioning disk') c.expect('\nPartition.*:') c.sendline('') c.expect('\nInstall the image on.*:') @@ -251,26 +252,26 @@ try: ################################################# # Powering down installer ################################################# - log.info("Shutting down installation system") + log.info('Shutting down installation system') c.sendline('poweroff') c.expect(r'\nAre you sure you want to poweroff this system.*\]') c.sendline('Y') for i in range(30): - log.info("Waiting for shutdown...") + log.info('Waiting for shutdown...') if not c.isalive(): - log.info("VM is shut down!") + log.info('VM shutdown!') break time.sleep(10) else: - log.error("VM Did not shut down after 300sec, killing") + log.error('VM Did not shutdown after 300sec, killing it!') c.close() ################################################# # Booting installed system ################################################# - log.info("Booting installed system") - cmd = get_qemu_cmd("TESTVM", kvm, args.disk) - log.debug('Executing command: {}'.format(cmd)) + log.info('Booting installed system') + cmd = get_qemu_cmd('TESTVM', kvm, args.disk) + log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) ################################################# @@ -280,7 +281,7 @@ try: c.expect('The highlighted entry will be executed automatically in', timeout=10) c.sendline('') except pexpect.TIMEOUT: - log.warning("Did not find grub countdown window, ignoring") + log.warning('Did not find GRUB countdown window, ignoring') log.info('Waiting for login prompt') c.expect('[Ll]ogin:', timeout=300) @@ -304,15 +305,14 @@ try: ################################################# if args.configd: c.sendline('sudo systemctl start vyos-configd.service &> /dev/null') - c.expect(r'vyos@vyos:~\$') else: c.sendline('sudo systemctl stop vyos-configd.service &> /dev/null') - c.expect(r'vyos@vyos:~\$') + c.expect(r'vyos@vyos:~\$') ################################################# # Basic Configmode/Opmode switch ################################################# - log.info("Basic CLI configuration mode test") + log.info('Basic CLI configuration mode test') c.sendline('configure') c.expect(r'vyos@vyos#') c.sendline('run show version') @@ -322,58 +322,55 @@ try: ################################################# # Executing test-suite ################################################# - log.info("Executing test-suite ") # run default smoketest suite if not args.configtest: + log.info('Executing VyOS smoketests') c.sendline('/usr/bin/vyos-smoketest') - i = c.expect(['\n +Invalid command:', - '\n +Set failed', - 'No such file or directory', - r'\n\S+@\S+[$#]'], timeout=7200) + i = c.expect(['\n +Invalid command:', '\n +Set failed', + 'No such file or directory', r'\n\S+@\S+[$#]'], timeout=7200) - if i==0: + if i == 0: raise Exception('Invalid command detected') - elif i==1: + elif i == 1: raise Exception('Set syntax failed :/') - elif i==2: - log.error("Did not find VyOS smoketest, this should be an exception") - raise Exception("WTF? did not find VyOS smoketest, this should be an exception") + elif i == 2: + tmp = '(W)hy (T)he (F)ace? VyOS smoketest not found!' + log.error(tmp) + raise Exception(tmp) c.sendline('echo EXITCODE:$\x16?') i = c.expect(['EXITCODE:0', 'EXITCODE:\d+'], timeout=20) - if i==0: + if i == 0: log.info('Smoketest finished successfully!') pass - if i==1: + elif i == 1: log.error('Smoketest failed :/') raise Exception("Smoketest-failed, please look into debug output") - #log.info("Smoke test status") - #data = c.before.decode() - # else, run configtest suite else: log.info("Executing load config tests") c.sendline('/usr/bin/vyos-configtest') - i = c.expect(['\n +Invalid command:', - 'No such file or directory', - r'\n\S+@\S+[$#]'], timeout=3600) + i = c.expect(['\n +Invalid command:', 'No such file or directory', + r'\n\S+@\S+[$#]'], timeout=3600) if i==0: raise Exception('Invalid command detected') elif i==1: - log.error("Did not find VyOS configtest, this should be an exception") - raise Exception("WTF? did not find VyOS configtest, this should be an exception") + tmp = '(W)hy (T)he (F)ace? VyOS smoketest not found!' + log.error(tmp) + raise Exception(tmp) c.sendline('echo EXITCODE:$\x16?') i = c.expect(['EXITCODE:0', 'EXITCODE:\d+'], timeout=10) - if i==0: + if i == 0: log.info('Configtest finished successfully!') pass - if i==1: - log.error('Configtest failed :/') - raise Exception("Configtest failed, please look into debug output") + elif i == 1: + tmp = 'Configtest failed :/ - check debug output' + log.error(tmp) + raise Exception(tmp) ################################################# # Powering off system @@ -382,31 +379,32 @@ try: c.sendline('poweroff') c.expect(r'\nAre you sure you want to poweroff this system.*\]') c.sendline('Y') - log.info("Shutting down virtual machine") + log.info('Shutting down virtual machine') for i in range(30): - log.info("Waiting for shutdown...") + log.info('Waiting for shutdown...') if not c.isalive(): - log.info("VM is shut down!") + log.info('VM is shut down!') break time.sleep(10) else: - log.error("VM Did not shut down after 300sec") - raise Exception("VM Did not shut down after 300sec") + tmp = 'VM Did not shut down after 300sec' + log.error(tmp) + raise Exception(tmp) c.close() except pexpect.exceptions.TIMEOUT: - log.error("Timeout waiting for VyOS system") + log.error('Timeout waiting for VyOS system') log.error(traceback.format_exc()) EXCEPTION = 1 except pexpect.exceptions.ExceptionPexpect: - log.error("Exeption while executing QEMU") - log.error("Is qemu working on this system?") + log.error('Exeption while executing QEMU') + log.error('Is qemu working on this system?') log.error(traceback.format_exc()) EXCEPTION = 1 except Exception: - log.error("An unknown error occured when installing the VyOS system") + log.error('Unknown error occured while VyOS!') traceback.print_exc() EXCEPTION = 1 @@ -416,15 +414,15 @@ except Exception: log.info("Cleaning up") if not args.keep: - log.info("Removing disk file: {}".format(args.disk)) + log.info(f'Removing disk file: {args.disk}') try: os.remove(args.disk) except Exception: - log.error("Exception while removing diskimage") + log.error('Exception while removing diskimage!') log.error(traceback.format_exc()) EXCEPTION = 1 if EXCEPTION: - log.error("Hmm... System got an exception while processing") - log.error("The ISO is not considered usable") + log.error('Hmm... system got an exception while processing.') + log.error('The ISO image is not considered usable!') sys.exit(1) |