1
0

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