Update cloud tests to be more efficient and accurate

This commit is contained in:
rallytime 2015-08-25 09:49:32 -06:00
parent da8bca09aa
commit 9ae1539c62
6 changed files with 188 additions and 153 deletions

View file

@ -78,61 +78,59 @@ class DigitalOceanTest(integration.ShellCase):
'''
Tests the return of running the --list-images command for digital ocean
'''
image_name = '14.10 x64'
ret_str = ' {0}'.format(image_name)
list_images = self.run_cloud('--list-images {0}'.format(PROVIDER_NAME))
self.assertIn(ret_str, list_images)
image_list = self.run_cloud('--list-images {0}'.format(PROVIDER_NAME))
self.assertIn(
'14.04 x64',
[i.strip() for i in image_list]
)
def test_list_locations(self):
'''
Tests the return of running the --list-locations command for digital ocean
'''
location_name = 'San Francisco 1'
ret_str = ' {0}'.format(location_name)
list_locations = self.run_cloud('--list-locations {0}'.format(PROVIDER_NAME))
self.assertIn(ret_str, list_locations)
_list_locations = self.run_cloud('--list-locations {0}'.format(PROVIDER_NAME))
self.assertIn(
'San Francisco 1',
[i.strip() for i in _list_locations]
)
def test_list_sizes(self):
'''
Tests the return of running the --list-sizes command for digital ocean
'''
size_name = '16GB'
ret_str = ' {0}'.format(size_name)
list_sizes = self.run_cloud('--list-sizes {0}'.format(PROVIDER_NAME))
self.assertIn(ret_str, list_sizes)
_list_sizes = self.run_cloud('--list-sizes {0}'.format(PROVIDER_NAME))
self.assertIn(
'16gb',
[i.strip() for i in _list_sizes]
)
def test_instance(self):
'''
Test creating an instance on DigitalOcean
'''
# create the instance
instance = self.run_cloud('-p digitalocean-test {0}'.format(INSTANCE_NAME))
ret_str = ' {0}'.format(INSTANCE_NAME)
# check if instance with salt installed returned
try:
self.assertIn(ret_str, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p digitalocean-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
ret_str = ' OK'
try:
self.assertIn(ret_str, delete)
self.assertIn(
'True',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
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.
query = self.run_cloud('--query')
ret_str = ' {0}:'.format(INSTANCE_NAME)
# if test instance is still present, delete it
if ret_str in query:
if INSTANCE_NAME in [i.strip() for i in self.run_cloud('--query')]:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))

View file

