test_profitbricks.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Ethan Devenport <ethand@stackpointcloud.com>
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Third-Party Libs
  8. from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
  9. # Import Salt Testing Libs
  10. from tests.support.unit import skipIf
  11. try:
  12. # pylint: disable=unused-import
  13. from profitbricks.client import ProfitBricksService
  14. HAS_PROFITBRICKS = True
  15. except ImportError:
  16. HAS_PROFITBRICKS = False
  17. @skipIf(HAS_PROFITBRICKS is False, "salt-cloud requires >= profitbricks 4.1.0")
  18. class ProfitBricksTest(CloudTest):
  19. """
  20. Integration tests for the ProfitBricks cloud provider
  21. """
  22. PROVIDER = "profitbricks"
  23. REQUIRED_PROVIDER_CONFIG_ITEMS = ("username", "password", "datacenter_id")
  24. def setUp(self):
  25. super(ProfitBricksTest, self).setUp()
  26. username = self.provider_config.get("username")
  27. password = self.provider_config.get("password")
  28. # A default username and password must be hard-coded as defaults as per issue #46265
  29. # If they are 'foo' and 'bar' it is the same as not being set
  30. self.skipTest(
  31. "Conf items are missing that must be provided to run these tests: username, password"
  32. "\nCheck tests/integration/files/conf/cloud.providers.d/{0}.conf".format(
  33. self.PROVIDER
  34. )
  35. )
  36. def test_list_images(self):
  37. """
  38. Tests the return of running the --list-images command for ProfitBricks
  39. """
  40. list_images = self.run_cloud("--list-images {0}".format(self.PROVIDER))
  41. self.assertIn(
  42. "Ubuntu-16.04-LTS-server-2017-10-01", [i.strip() for i in list_images]
  43. )
  44. def test_list_image_alias(self):
  45. """
  46. Tests the return of running the -f list_images
  47. command for ProfitBricks
  48. """
  49. cmd = "-f list_images {0}".format(self.PROVIDER)
  50. list_images = self.run_cloud(cmd)
  51. self.assertIn("- ubuntu:latest", [i.strip() for i in list_images])
  52. def test_list_sizes(self):
  53. """
  54. Tests the return of running the --list_sizes command for ProfitBricks
  55. """
  56. list_sizes = self.run_cloud("--list-sizes {0}".format(self.PROVIDER))
  57. self.assertIn("Micro Instance:", [i.strip() for i in list_sizes])
  58. def test_list_datacenters(self):
  59. """
  60. Tests the return of running the -f list_datacenters
  61. command for ProfitBricks
  62. """
  63. cmd = "-f list_datacenters {0}".format(self.PROVIDER)
  64. list_datacenters = self.run_cloud(cmd)
  65. self.assertIn(
  66. self.provider_config["datacenter_id"], [i.strip() for i in list_datacenters]
  67. )
  68. def test_list_nodes(self):
  69. """
  70. Tests the return of running the -f list_nodes command for ProfitBricks
  71. """
  72. list_nodes = self.run_cloud("-f list_nodes {0}".format(self.PROVIDER))
  73. self.assertIn("state:", [i.strip() for i in list_nodes])
  74. self.assertIn("name:", [i.strip() for i in list_nodes])
  75. def test_list_nodes_full(self):
  76. """
  77. Tests the return of running the -f list_nodes_full
  78. command for ProfitBricks
  79. """
  80. cmd = "-f list_nodes_full {0}".format(self.PROVIDER)
  81. list_nodes = self.run_cloud(cmd)
  82. self.assertIn("state:", [i.strip() for i in list_nodes])
  83. self.assertIn("name:", [i.strip() for i in list_nodes])
  84. def test_list_location(self):
  85. """
  86. Tests the return of running the --list-locations
  87. command for ProfitBricks
  88. """
  89. cmd = "--list-locations {0}".format(self.PROVIDER)
  90. list_locations = self.run_cloud(cmd)
  91. self.assertIn("de/fkb", [i.strip() for i in list_locations])
  92. self.assertIn("de/fra", [i.strip() for i in list_locations])
  93. self.assertIn("us/las", [i.strip() for i in list_locations])
  94. self.assertIn("us/ewr", [i.strip() for i in list_locations])
  95. def test_instance(self):
  96. """
  97. Test creating an instance on ProfitBricks
  98. """
  99. # check if instance with salt installed returned
  100. ret_str = self.run_cloud(
  101. "-p profitbricks-test {0}".format(self.instance_name), timeout=TIMEOUT
  102. )
  103. self.assertInstanceExists(ret_str)
  104. self.assertDestroyInstance()