test_cloud.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for functions located in the salt.cloud.__init__.py file.
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import salt.cloud
  7. from tests.integration.cloud.helpers.cloud_test_base import CloudTest
  8. from tests.support.helpers import PRE_PYTEST_SKIP, expensiveTest
  9. @PRE_PYTEST_SKIP
  10. class CloudClientTestCase(CloudTest):
  11. """
  12. Integration tests for the CloudClient class. Uses DigitalOcean as a salt-cloud provider.
  13. """
  14. PROVIDER = "digitalocean"
  15. REQUIRED_PROVIDER_CONFIG_ITEMS = tuple()
  16. IMAGE_NAME = "14.04.5 x64"
  17. @expensiveTest
  18. def setUp(self):
  19. # Use a --list-images salt-cloud call to see if the DigitalOcean provider is
  20. # configured correctly before running any tests.
  21. images = self.run_cloud("--list-images {0}".format(self.PROVIDER))
  22. if self.image_name not in [i.strip() for i in images]:
  23. self.skipTest(
  24. "Image '{0}' was not found in image search. Is the {1} provider "
  25. "configured correctly for this test?".format(
  26. self.PROVIDER, self.image_name
  27. )
  28. )
  29. def test_cloud_client_create_and_delete(self):
  30. """
  31. Tests that a VM is created successfully when calling salt.cloud.CloudClient.create(),
  32. which does not require a profile configuration.
  33. Also checks that salt.cloud.CloudClient.destroy() works correctly since this test needs
  34. to remove the VM after creating it.
  35. This test was created as a regression check against Issue #41971.
  36. """
  37. cloud_client = salt.cloud.CloudClient(self.config_file)
  38. # Create the VM using salt.cloud.CloudClient.create() instead of calling salt-cloud
  39. ret_val = cloud_client.create(
  40. provider=self.PROVIDER,
  41. names=[self.instance_name],
  42. image=self.IMAGE_NAME,
  43. location="sfo1",
  44. size="512mb",
  45. vm_size="512mb",
  46. )
  47. # Check that the VM was created correctly
  48. self.assertInstanceExists(ret_val)
  49. # Clean up after ourselves and delete the VM
  50. deleted = cloud_client.destroy(names=[self.instance_name])
  51. # Check that the VM was deleted correctly
  52. self.assertIn(self.instance_name, deleted)