test_msazure.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import logging
  8. # Import Salt Testing Libs
  9. from tests.integration.cloud.helpers.cloud_test_base import CloudTest
  10. from tests.support.unit import skipIf
  11. # Import Salt Libs
  12. from salt.utils.versions import LooseVersion
  13. try:
  14. import azure # pylint: disable=unused-import
  15. HAS_AZURE = True
  16. except ImportError:
  17. HAS_AZURE = False
  18. if HAS_AZURE and not hasattr(azure, '__version__'):
  19. import azure.common
  20. log = logging.getLogger(__name__)
  21. TIMEOUT = 1000
  22. REQUIRED_AZURE = '1.1.0'
  23. def __has_required_azure():
  24. '''
  25. Returns True/False if the required version of the Azure SDK is installed.
  26. '''
  27. if HAS_AZURE:
  28. if hasattr(azure, '__version__'):
  29. version = LooseVersion(azure.__version__)
  30. else:
  31. version = LooseVersion(azure.common.__version__)
  32. if LooseVersion(REQUIRED_AZURE) <= version:
  33. return True
  34. return False
  35. @skipIf(not HAS_AZURE, 'These tests require the Azure Python SDK to be installed.')
  36. @skipIf(not __has_required_azure(), 'The Azure Python SDK must be >= {}.'.format(REQUIRED_AZURE))
  37. class AzureTest(CloudTest):
  38. '''
  39. Integration tests for the Azure cloud provider in Salt-Cloud
  40. '''
  41. PROVIDER = 'azurearm'
  42. REQUIRED_PROVIDER_CONFIG_ITEMS = ('subscription_id',)
  43. def test_instance(self):
  44. '''
  45. Test creating an instance on Azure
  46. '''
  47. # check if instance with salt installed returned
  48. ret_val = self.run_cloud('-p azure-test {0}'.format(self.instance_name), timeout=TIMEOUT)
  49. self.assertInstanceExists(ret_val)
  50. self.assertDestroyInstance(timeout=TIMEOUT)