Improve cleanup logic

- ensure .scullery_* files are removed more reliably
- always write new Vagrant SSH configuration, do not rely on the
  existing one being the latest

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-05-24 00:32:01 +02:00
parent 01162e78a3
commit 2cb6d95ec3
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -106,6 +106,8 @@ def _setenv(envmap, dump=False):
env[variable] = value env[variable] = value
if dump: if dump:
fh.write(f'{variable}={value}\n') fh.write(f'{variable}={value}\n')
elif variable in env:
del env[variable]
if dump: if dump:
fh.close() fh.close()
@ -161,7 +163,6 @@ def runapply(state, target):
log.info('\n{}\n'.format(str(sshout))) log.info('\n{}\n'.format(str(sshout)))
def runtests(payload, hosts): def runtests(payload, hosts):
if not os.path.isfile(sshfile):
vagrant_sshconfig(sshfile) vagrant_sshconfig(sshfile)
testresult = pytest.main(['--verbose', '--hosts={}'.format(','.join(hosts)), '--ssh-config={}'.format(sshfile), payload]) testresult = pytest.main(['--verbose', '--hosts={}'.format(','.join(hosts)), '--ssh-config={}'.format(sshfile), payload])
log.debug('Test result is {}'.format(str(testresult.value))) log.debug('Test result is {}'.format(str(testresult.value)))
@ -172,6 +173,13 @@ def runtests(payload, hosts):
return False return False
return True return True
def _cleanup():
for file in [envfile, sshfile]:
if os.path.isfile(file):
log.debug('Removing {}'.format(file))
os.remove(file)
def main_interactive(): def main_interactive():
configmap = _config() configmap = _config()
boxes = configmap['boxes'] boxes = configmap['boxes']
@ -208,10 +216,6 @@ def main_interactive():
if True in [args.stop, args.force_stop]: if True in [args.stop, args.force_stop]:
log.info('Destroying machines ...') log.info('Destroying machines ...')
v.destroy() v.destroy()
for file in [envfile, sshfile]:
if os.path.isfile(file):
log.debug('Removing {}'.format(file))
os.remove(file)
if vagrant_isup(suite)[0] is False: if vagrant_isup(suite)[0] is False:
log.debug('OK') log.debug('OK')
else: else:
@ -220,7 +224,9 @@ def main_interactive():
log.info('Deployment is already running') log.info('Deployment is already running')
elif args.refresh: elif args.refresh:
log.info('Deployment is running, initiating refresh ...') log.info('Deployment is running, initiating refresh ...')
_cleanup()
v.provision() v.provision()
vagrant_sshconfig(sshfile)
elif status[0] is False: elif status[0] is False:
if status[1] is True: if status[1] is True:
log.debug('Deployment is not running') log.debug('Deployment is not running')
@ -240,6 +246,9 @@ def main_interactive():
else: else:
_abort('Start failed') _abort('Start failed')
if args.stop:
_cleanup()
if args.test: if args.test:
test = suiteconf.get('test', None) test = suiteconf.get('test', None)
if test is None: if test is None: