1
0

test_kitchen.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. import salt.utils.path
  10. import setup
  11. from salt.modules import cmdmod as cmd
  12. from tests.support.unit import TestCase, skipIf
  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(
  31. cls.topdir, "dist", "salt-{0}.tar.gz".format(setup.__version__)
  32. ),
  33. }
  34. @classmethod
  35. def tearDownClass(cls):
  36. del cls.topdir
  37. del cls.env
  38. def tearDown(self):
  39. cmd.run(
  40. "bundle exec kitchen destroy all",
  41. cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
  42. env=self.env,
  43. use_vt=self.use_vt,
  44. )
  45. del self.testdir
  46. def func_builder(testdir):
  47. def func(self):
  48. self.testdir = testdir
  49. if "TESTS_XML_OUTPUT_DIR" in os.environ:
  50. self.env[
  51. "TESTS_JUNIT_XML_PATH"
  52. ] = "{0}/kitchen.tests.{1}.$KITCHEN_SUITE.$KITCHEN_PLATFORM.xml".format(
  53. os.environ.get("TESTS_XML_OUTPUT_DIR"), self.testdir,
  54. )
  55. self.assertEqual(
  56. cmd.retcode(
  57. "bundle exec kitchen converge -c 999 all",
  58. cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
  59. env=self.env,
  60. use_vt=self.use_vt,
  61. ),
  62. 0,
  63. )
  64. self.assertEqual(
  65. cmd.retcode(
  66. "bundle exec kitchen verify all",
  67. cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
  68. env=self.env,
  69. use_vt=self.use_vt,
  70. ),
  71. 0,
  72. )
  73. return func
  74. for testdir in os.listdir(os.path.join(CURRENT_DIR, "tests")):
  75. setattr(KitchenTestCase, "test_kitchen_{0}".format(testdir), func_builder(testdir))