test_gogrid.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. # Import Salt Testing Libs
  9. from tests.support.case import ShellCase
  10. from tests.support.paths import FILES
  11. from tests.support.helpers import expensiveTest, generate_random_name
  12. from tests.support.unit import skipIf
  13. # Import Salt Libs
  14. from salt.config import cloud_providers_config
  15. # Create the cloud instance name to be used throughout the tests
  16. INSTANCE_NAME = generate_random_name('CLOUD-TEST-')
  17. PROVIDER_NAME = 'gogrid'
  18. @skipIf(True, 'waiting on bug report fixes from #13365')
  19. class GoGridTest(ShellCase):
  20. '''
  21. Integration tests for the GoGrid cloud provider in Salt-Cloud
  22. '''
  23. @expensiveTest
  24. def setUp(self):
  25. '''
  26. Sets up the test requirements
  27. '''
  28. super(GoGridTest, self).setUp()
  29. # check if appropriate cloud provider and profile files are present
  30. profile_str = 'gogrid-config'
  31. providers = self.run_cloud('--list-providers')
  32. if profile_str + ':' not in providers:
  33. self.skipTest(
  34. 'Configuration file for {0} was not found. Check {0}.conf files '
  35. 'in tests/integration/files/conf/cloud.*.d/ to run these tests.'
  36. .format(PROVIDER_NAME)
  37. )
  38. # check if client_key and api_key are present
  39. config = cloud_providers_config(
  40. os.path.join(
  41. FILES,
  42. 'conf',
  43. 'cloud.providers.d',
  44. PROVIDER_NAME + '.conf'
  45. )
  46. )
  47. api = config[profile_str][PROVIDER_NAME]['apikey']
  48. shared_secret = config[profile_str][PROVIDER_NAME]['sharedsecret']
  49. if api == '' or shared_secret == '':
  50. self.skipTest(
  51. 'An api key and shared secret must be provided to run these tests. '
  52. 'Check tests/integration/files/conf/cloud.providers.d/{0}.conf'
  53. .format(PROVIDER_NAME)
  54. )
  55. def test_instance(self):
  56. '''
  57. Test creating an instance on GoGrid
  58. '''
  59. # check if instance with salt installed returned
  60. try:
  61. self.assertIn(
  62. INSTANCE_NAME,
  63. [i.strip() for i in self.run_cloud('-p gogrid-test {0}'.format(INSTANCE_NAME), timeout=500)]
  64. )
  65. except AssertionError:
  66. self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)
  67. raise
  68. # delete the instance
  69. try:
  70. self.assertIn(
  71. INSTANCE_NAME + ':',
  72. [i.strip() for i in self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)]
  73. )
  74. except AssertionError:
  75. raise
  76. def tearDown(self):
  77. '''
  78. Clean up after tests
  79. '''
  80. query = self.run_cloud('--query')
  81. ret_str = ' {0}:'.format(INSTANCE_NAME)
  82. # if test instance is still present, delete it
  83. if ret_str in query:
  84. self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME), timeout=500)