mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
On bootstrap failure, also cleanup.
This commit is contained in:
parent
5b81160804
commit
49a6cfdc51
1 changed files with 21 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue