test_profitbricks.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 Salt Testing Libs
  8. from tests.support.unit import skipIf
  9. # Import Third-Party Libs
  10. from tests.integration.cloud.helpers.cloud_test_base import TIMEOUT, CloudTest
  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('Conf items are missing that must be provided to run these tests: username, password'
  31. '\nCheck tests/integration/files/conf/cloud.providers.d/{0}.conf'.format(self.PROVIDER))
  32. def test_list_images(self):
  33. '''
  34. Tests the return of running the --list-images command for ProfitBricks
  35. '''
  36. list_images = self.run_cloud('--list-images {0}'.format(self.PROVIDER))
  37. self.assertIn(
  38. 'Ubuntu-16.04-LTS-server-2017-10-01',
  39. [i.strip() for i in list_images]
  40. )
  41. def test_list_image_alias(self):
  42. '''
  43. Tests the return of running the -f list_images
  44. command for ProfitBricks
  45. '''
  46. cmd = '-f list_images {0}'.format(self.PROVIDER)
  47. list_images = self.run_cloud(cmd)
  48. self.assertIn(
  49. '- ubuntu:latest',
  50. [i.strip() for i in list_images]
  51. )
  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(
  58. 'Micro Instance:',
  59. [i.strip() for i in list_sizes]
  60. )
  61. def test_list_datacenters(self):
  62. '''
  63. Tests the return of running the -f list_datacenters
  64. command for ProfitBricks
  65. '''
  66. cmd = '-f list_datacenters {0}'.format(self.PROVIDER)
  67. list_datacenters = self.run_cloud(cmd)
  68. self.assertIn(
  69. self.provider_config['datacenter_id'],
  70. [i.strip() for i in list_datacenters]
  71. )
  72. def test_list_nodes(self):
  73. '''
  74. Tests the return of running the -f list_nodes command for ProfitBricks
  75. '''
  76. list_nodes = self.run_cloud('-f list_nodes {0}'.format(self.PROVIDER))
  77. self.assertIn(
  78. 'state:',
  79. [i.strip() for i in list_nodes]
  80. )
  81. self.assertIn(
  82. 'name:',
  83. [i.strip() for i in list_nodes]
  84. )
  85. def test_list_nodes_full(self):
  86. '''
  87. Tests the return of running the -f list_nodes_full
  88. command for ProfitBricks
  89. '''
  90. cmd = '-f list_nodes_full {0}'.format(self.PROVIDER)
  91. list_nodes = self.run_cloud(cmd)
  92. self.assertIn(
  93. 'state:',
  94. [i.strip() for i in list_nodes]
  95. )
  96. self.assertIn(
  97. 'name:',
  98. [i.strip() for i in list_nodes]
  99. )
  100. def test_list_location(self):
  101. '''
  102. Tests the return of running the --list-locations
  103. command for ProfitBricks
  104. '''
  105. cmd = '--list-locations {0}'.format(self.PROVIDER)
  106. list_locations = self.run_cloud(cmd)
  107. self.assertIn(
  108. 'de/fkb',
  109. [i.strip() for i in list_locations]
  110. )
  111. self.assertIn(
  112. 'de/fra',
  113. [i.strip() for i in list_locations]
  114. )
  115. self.assertIn(
  116. 'us/las',
  117. [i.strip() for i in list_locations]
  118. )
  119. self.assertIn(
  120. 'us/ewr',
  121. [i.strip() for i in list_locations]
  122. )
  123. def test_instance(self):
  124. '''
  125. Test creating an instance on ProfitBricks
  126. '''
  127. # check if instance with salt installed returned
  128. ret_str = self.run_cloud('-p profitbricks-test {0}'.format(self.instance_name), timeout=TIMEOUT)
  129. self.assertInstanceExists(ret_str)
  130. self.assertDestroyInstance()