diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2015-09-16 10:08:05 +0100 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2015-09-16 14:55:44 +0000 |
commit | 93cd6b6b319c1eec4a1f2f2af5e49055443762d4 (patch) | |
tree | 9b11404a6660687706702d993ba298e623945178 /openstack | |
parent | 24404f7ba84ab27929af4da9bc4a5c70b12bc35f (diff) | |
download | ciat-tester-93cd6b6b319c1eec4a1f2f2af5e49055443762d4.tar.gz |
Improve cleanup when IP address assignment fails.
Diffstat (limited to 'openstack')
-rwxr-xr-x | openstack/tester | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/openstack/tester b/openstack/tester index 8ba9764..8b6e361 100755 --- a/openstack/tester +++ b/openstack/tester @@ -39,6 +39,38 @@ class TimeoutError(cliapp.AppException): def __init__(self, msg): super(TimeoutError, self).__init__(msg) + +def delete_image(hostname): + # TODO: Do all this stuff properly with python novaclient + # Remove an image from the openstack tenancy + print "Deleting %s test disc image" % (hostname) + try: + cliapp.runcmd(['nova', 'image-delete', hostname]) + except cliapp.AppException as e: + # TODO: Stop assuming that image-delete failed because it was + # already removed + print "- Failed" + pass + +def delete_instance_and_image(hostname): + # TODO: Do all this stuff properly with python novaclient + # Stop and remove VM, and its image + print "Deleting %s test instance" % (hostname) + try: + cliapp.runcmd(['nova', 'delete', hostname]) + except cliapp.AppException as e: + # TODO: Stop assuming that delete failed because the instance + # wasn't running + print "- Failed" + pass + + # Sleep for a bit, or nova silently fails to delete the image + # TODO: Test whether the image has been deleted in a retry loop. + time.sleep(20) + + delete_image(hostname) + + class DeployedSystemInstance(object): def __init__(self, deployment, ip_addr, hostname): @@ -119,28 +151,7 @@ class DeployedSystemInstance(object): print "Test system %s ready to run tests." % (self.hostname) def delete(self): - # Stop and remove VM - print "Deleting %s test instance" % (self.hostname) - try: - cliapp.runcmd(['nova', 'delete', self.hostname]) - except cliapp.AppException as e: - # TODO: Stop assuming that delete failed because the instance - # wasn't running - print "- Failed" - pass - - # Sleep for a bit, or nova silently fails to delete the image - # TODO: Test whether the image has been deleted in a retry loop. - time.sleep(20) - - print "Deleting %s test disc image" % (self.hostname) - try: - cliapp.runcmd(['nova', 'image-delete', self.hostname]) - except cliapp.AppException as e: - # TODO: Stop assuming that image-delete failed because it was - # already removed - print "- Failed" - pass + delete_instance_and_image(self.hostname) class Deployment(object): @@ -211,6 +222,7 @@ class Deployment(object): ip_addr = free_ip.ip break else: + delete_instance_and_image(hostname) raise cliapp.AppException('Could not get a floating IP') # Print the IP address |