Fixed failing Ec2 Tests

This commit is contained in:
Tyler Johnson 2019-08-12 12:15:16 -06:00
parent e2f085ca59
commit 60f8351864
No known key found for this signature in database
GPG key ID: 691E31397E27D004
2 changed files with 18 additions and 8 deletions

View file

@ -5,6 +5,7 @@
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
from time import sleep
import os
import yaml
@ -145,6 +146,8 @@ class EC2Test(CloudTest):
# check if instance returned with salt installed
self.assertInstanceExists(ret_val)
# Let the instance exist for a bit before destroying it, otherwise the test will fail
sleep(30)
self._destroy_instance()
@ -158,7 +161,7 @@ class EC2Test(CloudTest):
ret_val = self.run_cloud('-p ec2-test {0} --no-deploy'.format(changed_name), timeout=TIMEOUT)
# check if instance returned
self.assertInstanceExists(ret_val)
self.assertInstanceExists(ret_val, changed_name)
change_name = self.run_cloud('-a rename {0} newname={1} --assume-yes'.format(changed_name, self.instance_name),
timeout=TIMEOUT)

View file

@ -12,9 +12,10 @@ from time import sleep
from tests.support.case import ShellCase
from tests.support.helpers import generate_random_name
log = logging.getLogger(__name__)
TIMEOUT = 500
log = logging.getLogger(__name__)
class CloudTest(ShellCase):
@property
@ -24,20 +25,26 @@ class CloudTest(ShellCase):
self._instance_name = generate_random_name('cloud-test-').lower()
return self._instance_name
def _instance_exists(self):
def _instance_exists(self, instance_name=None):
# salt-cloud -a show_instance myinstance
if not instance_name:
instance_name = self.instance_name
query = self.run_cloud('--query')
log.debug('Checking for "{}" in => {}'.format(self.instance_name, query))
return any(self.instance_name == q.strip(': ') for q in query)
log.debug('Checking for "{}" in => {}'.format(instance_name, query))
return any(instance_name == q.strip(': ') for q in query)
def assertInstanceExists(self, creation_ret=None):
def assertInstanceExists(self, creation_ret=None, instance_name=None):
'''
:param instance_name: Override the checked instance name, otherwise the class default will be used.
:param creation_ret: The return value from the run_cloud() function that created the instance
'''
if not instance_name:
instance_name = self.instance_name
if creation_ret:
self.assertIn(self.instance_name, [i.strip(': ') for i in creation_ret])
self.assertIn(instance_name, [i.strip(': ') for i in creation_ret])
self.assertNotIn('Failed to start', ''.join(creation_ret))
self.assertTrue(self._instance_exists(), 'Instance "{}" was not created successfully')
self.assertTrue(self._instance_exists(instance_name), 'Instance "{}" was not created successfully'
.format(instance_name))
def _destroy_instance(self):
log.debug('Deleting instance "{}"'.format(self.instance_name))