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