Separated assertInstanceDestroy and _destry_instance

This commit is contained in:
Tyler Johnson 2019-08-14 12:06:54 -06:00
parent 158a38c750
commit 686cab945e
No known key found for this signature in database
GPG Key ID: 691E31397E27D004
14 changed files with 30 additions and 65 deletions

View File

@ -106,4 +106,4 @@ class DigitalOceanTest(CloudTest):
ret_str = self.run_cloud('-p digitalocean-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -55,4 +55,4 @@ class DimensionDataTest(CloudTest):
ret_val = self.run_cloud('-p dimensiondata-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_val)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -110,7 +110,7 @@ class EC2Test(CloudTest):
self.assertInstanceExists(ret_val)
# Let the instance exist for a bit before destroying it, otherwise the test will fail
self._destroy_instance()
self.assertDestroyInstance()
def test_instance_rename(self):
'''
@ -133,7 +133,7 @@ class EC2Test(CloudTest):
for result in exp_results:
self.assertIn(result, check_rename[0])
self._destroy_instance()
self.assertDestroyInstance()
def test_instance(self):
'''

View File

@ -32,7 +32,7 @@ class GCETest(CloudTest):
# Let the instance exist for half a minute before destroying it
sleep(30)
self._destroy_instance()
self.assertDestroyInstance()
def test_instance_extra(self):
'''
@ -46,4 +46,4 @@ class GCETest(CloudTest):
# Let the instance exist for half a minute before destroying it
sleep(30)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -29,4 +29,4 @@ class GoGridTest(CloudTest):
ret_str = self.run_cloud('-p gogrid-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: Nicole Thomas <nicole@saltstack.com>
'''
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing Libs
from tests.support.unit import skipIf
# Create the cloud instance name to be used throughout the tests
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
PROVIDER_NAME = 'joyent'
@skipIf(True, 'Joyent is EOL as of November 9th, 2019. It will no longer be supported in salt-cloud')
class JoyentTest(CloudTest):
'''
Integration tests for the Joyent cloud provider in Salt-Cloud
'''
PROVIDER = 'joyent'
REQUIRED_PROVIDER_CONFIG_ITEMS = ('user', 'password', 'private_key', 'keyname')
def test_instance(self):
'''
Test creating and deleting instance on Joyent
'''
ret_str = self.run_cloud('-p joyent-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()

View File

@ -26,4 +26,4 @@ class LinodeTest(CloudTest):
ret_str = self.run_cloud('-p linode-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -61,4 +61,4 @@ class AzureTest(CloudTest):
ret_val = self.run_cloud('-p {0} {1}'.format(self.profile_str, self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_val)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -45,4 +45,4 @@ class OneAndOneTest(CloudTest):
ret_str = self.run_cloud('-p oneandone-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -186,4 +186,4 @@ class RackspaceTest(CloudTest):
ret_val = self.run_cloud('-p rackspace-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_val)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -140,4 +140,4 @@ class ProfitBricksTest(CloudTest):
ret_str = self.run_cloud('-p profitbricks-test {0}'.format(self.instance_name), timeout=TIMEOUT)
self.assertInstanceExists(ret_str)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -36,7 +36,7 @@ class VMWareTest(CloudTest):
self.assertIn(disk_datastore_str, ret_val,
msg='Hard Disk 2 did not use the Datastore {0} '.format(disk_datastore))
self._destroy_instance()
self.assertDestroyInstance()
def test_snapshot(self):
'''
@ -56,4 +56,4 @@ class VMWareTest(CloudTest):
self.assertIn(s_ret_str, six.text_type(create_snapshot))
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -101,4 +101,4 @@ class VultrTest(CloudTest):
# Vultr won't let us delete an instance less than 5 minutes old.
time.sleep(300)
self._destroy_instance()
self.assertDestroyInstance()

View File

@ -68,7 +68,10 @@ class CloudTest(ShellCase):
else:
log.warning('Instance "{}" may not have been deleted properly'.format(self.instance_name))
# By now it should all be over
return delete_str
def assertDestroyInstance(self):
delete_str = self._destroy_instance()
self.assertFalse(self._instance_exists(), 'Could not destroy "{}". Delete_str: `{}`'
.format(self.instance_name, delete_str))
log.debug('Instance "{}" no longer exists'.format(self.instance_name))
@ -77,7 +80,7 @@ class CloudTest(ShellCase):
def instance_name(self):
if not hasattr(self, '__instance_name'):
# Create the cloud instance name to be used throughout the tests
subclass = self.__class__.__bases__[0].__name__.strip('Test')
subclass = self.__class__.__name__.strip('Test')
# Use the first three letters of the subclass, fill with '-' if too short
self.__instance_name = generate_random_name('cloud-test-{:-<3}-'.format(subclass[:3])).lower()
return self.__instance_name
@ -156,22 +159,17 @@ class CloudTest(ShellCase):
one time in a test for each instance created. This is a failSafe and something went wrong
if the tearDown is where an instance is destroyed.
'''
instance_deleted = True
tries = 0
for tries in range(12):
# Make sure that the instance for sure gets deleted, but fail the test if it happens in the tearDown
instance_deleted_before_teardown = True
for _ in range(12):
if self._instance_exists():
instance_deleted = False
try:
self._destroy_instance()
log.debug('Instance "{}" destroyed after {} tries'.format(self.instance_name, tries))
except AssertionError as e:
log.error(e)
sleep(30)
else:
break
sleep(30)
instance_deleted_before_teardown = False
self._destroy_instance()
self.assertFalse(self._instance_exists(), 'Instance exists after multiple attempts to delete: {}'
.format(self.instance_name))
# Complain if the instance was destroyed in this tearDown.
# Destroying instances in the tearDown is a contingency, not the way things should work by default.
self.assertTrue(instance_deleted, 'The Instance "{}" was deleted during the tearDown, not the test. Tries: {}'
.format(self.instance_name, tries))
self.assertTrue(instance_deleted_before_teardown,
'The Instance "{}" was deleted during the tearDown, not the test.'.format(self.instance_name))