test_msazure.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Libs
  9. from salt.utils.versions import LooseVersion
  10. # Import Salt Testing Libs
  11. from tests.integration.cloud.helpers.cloud_test_base import CloudTest
  12. from tests.support.unit import skipIf
  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(
  37. not __has_required_azure(),
  38. "The Azure Python SDK must be >= {}.".format(REQUIRED_AZURE),
  39. )
  40. class AzureTest(CloudTest):
  41. """
  42. Integration tests for the Azure cloud provider in Salt-Cloud
  43. """
  44. PROVIDER = "azurearm"
  45. REQUIRED_PROVIDER_CONFIG_ITEMS = ("subscription_id",)
  46. def test_instance(self):
  47. """
  48. Test creating an instance on Azure
  49. """
  50. # check if instance with salt installed returned
  51. ret_val = self.run_cloud(
  52. "-p azure-test {0}".format(self.instance_name), timeout=TIMEOUT
  53. )
  54. self.assertInstanceExists(ret_val)
  55. self.assertDestroyInstance(timeout=TIMEOUT)