Skip to content

Commit

Permalink
Merge pull request #200 from SUSE-Enceladus/ssh-exc
Browse files Browse the repository at this point in the history
Attempt to cleanup instance on ssh fail.
  • Loading branch information
smarlowucf authored May 30, 2019
2 parents afe3e28 + ef971a6 commit 2acbb91
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ipa/ipa_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,19 @@ def put_file(self, client, source_file):
else:
return file_name

def _cleanup_instance(self, status):
"""
Cleanup instance based on arguments.
If tests pass and cleanup flag is none, or
cleanup flag is true, terminate instance.
"""
if (status == 0 and self.cleanup is None) or self.cleanup:
self.logger.info(
'Terminating instance %s' % self.running_instance_id
)
self._terminate_instance()

def test_image(self):
"""
The entry point for testing an image.
Expand Down Expand Up @@ -640,10 +653,14 @@ def test_image(self):
client
)
except IpaSSHException as error:
self._cleanup_instance(1)

raise IpaCloudException(
'Unable to connect to instance: %s' % error
)
except Exception as error:
self._cleanup_instance(1)

raise IpaCloudException(
'An error occurred retrieving host key: %s' % error
)
Expand Down Expand Up @@ -762,14 +779,7 @@ def test_image(self):
if self.collect_vm_info:
self._collect_vm_info()

# If tests pass and cleanup flag is none, or
# cleanup flag is true, terminate instance.
if status == 0 and self.cleanup is None or self.cleanup:
self.logger.info(
'Terminating instance %s' % self.running_instance_id
)
self._terminate_instance()

self._cleanup_instance(status)
self._save_results()
self._update_history()

Expand Down

0 comments on commit 2acbb91

Please sign in to comment.