diff --git a/tests/integration/cloud/helpers/cloud_test_base.py b/tests/integration/cloud/helpers/cloud_test_base.py index ab2785bc0d83..ce38faeee1be 100644 --- a/tests/integration/cloud/helpers/cloud_test_base.py +++ b/tests/integration/cloud/helpers/cloud_test_base.py @@ -6,7 +6,8 @@ # Import python libs from __future__ import absolute_import, print_function, unicode_literals import logging -from os import path +import os +import shutil from time import sleep # Import Salt Testing libs @@ -29,6 +30,14 @@ class CloudTest(ShellCase): __RE_RUN_DELAY = 15 __RE_TRIES = 3 + def clean_cloud_dir(self, tmp_dir): + ''' + Clean the cloud.providers.d tmp directory + ''' + # make sure old provider configs are deleted + for i in os.listdir(tmp_dir): + os.remove(os.path.join(tmp_dir, i)) + def query_instances(self): ''' Standardize the data returned from a salt-cloud --query @@ -134,9 +143,8 @@ def providers(self): def provider_config(self): if not hasattr(self, '_provider_config'): self._provider_config = cloud_providers_config( - path.join( - FILES, - 'conf', + os.path.join( + self.config_dir, 'cloud.providers.d', self.PROVIDER + '.conf' ) @@ -147,9 +155,8 @@ def provider_config(self): def config(self): if not hasattr(self, '_config'): self._config = cloud_config( - path.join( - FILES, - 'conf', + os.path.join( + self.config_dir, 'cloud.profiles.d', self.PROVIDER + '.conf' ) @@ -170,6 +177,15 @@ def setUp(self): if not self.PROVIDER: self.fail('A PROVIDER must be defined for this test') + # clean up before setup + self.tmp_cloud_provider = os.path.join(self.config_dir, 'cloud.providers.d') + self.clean_cloud_dir(self.tmp_cloud_provider) + + # add the provider config for only the cloud we are testing + provider_file = self.PROVIDER + '.conf' + shutil.copyfile(os.path.join(os.path.join(FILES, 'conf', 'cloud.providers.d'), provider_file), + os.path.join(self.tmp_cloud_provider, provider_file)) + # check if appropriate cloud provider and profile files are present if self.profile_str + ':' not in self.providers: self.skipTest( @@ -196,13 +212,21 @@ def tearDown(self): if the tearDown is where an instance is destroyed. ''' # Make sure that the instance for sure gets deleted, but fail the test if it happens in the tearDown - if self._instance_exists(): - for _ in range(12): - sleep(30) - success, result_str = self._destroy_instance() - if success: - self.fail('The instance "{}" was deleted during the tearDown, not the test.'.format( - self.instance_name)) - - # Destroying instances in the tearDown is a contingency, not the way things should work by default. - self.fail('The Instance "{}" was not deleted after multiple attempts'.format(self.instance_name)) + try: + destroyed = False + if self._instance_exists(): + for _ in range(3): + sleep(30) + success, result_str = self._destroy_instance() + if success: + self.fail('The instance "{}" was deleted during the tearDown, not the test.'.format( + self.instance_name)) + if not self._instance_exists(): + destroyed = True + break + + if not destroyed: + # Destroying instances in the tearDown is a contingency, not the way things should work by default. + self.fail('The Instance "{}" was not deleted after multiple attempts'.format(self.instance_name)) + finally: + self.clean_cloud_dir(self.tmp_cloud_provider)