On bootstrap failure, also cleanup.

This commit is contained in:
Pedro Algarvio 2013-08-17 07:59:13 +01:00
parent 5b81160804
commit 49a6cfdc51

View file

@ -37,6 +37,25 @@ except ImportError:
def cleanup(clean, vm_name):
if not clean:
return
cmd = 'salt-cloud -d {0} -y'.format(vm_name)
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stream_stds=True
)
proc.poll_and_read_until_finish()
proc.communicate()
def run(platform, provider, commit, clean):
'''
RUN!
@ -60,6 +79,7 @@ def run(platform, provider, commit, clean):
if proc.returncode > 0:
print('Failed to bootstrap VM. Exit code: {0}'.format(proc.returncode))
sys.stdout.flush()
cleanup(clean, vm_name)
sys.exit(proc.returncode)
print('VM Bootstrapped. Exit code: {0}'.format(proc.returncode))
@ -105,21 +125,7 @@ def run(platform, provider, commit, clean):
# Anything else, raise the exception
raise
# Clean up the vm
if clean:
cmd = 'salt-cloud -d {0} -y'.format(vm_name)
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stream_stds=True
)
proc.poll_and_read_until_finish()
proc.communicate()
cleanup(clean, vm_name)
return retcode