mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Further refactored cloud test code
This commit is contained in:
parent
b03cc4826f
commit
fd13ce1db4
15 changed files with 81 additions and 180 deletions
|
@ -11,9 +11,9 @@ import os
|
|||
from Crypto.PublicKey import RSA
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.helpers import expensiveTest, generate_random_name
|
||||
from tests.support.helpers import expensiveTest
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.config import cloud_providers_config
|
||||
|
@ -22,11 +22,10 @@ import salt.utils.stringutils
|
|||
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
INSTANCE_NAME = generate_random_name('CLOUD-TEST-')
|
||||
PROVIDER_NAME = 'digitalocean'
|
||||
|
||||
|
||||
class DigitalOceanTest(ShellCase):
|
||||
class DigitalOceanTest(CloudTest):
|
||||
'''
|
||||
Integration tests for the DigitalOcean cloud provider in Salt-Cloud
|
||||
'''
|
||||
|
@ -70,6 +69,9 @@ class DigitalOceanTest(ShellCase):
|
|||
.format(PROVIDER_NAME)
|
||||
)
|
||||
|
||||
self.assertEqual(self._instance_exists(), False,
|
||||
'The instance "{}" exists before it was created by the test'.format(self.INSTANCE_NAME))
|
||||
|
||||
def test_list_images(self):
|
||||
'''
|
||||
Tests the return of running the --list-images command for digitalocean
|
||||
|
@ -104,7 +106,7 @@ class DigitalOceanTest(ShellCase):
|
|||
'''
|
||||
Test key management
|
||||
'''
|
||||
do_key_name = INSTANCE_NAME + '-key'
|
||||
do_key_name = self.INSTANCE_NAME + '-key'
|
||||
|
||||
# generate key and fingerprint
|
||||
ssh_key = RSA.generate(4096)
|
||||
|
@ -149,26 +151,9 @@ class DigitalOceanTest(ShellCase):
|
|||
Test creating an instance on DigitalOcean
|
||||
'''
|
||||
# check if instance with salt installed returned
|
||||
try:
|
||||
self.assertIn(
|
||||
INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p digitalocean-test {0}'.format(INSTANCE_NAME), timeout=500)]
|
||||
)
|
||||
except AssertionError:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
||||
raise
|
||||
|
||||
# delete the instance
|
||||
try:
|
||||
self.assertIn(
|
||||
'True',
|
||||
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)]
|
||||
)
|
||||
except AssertionError:
|
||||
raise
|
||||
|
||||
# Final clean-up of created instance, in case something went wrong.
|
||||
# This was originally in a tearDown function, but that didn't make sense
|
||||
# To run this for each test when not all tests create instances.
|
||||
if INSTANCE_NAME in [i.strip() for i in self.run_cloud('--query')]:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p digitalocean-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -6,35 +6,21 @@ Integration tests for the Dimension Data cloud provider
|
|||
# Import Python Libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.helpers import expensiveTest
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.config import cloud_providers_config
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
|
||||
def _random_name(size=6):
|
||||
'''
|
||||
Generates a random cloud instance name
|
||||
'''
|
||||
return 'cloud-test-' + ''.join(
|
||||
random.choice(string.ascii_lowercase + string.digits)
|
||||
for x in range(size)
|
||||
)
|
||||
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
INSTANCE_NAME = _random_name()
|
||||
PROVIDER_NAME = 'dimensiondata'
|
||||
|
||||
|
||||
class DimensionDataTest(ShellCase):
|
||||
class DimensionDataTest(CloudTest):
|
||||
'''
|
||||
Integration tests for the Dimension Data cloud provider in Salt-Cloud
|
||||
'''
|
||||
|
@ -78,6 +64,9 @@ class DimensionDataTest(ShellCase):
|
|||
.format(PROVIDER_NAME)
|
||||
)
|
||||
|
||||
self.assertEqual(self._instance_exists(), False,
|
||||
'The instance "{}" exists before it was created by the test'.format(self.INSTANCE_NAME))
|
||||
|
||||
def test_list_images(self):
|
||||
'''
|
||||
Tests the return of running the --list-images command for the dimensiondata cloud provider
|
||||
|
@ -113,26 +102,10 @@ class DimensionDataTest(ShellCase):
|
|||
Test creating an instance on Dimension Data's cloud
|
||||
'''
|
||||
# check if instance with salt installed returned
|
||||
try:
|
||||
self.assertIn(
|
||||
INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p dimensiondata-test {0}'.format(INSTANCE_NAME), timeout=500)]
|
||||
)
|
||||
except AssertionError:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
||||
raise
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p dimensiondata-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
|
||||
# delete the instance
|
||||
try:
|
||||
self.assertIn(
|
||||
'True',
|
||||
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)]
|
||||
)
|
||||
except AssertionError:
|
||||
raise
|
||||
self._destroy_instance()
|
||||
|
||||
# Final clean-up of created instance, in case something went wrong.
|
||||
# This was originally in a tearDown function, but that didn't make sense
|
||||
# To run this for each test when not all tests create instances.
|
||||
if INSTANCE_NAME in [i.strip() for i in self.run_cloud('--query')]:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
||||
|
|
|
@ -20,7 +20,7 @@ from tests.support.unit import skipIf
|
|||
from tests.support import win_installer
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
from tests.integration.cloud.cloud_test_helpers import CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest
|
||||
|
||||
PROVIDER_NAME = 'ec2'
|
||||
HAS_WINRM = salt.utils.cloud.HAS_WINRM and salt.utils.cloud.HAS_SMB
|
||||
|
@ -148,6 +148,8 @@ class EC2Test(CloudTest):
|
|||
self.assertIn(ret_str, instance)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
self._destroy_instance()
|
||||
|
||||
def test_instance_rename(self):
|
||||
'''
|
||||
Tests creating and renaming an instance on EC2 (classic)
|
||||
|
@ -170,6 +172,8 @@ class EC2Test(CloudTest):
|
|||
for result in exp_results:
|
||||
self.assertIn(result, check_rename[0])
|
||||
|
||||
self._destroy_instance()
|
||||
|
||||
def test_instance(self):
|
||||
'''
|
||||
Tests creating and deleting an instance on EC2 (classic)
|
||||
|
@ -246,6 +250,3 @@ class EC2Test(CloudTest):
|
|||
|
||||
)
|
||||
self._test_instance('ec2-win2016-test', debug=True)
|
||||
|
||||
def tearDown(self):
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -12,7 +12,7 @@ import os
|
|||
from salt.config import cloud_providers_config
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.integration.cloud.cloud_test_helpers import TIMEOUT, CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.helpers import expensiveTest
|
||||
|
||||
|
@ -81,6 +81,7 @@ class GCETest(CloudTest):
|
|||
# check if instance returned with salt installed
|
||||
self.assertIn(ret_str, instance)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
||||
def test_instance_extra(self):
|
||||
'''
|
||||
|
@ -96,3 +97,4 @@ class GCETest(CloudTest):
|
|||
# check if instance returned with salt installed
|
||||
self.assertIn(ret_str, instance)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -16,7 +16,7 @@ from tests.support.unit import skipIf
|
|||
from salt.config import cloud_providers_config
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
from tests.integration.cloud.cloud_test_helpers import CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
|
||||
PROVIDER_NAME = 'gogrid'
|
||||
|
||||
|
@ -74,9 +74,7 @@ class GoGridTest(CloudTest):
|
|||
# check if instance with salt installed returned
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p gogrid-test {0}'.format(self.INSTANCE_NAME), timeout=500)]
|
||||
[i.strip() for i in self.run_cloud('-p gogrid-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
def tearDown(self):
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -15,7 +15,7 @@ from tests.support.helpers import expensiveTest
|
|||
from salt.config import cloud_providers_config
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
from tests.integration.cloud.cloud_test_helpers import CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
|
||||
PROVIDER_NAME = 'joyent'
|
||||
|
||||
|
@ -74,9 +74,7 @@ class JoyentTest(CloudTest):
|
|||
'''
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p joyent-test {0}'.format(self.INSTANCE_NAME), timeout=500)]
|
||||
[i.strip() for i in self.run_cloud('-p joyent-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
def tearDown(self):
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -15,7 +15,7 @@ from tests.support.helpers import expensiveTest
|
|||
from salt.config import cloud_providers_config
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
from tests.integration.cloud.cloud_test_helpers import CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
|
||||
PROVIDER_NAME = 'linode'
|
||||
|
||||
|
@ -72,6 +72,7 @@ class LinodeTest(CloudTest):
|
|||
# check if instance with salt installed returned
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud('-p linode-test {0}'.format(self.INSTANCE_NAME), timeout=500)]
|
||||
[i.strip() for i in self.run_cloud('-p linode-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -9,7 +9,7 @@ import os
|
|||
import logging
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.integration.cloud.cloud_test_helpers import TIMEOUT, CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.unit import skipIf
|
||||
from tests.support.helpers import expensiveTest
|
||||
|
@ -113,10 +113,6 @@ class AzureTest(CloudTest):
|
|||
self.assertEqual(self._instance_exists(), False,
|
||||
'The instance "{}" exists before it was created by the test'.format(self.INSTANCE_NAME))
|
||||
|
||||
def _instance_exists(self):
|
||||
# salt-cloud -a show_instance myinstance
|
||||
return ' {0}:'.format(self.INSTANCE_NAME) in self.run_cloud('--query')
|
||||
|
||||
def test_instance(self):
|
||||
'''
|
||||
Test creating an instance on Azure
|
||||
|
@ -131,6 +127,5 @@ class AzureTest(CloudTest):
|
|||
), timeout=TIMEOUT
|
||||
)]
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -8,7 +8,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
import os
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.unit import skipIf
|
||||
from tests.support.helpers import expensiveTest, generate_random_name
|
||||
|
@ -28,11 +28,10 @@ except ImportError:
|
|||
INSTANCE_NAME = generate_random_name('CLOUD-TEST-')
|
||||
PROVIDER_NAME = 'oneandone'
|
||||
DRIVER_NAME = 'oneandone'
|
||||
TIMEOUT = 500
|
||||
|
||||
|
||||
@skipIf(HAS_ONEANDONE is False, 'salt-cloud requires >= 1and1 1.2.0')
|
||||
class OneAndOneTest(ShellCase):
|
||||
class OneAndOneTest(CloudTest):
|
||||
'''
|
||||
Integration tests for the 1and1 cloud provider
|
||||
'''
|
||||
|
@ -76,9 +75,6 @@ class OneAndOneTest(ShellCase):
|
|||
self.assertEqual(self._instance_exists(), False,
|
||||
'The instance "{}" exists before it was created by the test'.format(INSTANCE_NAME))
|
||||
|
||||
def _instance_exists(self):
|
||||
return ' {0}:'.format(INSTANCE_NAME) in self.run_cloud('--query')
|
||||
|
||||
def test_list_images(self):
|
||||
'''
|
||||
Tests the return of running the --list-images command for 1and1
|
||||
|
@ -94,26 +90,12 @@ class OneAndOneTest(ShellCase):
|
|||
Test creating an instance on 1and1
|
||||
'''
|
||||
# check if instance with salt installed returned
|
||||
try:
|
||||
self.assertIn(
|
||||
INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud(
|
||||
'-p oneandone-test {0}'.format(INSTANCE_NAME), timeout=500
|
||||
)]
|
||||
)
|
||||
except AssertionError:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
|
||||
raise
|
||||
self.assertIn(
|
||||
INSTANCE_NAME,
|
||||
[i.strip() for i in self.run_cloud(
|
||||
'-p oneandone-test {0}'.format(INSTANCE_NAME), timeout=TIMEOUT
|
||||
)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
def tearDown(self):
|
||||
'''
|
||||
Clean up after tests
|
||||
'''
|
||||
if self._instance_exists():
|
||||
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=TIMEOUT)
|
||||
# example response: ['gce-config:', '----------', ' gce:', '----------', 'cloud-test-dq4e6c:', 'True', '']
|
||||
delete_str = ''.join(delete)
|
||||
|
||||
# check if deletion was performed appropriately
|
||||
self.assertIn(INSTANCE_NAME, delete_str)
|
||||
self.assertIn('True', delete_str)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -17,7 +17,7 @@ from tests.support.mixins import SaltReturnAssertsMixin
|
|||
|
||||
# Import Salt Libs
|
||||
from salt.config import cloud_providers_config
|
||||
from tests.integration.cloud.cloud_test_helpers import TIMEOUT, CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -233,5 +233,5 @@ class RackspaceTest(CloudTest):
|
|||
[i.strip() for i in self.run_cloud('-p rackspace-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT)]
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -16,7 +16,7 @@ from tests.support.helpers import expensiveTest
|
|||
from salt.config import cloud_providers_config
|
||||
|
||||
# Import Third-Party Libs
|
||||
from tests.integration.cloud.cloud_test_helpers import TIMEOUT, CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
|
||||
|
||||
try:
|
||||
# pylint: disable=unused-import
|
||||
|
@ -195,5 +195,6 @@ class ProfitBricksTest(CloudTest):
|
|||
timeout=TIMEOUT
|
||||
)]
|
||||
)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -16,7 +16,7 @@ from tests.support.paths import FILES
|
|||
from tests.support.helpers import expensiveTest
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
from tests.integration.cloud.cloud_test_helpers import TIMEOUT, CloudTest
|
||||
from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
|
||||
|
||||
PROVIDER_NAME = 'vmware'
|
||||
|
||||
|
@ -100,6 +100,8 @@ class VMWareTest(CloudTest):
|
|||
self.assertIn(disk_datastore_str, instance,
|
||||
msg='Hard Disk 2 did not use the Datastore {0} '.format(disk_datastore))
|
||||
|
||||
self._destroy_instance()
|
||||
|
||||
def test_snapshot(self):
|
||||
'''
|
||||
Tests creating snapshot and creating vm with --no-deploy
|
||||
|
@ -120,6 +122,6 @@ class VMWareTest(CloudTest):
|
|||
s_ret_str = 'Snapshot created successfully'
|
||||
|
||||
self.assertIn(s_ret_str, six.text_type(create_snapshot))
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
def tearDown(self):
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -9,9 +9,9 @@ import os
|
|||
import time
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
|
||||
from tests.support.paths import FILES
|
||||
from tests.support.helpers import expensiveTest, generate_random_name
|
||||
from tests.support.helpers import expensiveTest
|
||||
from tests.support.unit import skipIf
|
||||
|
||||
# Import Salt Libs
|
||||
|
@ -20,12 +20,10 @@ from salt.ext import six
|
|||
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
INSTANCE_NAME = generate_random_name('CLOUD-TEST-')
|
||||
PROVIDER_NAME = 'vultr'
|
||||
TIMEOUT = 500
|
||||
|
||||
|
||||
class VultrTest(ShellCase):
|
||||
class VultrTest(CloudTest):
|
||||
'''
|
||||
Integration tests for the Vultr cloud provider in Salt-Cloud
|
||||
'''
|
||||
|
@ -69,6 +67,9 @@ class VultrTest(ShellCase):
|
|||
.format(PROVIDER_NAME)
|
||||
)
|
||||
|
||||
self.assertEqual(self._instance_exists(), False,
|
||||
'The instance "{}" exists before it was created by the test'.format(self.INSTANCE_NAME))
|
||||
|
||||
def test_list_images(self):
|
||||
'''
|
||||
Tests the return of running the --list-images command for Vultr
|
||||
|
@ -146,36 +147,14 @@ class VultrTest(ShellCase):
|
|||
Test creating an instance on Vultr
|
||||
'''
|
||||
# check if instance with salt installed returned
|
||||
try:
|
||||
create_vm = self.run_cloud('-p vultr-test {0}'.format(INSTANCE_NAME), timeout=800)
|
||||
self.assertIn(
|
||||
INSTANCE_NAME,
|
||||
[i.strip() for i in create_vm]
|
||||
)
|
||||
self.assertNotIn('Failed to start', six.text_type(create_vm))
|
||||
except AssertionError:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=TIMEOUT)
|
||||
raise
|
||||
create_vm = self.run_cloud('-p vultr-test {0}'.format(self.INSTANCE_NAME), timeout=TIMEOUT + 300)
|
||||
self.assertIn(
|
||||
self.INSTANCE_NAME,
|
||||
[i.strip() for i in create_vm]
|
||||
)
|
||||
self.assertNotIn('Failed to start', six.text_type(create_vm))
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
# Vultr won't let us delete an instance less than 5 minutes old.
|
||||
time.sleep(420)
|
||||
# delete the instance
|
||||
results = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=TIMEOUT)
|
||||
try:
|
||||
self.assertIn(
|
||||
'True',
|
||||
[i.strip() for i in results]
|
||||
)
|
||||
except AssertionError:
|
||||
raise
|
||||
|
||||
# Final clean-up of created instance, in case something went wrong.
|
||||
# This was originally in a tearDown function, but that didn't make sense
|
||||
# To run this for each test when not all tests create instances.
|
||||
# Also, Vultr won't let instances be deleted unless they have been alive for 5 minutes.
|
||||
# If we exceed 6 minutes and the instance is still there, quit
|
||||
ct = 0
|
||||
while ct < 12 and INSTANCE_NAME in [i.strip() for i in self.run_cloud('--query')]:
|
||||
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=TIMEOUT)
|
||||
time.sleep(30)
|
||||
ct = ct + 1
|
||||
time.sleep(300)
|
||||
self._destroy_instance()
|
||||
|
|
|
@ -41,7 +41,7 @@ class CloudTest(ShellCase):
|
|||
|
||||
def tearDown(self):
|
||||
'''
|
||||
Clean up after tests, share this between all the cloud tests
|
||||
Clean up after tests, If the instance still exists for any reason, delete it
|
||||
'''
|
||||
if self._instance_exists():
|
||||
self._destroy_instance()
|
|
@ -6,34 +6,17 @@ Integration tests for functions located in the salt.cloud.__init__.py file.
|
|||
# Import Python Libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.integration.cloud.helpers.cloud_test_base import CloudTest
|
||||
from tests.support.helpers import expensiveTest
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
# Import Salt libs
|
||||
import salt.cloud
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
|
||||
def __random_name(size=6):
|
||||
'''
|
||||
Generates a random cloud instance name
|
||||
'''
|
||||
return 'CLOUD-TEST-' + ''.join(
|
||||
random.choice(string.ascii_uppercase + string.digits)
|
||||
for x in range(size)
|
||||
)
|
||||
|
||||
|
||||
# Create the cloud instance name to be used throughout the tests
|
||||
INSTANCE_NAME = __random_name()
|
||||
|
||||
|
||||
class CloudClientTestCase(ShellCase):
|
||||
class CloudClientTestCase(CloudTest):
|
||||
'''
|
||||
Integration tests for the CloudClient class. Uses DigitalOcean as a salt-cloud provider.
|
||||
'''
|
||||
|
@ -73,16 +56,17 @@ class CloudClientTestCase(ShellCase):
|
|||
# Create the VM using salt.cloud.CloudClient.create() instead of calling salt-cloud
|
||||
created = cloud_client.create(
|
||||
provider=self.provider_name,
|
||||
names=[INSTANCE_NAME],
|
||||
names=[self.INSTANCE_NAME],
|
||||
image=self.image_name,
|
||||
location='sfo1', size='512mb', vm_size='512mb'
|
||||
)
|
||||
|
||||
# Check that the VM was created correctly
|
||||
self.assertIn(INSTANCE_NAME, created)
|
||||
self.assertIn(self.INSTANCE_NAME, created)
|
||||
self.assertEqual(self._instance_exists(), True)
|
||||
|
||||
# Clean up after ourselves and delete the VM
|
||||
deleted = cloud_client.destroy(names=[INSTANCE_NAME])
|
||||
deleted = cloud_client.destroy(names=[self.INSTANCE_NAME])
|
||||
|
||||
# Check that the VM was deleted correctly
|
||||
self.assertIn(INSTANCE_NAME, deleted)
|
||||
self.assertIn(self.INSTANCE_NAME, deleted)
|
||||
|
|
Loading…
Add table
Reference in a new issue