Update the Azure Cloud Provider tests to be more acurate and use newer azure SDK version

This commit is contained in:
rallytime 2015-06-25 15:14:21 -06:00
parent 7c66611fe2
commit b68e3c0d0c
2 changed files with 48 additions and 29 deletions

View file

@ -8,6 +8,7 @@ from __future__ import absolute_import
import os
import random
import string
from distutils.version import LooseVersion
# Import Salt Testing Libs
from salttesting import skipIf
@ -16,18 +17,17 @@ from salttesting.helpers import ensure_in_syspath, expensiveTest
ensure_in_syspath('../../../')
# Import Salt Libs
import integration # pylint: disable=import-error
import integration
from salt.config import cloud_providers_config
# Import Third-Party Libs
# pylint: disable=import-error
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
from salt.ext.six.moves import range
try:
import azure # pylint: disable=unused-import
HAS_AZURE = True
except ImportError:
HAS_AZURE = False
# pylint: enable=import-error
def __random_name(size=6):
@ -41,9 +41,23 @@ def __random_name(size=6):
# Create the cloud instance name to be used throughout the tests
INSTANCE_NAME = __random_name()
PROVIDER_NAME = 'azure'
REQUIRED_AZURE = '0.11.1'
@skipIf(HAS_AZURE is False, 'These tests require azure to be installed.')
def __has_required_azure():
'''
Returns True/False if the required version of the Azure SDK is installed.
'''
version = LooseVersion(azure.__version__)
if HAS_AZURE is True and REQUIRED_AZURE <= version:
return True
else:
return False
@skipIf(HAS_AZURE is False, 'These tests require the Azure Python SDK to be installed.')
@skipIf(__has_required_azure() is False, 'The Azure Python SDK must be >= 0.11.1.')
class AzureTest(integration.ShellCase):
'''
Integration tests for the Azure cloud provider in Salt-Cloud
@ -57,21 +71,20 @@ class AzureTest(integration.ShellCase):
super(AzureTest, self).setUp()
# check if appropriate cloud provider and profile files are present
profile_str = 'azure-config:'
provider = 'azure'
profile_str = 'azure-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 subscription_id and certificate_path are present in provider file
provider_path = os.path.join(integration.FILES,
'conf',
'cloud.providers.d',
provider + '.conf')
PROVIDER_NAME + '.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']
@ -80,27 +93,30 @@ class AzureTest(integration.ShellCase):
'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['azure-test'][profile_str]['ssh_username']
ssh_pass = profile_config['azure-test'][profile_str]['ssh_password']
media_link = profile_config['azure-test'][profile_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
)
)
@ -108,22 +124,22 @@ 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 azure-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))
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

@ -2,3 +2,6 @@ azure-config:
provider: azure
subscription_id: ''
certificate_path: ''
cleanup_disks: True
cleanup_vhds: True
cleanup_services: True