Skip to content

Commit 4e2083f

Browse files
author
Gabriel Monroy
committed
Merge pull request #347 from opdemand/346-vagrant-node-dir-err
Fixed #346 - made vagrant destroy_node() RuntimeError into a warning.
2 parents f6f3652 + 7bd348a commit 4e2083f

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

provider/vagrant.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,25 @@ def destroy_node(node):
131131
return
132132

133133
# Shut the VM down and destroy it
134-
_run_vagrant_command(node['provider_id'], args=['destroy', '--force'], creds=node['creds'])
135-
node_dir = HOST_NODES_DIR + '/' + node['provider_id']
136-
137-
# Sanity check before `rm -rf`
138-
if 'contrib/vagrant' not in node_dir:
139-
raise RuntimeError("Aborted node destruction: attempting to 'rm -rf' unexpected directory")
140-
141-
# Completely remove the folder that contained the VM
142-
rm_vagrantfile = 'rm ' + node_dir + '/Vagrantfile'
143-
rm_node_dir = 'rm -rf ' + node_dir
144-
_host_ssh(commands=[rm_vagrantfile, rm_node_dir], creds=node['creds'])
134+
try:
135+
_run_vagrant_command(node['provider_id'], args=['destroy', '--force'], creds=node['creds'])
136+
node_dir = HOST_NODES_DIR + '/' + node['provider_id']
137+
138+
# Sanity check before `rm -rf`
139+
if 'contrib/vagrant' not in node_dir:
140+
raise RuntimeError(
141+
"Aborted node destruction: attempting to 'rm -rf' unexpected directory")
142+
143+
# Completely remove the folder that contained the VM
144+
rm_vagrantfile = 'rm ' + node_dir + '/Vagrantfile'
145+
rm_node_dir = 'rm -rf ' + node_dir
146+
_host_ssh(commands=[rm_vagrantfile, rm_node_dir], creds=node['creds'])
147+
except RuntimeError as err:
148+
# If we couldn't cd to the node dir, just log that as a warning
149+
if 'No such file or directory' in str(err):
150+
logger.warn(err)
151+
else:
152+
raise
145153

146154

147155
def _run_vagrant_command(node_id, args=[], creds={}):

0 commit comments

Comments
 (0)