@ -29,6 +29,7 @@ def __random_name(size=6):
# Create the cloud instance name to be used throughout the tests
INSTANCE_NAME = __random_name()
PROVIDER_NAME = 'ec2'
class EC2Test(integration.ShellCase):
@ -44,31 +45,33 @@ class EC2Test(integration.ShellCase):
super(EC2Test, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'ec2-config:'
provider = 'ec2'
profile_str = 'ec2-config'
providers = self.run_cloud('--list-providers')
if profile_str not in providers:
if profile_str + ':' not in providers:
self.skipTest(
'Configuration file for {0} was not found. Check {0}.conf files '
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
.format(provider)
.format(PROVIDER_NAME)
)
# check if id, key, keyname, securitygroup, private_key, location,
# and provider are present
path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
config = cloud_providers_config(path)
config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
id = config['ec2-config']['ec2']['id']
key = config['ec2-config']['ec2']['key']
keyname = config['ec2-config']['ec2']['keyname']
sec_group = config['ec2-config']['ec2']['securitygroup']
private_key = config['ec2-config']['ec2']['private_key']
location = config['ec2-config']['ec2']['location']
id = config[profile_str][PROVIDER_NAME]['id']
key = config[profile_str][PROVIDER_NAME]['key']
keyname = config[profile_str][PROVIDER_NAME]['keyname']
sec_group = config[profile_str][PROVIDER_NAME]['securitygroup']
private_key = config[profile_str][PROVIDER_NAME]['private_key']
location = config[profile_str][PROVIDER_NAME]['location']
conf_items = [id, key, keyname, sec_group, private_key, location]
missing_conf_item = []
@ -82,32 +85,29 @@ class EC2Test(integration.ShellCase):
'An id, key, keyname, security group, private key, and location must '
'be provided to run these tests. One or more of these elements is '
'missing. Check tests/integration/files/conf/cloud.providers.d/{0}.conf'
.format(provider)
.format(PROVIDER_NAME)
)
def test_instance(self):
'''
Tests creating and deleting an instance on EC2 (classic)
'''
# create the instance
instance = self.run_cloud('-p ec2-test {0}'.format(INSTANCE_NAME))
ret_str = '{0}:'.format(INSTANCE_NAME)
# check if instance returned with salt installed
# check if instance with salt installed returned
try:
self.assertIn(ret_str, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p ec2-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
ret_str = ' shutting-down'
# check if deletion was performed appropriately
try:
self.assertIn(ret_str, delete)
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
except AssertionError:
raise

View file

@ -5,6 +5,8 @@
# Import Python Libs
import os
import random
import string
# Import Salt Testing Libs
from salttesting import skipIf
@ -17,6 +19,20 @@ import integration
from salt.config import cloud_providers_config
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()
PROVIDER_NAME = 'gogrid'
@skipIf(True, 'waiting on bug report fixes from #13365')
class GoGridTest(integration.ShellCase):
'''
@ -31,53 +47,53 @@ class GoGridTest(integration.ShellCase):
super(GoGridTest, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'gogrid-config:'
provider = 'gogrid'
profile_str = 'gogrid-config'
providers = self.run_cloud('--list-providers')
if profile_str not in providers:
if profile_str + ':' not in providers:
self.skipTest(
'Configuration file for {0} was not found. Check {0}.conf files '
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
.format(provider)
.format(PROVIDER_NAME)
)
# check if client_key and api_key are present
path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
config = cloud_providers_config(path)
api = config['gogrid-config']['gogrid']['apikey']
shared_secret = config['gogrid-config']['gogrid']['sharedsecret']
config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
api = config[profile_str][PROVIDER_NAME]['apikey']
shared_secret = config[profile_str][PROVIDER_NAME]['sharedsecret']
if api == '' or shared_secret == '':
self.skipTest(
'An api key and shared secret must be provided to run these tests. '
'Check tests/integration/files/conf/cloud.providers.d/{0}.conf'
.format(provider)
.format(PROVIDER_NAME)
)
def test_instance(self):
'''
Test creating an instance on GoGrid
'''
name = 'gogrid-testing'
# create the instance
instance = self.run_cloud('-p gogrid-test {0}'.format(name))
ret_str = ' {0}'.format(name)
# check if instance with salt installed returned
try:
self.assertIn(ret_str, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p gogrid-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(name))
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(name))
ret_str = ' True'
try:
self.assertIn(ret_str, delete)
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
except AssertionError:
raise
@ -85,13 +101,12 @@ class GoGridTest(integration.ShellCase):
'''
Clean up after tests
'''
name = 'gogrid-testing'
query = self.run_cloud('--query')
ret_str = ' {0}:'.format(name)
ret_str = ' {0}:'.format(INSTANCE_NAME)
# if test instance is still present, delete it
if ret_str in query:
self.run_cloud('-d {0} --assume-yes'.format(name))
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
if __name__ == '__main__':

View file

@ -37,6 +37,7 @@ def __random_name(size=6):
# Create the cloud instance name to be used throughout the tests
INSTANCE_NAME = __random_name()
PROVIDER_NAME = 'linode'
@skipIf(HAS_LIBCLOUD is False, 'salt-cloud requires >= libcloud 0.13.2')
@ -53,29 +54,31 @@ class LinodeTest(integration.ShellCase):
super(LinodeTest, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'linode-config:'
provider = 'linode'
profile_str = 'linode-config'
providers = self.run_cloud('--list-providers')
if profile_str not in providers:
if profile_str + ':' not in providers:
self.skipTest(
'Configuration file for {0} was not found. Check {0}.conf files '
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
.format(provider)
.format(PROVIDER_NAME)
)
# check if apikey and password are present
path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
config = cloud_providers_config(path)
api = config['linode-config']['linode']['apikey']
password = config['linode-config']['linode']['password']
config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
api = config[profile_str][PROVIDER_NAME]['apikey']
password = config[profile_str][PROVIDER_NAME]['password']
if api == '' or password == '':
self.skipTest(
'An api key and password must be provided to run these tests. Check '
'tests/integration/files/conf/cloud.providers.d/{0}.conf'.format(
provider
PROVIDER_NAME
)
)
@ -83,22 +86,22 @@ class LinodeTest(integration.ShellCase):
'''
Test creating an instance on Linode
'''
# create the instance
instance = self.run_cloud('-p linode-test {0}'.format(INSTANCE_NAME))
ret_str = ' {0}'.format(INSTANCE_NAME)
# check if instance with salt installed returned
try:
self.assertIn(ret_str, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p linode-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
ret_str = ' True'
try:
self.assertIn(ret_str, delete)
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
except AssertionError:
raise

View file

@ -37,6 +37,8 @@ def __random_name(size=6):
# Create the cloud instance name to be used throughout the tests
INSTANCE_NAME = __random_name()
PROVIDER_NAME = 'azure'
PROFILE_NAME = 'azure-test'
@skipIf(HAS_AZURE is False, 'These tests require azure to be installed.')
@ -53,50 +55,55 @@ class AzureTest(integration.ShellCase):
super(AzureTest, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'azure-config:'
provider = 'azure'
provider_str = 'azure-config'
providers = self.run_cloud('--list-providers')
if profile_str not in providers:
if provider_str + ':' not in providers:
self.skipTest(
'Configuration file for {0} was not found. Check {0}.conf files '
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
.format(provider)
.format(PROVIDER_NAME)
)
# check if subscription_id and certificate_path are present in provider file
provider_path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
provider_config = cloud_providers_config(provider_path)
sub_id = provider_config['azure-config']['azure']['subscription_id']
cert_path = provider_config['azure-config']['azure']['certificate_path']
provider_config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
sub_id = provider_config[provider_str][PROVIDER_NAME]['subscription_id']
cert_path = provider_config[provider_str][PROVIDER_NAME]['certificate_path']
if sub_id == '' or cert_path == '':
self.skipTest(
'A subscription_id and certificate_path must be provided to run '
'these tests. Check '
'tests/integration/files/conf/cloud.providers.d/{0}.conf'.format(
provider
PROVIDER_NAME
)
)
# check if ssh_username, ssh_password, and media_link are present
# in the azure configuration file
profile_path = os.path.join(integration.FILES,
'conf',
'cloud.profiles.d',
provider + '.conf')
profile_config = cloud_providers_config(profile_path)
ssh_user = profile_config['azure-test']['azure-config']['ssh_username']
ssh_pass = profile_config['azure-test']['azure-config']['ssh_password']
media_link = profile_config['azure-test']['azure-config']['media_link']
profile_config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.profiles.d',
PROVIDER_NAME + '.conf'
)
)
ssh_user = profile_config[PROFILE_NAME][provider_str]['ssh_username']
ssh_pass = profile_config[PROFILE_NAME][provider_str]['ssh_password']
media_link = profile_config[PROFILE_NAME][provider_str]['media_link']
if ssh_user == '' or ssh_pass == '' or media_link == '':
self.skipTest(
'An ssh_username, ssh_password, and media_link must be provided to run '
'these tests. One or more of these elements is missing. Check '
'tests/integration/files/conf/cloud.profiles.d/{0}.conf'.format(
provider
PROVIDER_NAME
)
)
@ -104,22 +111,31 @@ class AzureTest(integration.ShellCase):
'''
Test creating an instance on Azure
'''
# create the instance
instance = self.run_cloud('-p azure-test {0}'.format(INSTANCE_NAME))
ret_str = ' {0}'.format(INSTANCE_NAME)
# check if instance installed salt and returned correctly
# check if instance with salt installed returned
try:
self.assertIn(ret_str, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud(
'-p {0} {1}'.format(
PROFILE_NAME,
INSTANCE_NAME
)
)]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
not_deleted = 'No machines were found to be destroyed'
try:
self.assertNotEqual(not_deleted, delete)
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud(
'-d {0} --assume-yes'.format(
INSTANCE_NAME
)
)]
)
except AssertionError:
raise

View file

@ -37,6 +37,8 @@ def __random_name(size=6):
# Create the cloud instance name to be used throughout the tests
INSTANCE_NAME = __random_name()
PROVIDER_NAME = 'rackspace'
DRIVER = 'openstack'
@skipIf(HAS_LIBCLOUD is False, 'salt-cloud requires >= libcloud 0.13.2')
@ -53,53 +55,54 @@ class RackspaceTest(integration.ShellCase):
super(RackspaceTest, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'rackspace-config:'
provider = 'rackspace'
profile_str = 'rackspace-config'
providers = self.run_cloud('--list-providers')
if profile_str not in providers:
if profile_str + ':' not in providers:
self.skipTest(
'Configuration file for {0} was not found. Check {0}.conf files '
'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
.format(provider)
.format(PROVIDER_NAME)
)
# check if api key, user, and tenant are present
path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
config = cloud_providers_config(path)
user = config['rackspace-config']['openstack']['user']
tenant = config['rackspace-config']['openstack']['tenant']
api = config['rackspace-config']['openstack']['apikey']
config = cloud_providers_config(
os.path.join(
integration.FILES,
'conf',
'cloud.providers.d',
PROVIDER_NAME + '.conf'
)
)
user = config[profile_str][DRIVER]['user']
tenant = config[profile_str][DRIVER]['tenant']
api = config[profile_str][DRIVER]['apikey']
if api == '' or tenant == '' or user == '':
self.skipTest(
'A user, tenant, and an api key must be provided to run these '
'tests. Check tests/integration/files/conf/cloud.providers.d/{0}.conf'
.format(provider)
.format(PROVIDER_NAME)
)
def test_instance(self):
'''
Test creating an instance on rackspace with the openstack driver
'''
# create the instance
instance = self.run_cloud('-p rackspace-test {0}'.format(INSTANCE_NAME))
ret = ' {0}'.format(INSTANCE_NAME)
# check if instance with salt installed returned successfully
# check if instance with salt installed returned
try:
self.assertIn(ret, instance)
self.assertIn(
INSTANCE_NAME,
[i.strip() for i in self.run_cloud('-p rackspace-test {0}'.format(INSTANCE_NAME))]
)
except AssertionError:
self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
raise
# delete the instance
delete = self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
ret = ' True'
try:
self.assertIn(ret, delete)
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))]
)
except AssertionError:
raise