test_vultrpy.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Integration tests for Vultr
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import time
  8. # Import Salt Testing Libs
  9. from tests.integration.cloud.helpers.cloud_test_base import CloudTest, TIMEOUT
  10. from tests.support.unit import skipIf
  11. class VultrTest(CloudTest):
  12. '''
  13. Integration tests for the Vultr cloud provider in Salt-Cloud
  14. '''
  15. PROVIDER = 'vultr'
  16. REQUIRED_PROVIDER_CONFIG_ITEMS = ('api_key', 'ssh_key_file', 'ssh_key_name')
  17. def test_list_images(self):
  18. '''
  19. Tests the return of running the --list-images command for Vultr
  20. '''
  21. image_list = self.run_cloud('--list-images {0}'.format(self.PROVIDER))
  22. self.assertIn(
  23. 'Debian 8 x64 (jessie)',
  24. [i.strip() for i in image_list]
  25. )
  26. def test_list_locations(self):
  27. '''
  28. Tests the return of running the --list-locations command for Vultr
  29. '''
  30. location_list = self.run_cloud('--list-locations {0}'.format(self.PROVIDER))
  31. self.assertIn(
  32. 'New Jersey',
  33. [i.strip() for i in location_list]
  34. )
  35. def test_list_sizes(self):
  36. '''
  37. Tests the return of running the --list-sizes command for Vultr
  38. '''
  39. size_list = self.run_cloud('--list-sizes {0}'.format(self.PROVIDER))
  40. self.assertIn(
  41. '32768 MB RAM,4x110 GB SSD,40.00 TB BW',
  42. [i.strip() for i in size_list]
  43. )
  44. # Commented for now, Vultr driver does not yet support key management
  45. # def test_key_management(self):
  46. # '''
  47. # Test key management
  48. # '''
  49. # pub = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example'
  50. # finger_print = '3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa'
  51. #
  52. # _key = self.run_cloud('-f create_key {0} name="MyPubKey" public_key="{1}"'.format(self.PROVIDER, pub))
  53. #
  54. # # Upload public key
  55. # self.assertIn(
  56. # finger_print,
  57. # [i.strip() for i in _key]
  58. # )
  59. #
  60. # try:
  61. # # List all keys
  62. # list_keypairs = self.run_cloud('-f list_keypairs {0}'.format(self.PROVIDER))
  63. #
  64. # self.assertIn(
  65. # finger_print,
  66. # [i.strip() for i in list_keypairs]
  67. # )
  68. #
  69. # # List key
  70. # show_keypair = self.run_cloud('-f show_keypair {0} keyname={1}'.format(self.PROVIDER, 'MyPubKey'))
  71. #
  72. # self.assertIn(
  73. # finger_print,
  74. # [i.strip() for i in show_keypair]
  75. # )
  76. # except AssertionError:
  77. # # Delete the public key if the above assertions fail
  78. # self.run_cloud('-f remove_key {0} id={1}'.format(self.PROVIDER, finger_print))
  79. # raise
  80. #
  81. # # Delete public key
  82. # self.assertTrue(self.run_cloud('-f remove_key {0} id={1}'.format(self.PROVIDER, finger_print)))
  83. @skipIf(True, 'Skipped temporarily')
  84. def test_instance(self):
  85. '''
  86. Test creating an instance on Vultr
  87. '''
  88. # check if instance with salt installed returned
  89. ret_val = self.run_cloud('-p vultr-test {0}'.format(self.instance_name), timeout=TIMEOUT + 300)
  90. self.assertInstanceExists(ret_val)
  91. # Vultr won't let us delete an instance less than 5 minutes old.
  92. time.sleep(300)
  93. self.assertDestroyInstance()