test_vultrpy.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 10 x64 (buster)',
  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('2048 MB RAM,64 GB SSD,2.00 TB BW', [i.strip() for i in size_list])
  41. # Commented for now, Vultr driver does not yet support key management
  42. # def test_key_management(self):
  43. # '''
  44. # Test key management
  45. # '''
  46. # pub = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example'
  47. # finger_print = '3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa'
  48. #
  49. # _key = self.run_cloud('-f create_key {0} name="MyPubKey" public_key="{1}"'.format(self.PROVIDER, pub))
  50. #
  51. # # Upload public key
  52. # self.assertIn(
  53. # finger_print,
  54. # [i.strip() for i in _key]
  55. # )
  56. #
  57. # try:
  58. # # List all keys
  59. # list_keypairs = self.run_cloud('-f list_keypairs {0}'.format(self.PROVIDER))
  60. #
  61. # self.assertIn(
  62. # finger_print,
  63. # [i.strip() for i in list_keypairs]
  64. # )
  65. #
  66. # # List key
  67. # show_keypair = self.run_cloud('-f show_keypair {0} keyname={1}'.format(self.PROVIDER, 'MyPubKey'))
  68. #
  69. # self.assertIn(
  70. # finger_print,
  71. # [i.strip() for i in show_keypair]
  72. # )
  73. # except AssertionError:
  74. # # Delete the public key if the above assertions fail
  75. # self.run_cloud('-f remove_key {0} id={1}'.format(self.PROVIDER, finger_print))
  76. # raise
  77. #
  78. # # Delete public key
  79. # self.assertTrue(self.run_cloud('-f remove_key {0} id={1}'.format(self.PROVIDER, finger_print)))
  80. @skipIf(True, 'Skipped temporarily')
  81. def test_instance(self):
  82. '''
  83. Test creating an instance on Vultr
  84. '''
  85. # check if instance with salt installed returned
  86. ret_val = self.run_cloud('-p vultr-test {0}'.format(self.instance_name), timeout=TIMEOUT + 300)
  87. self.assertInstanceExists(ret_val)
  88. # Vultr won't let us delete an instance less than 5 minutes old.
  89. time.sleep(300)
  90. self.assertDestroyInstance()