Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to cleanup instance on ssh fail. #200

Merged
merged 2 commits into from
May 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
smarlowucf marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -638,10 +651,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 @@ -761,14 +778,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