test_cloud.py 2.3 KB

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