1
0

test_kitchen.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test wrapper for running all KitchenSalt tests
  4. All directories in 'tests/kitchen/' will be treated as a separate test under
  5. the KitchenTestCase.
  6. '''
  7. from __future__ import absolute_import
  8. import os
  9. from tests.support.unit import TestCase, skipIf
  10. import setup
  11. import salt.utils.path
  12. from salt.modules import cmdmod as cmd
  13. CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
  14. @skipIf(not salt.utils.path.which('bundle'), 'Bundler is not installed')
  15. class KitchenTestCase(TestCase):
  16. '''
  17. Test kitchen environments
  18. '''
  19. @classmethod
  20. def setUpClass(cls):
  21. '''
  22. setup kitchen tests
  23. '''
  24. cls.topdir = '/' + os.path.join(*CURRENT_DIR.split('/')[:-2])
  25. cls.use_vt = int(os.environ.get('TESTS_LOG_LEVEL')) >= 5
  26. cmd.run('python setup.py sdist', cwd=cls.topdir)
  27. cmd.run('bundle install', cwd=CURRENT_DIR)
  28. cls.env = {
  29. 'KITCHEN_YAML': os.path.join(CURRENT_DIR, '.kitchen.yml'),
  30. 'SALT_SDIST_PATH': os.path.join(cls.topdir, 'dist', 'salt-{0}.tar.gz'.format(setup.__version__)),
  31. }
  32. @classmethod
  33. def tearDownClass(cls):
  34. del cls.topdir
  35. del cls.env
  36. def tearDown(self):
  37. cmd.run(
  38. 'bundle exec kitchen destroy all',
  39. cwd=os.path.join(CURRENT_DIR, 'tests', self.testdir),
  40. env=self.env,
  41. use_vt=self.use_vt,
  42. )
  43. del self.testdir
  44. def func_builder(testdir):
  45. def func(self):
  46. self.testdir = testdir
  47. if 'TESTS_XML_OUTPUT_DIR' in os.environ:
  48. self.env['TESTS_JUNIT_XML_PATH'] = '{0}/kitchen.tests.{1}.$KITCHEN_SUITE.$KITCHEN_PLATFORM.xml'.format(
  49. os.environ.get('TESTS_XML_OUTPUT_DIR'),
  50. self.testdir,
  51. )
  52. self.assertEqual(
  53. cmd.retcode(
  54. 'bundle exec kitchen converge -c 999 all',
  55. cwd=os.path.join(CURRENT_DIR, 'tests', self.testdir),
  56. env=self.env,
  57. use_vt=self.use_vt,
  58. ),
  59. 0
  60. )
  61. self.assertEqual(
  62. cmd.retcode(
  63. 'bundle exec kitchen verify all',
  64. cwd=os.path.join(CURRENT_DIR, 'tests', self.testdir),
  65. env=self.env,
  66. use_vt=self.use_vt,
  67. ),
  68. 0
  69. )
  70. return func
  71. for testdir in os.listdir(os.path.join(CURRENT_DIR, 'tests')):
  72. setattr(KitchenTestCase, 'test_kitchen_{0}'.format(testdir), func_builder(testdir))