1
0

test_cloud.py 2.3 KB

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