1
0

test_ext_modules.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. integration.loader.ext_modules
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. Test Salt's loader regarding external overrides
  7. """
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. import os
  10. import time
  11. import pytest
  12. from tests.support.case import ModuleCase
  13. from tests.support.helpers import slowTest
  14. from tests.support.runtests import RUNTIME_VARS
  15. @pytest.mark.windows_whitelisted
  16. class LoaderOverridesTest(ModuleCase):
  17. def setUp(self):
  18. self.run_function("saltutil.sync_modules")
  19. @slowTest
  20. def test_overridden_internal(self):
  21. # To avoid a race condition on Windows, we need to make sure the
  22. # `override_test.py` file is present in the _modules directory before
  23. # trying to list all functions. This test may execute before the
  24. # minion has finished syncing down the files it needs.
  25. module = os.path.join(
  26. RUNTIME_VARS.TMP,
  27. "rootdir",
  28. "cache",
  29. "files",
  30. "base",
  31. "_modules",
  32. "override_test.py",
  33. )
  34. tries = 0
  35. while not os.path.exists(module):
  36. tries += 1
  37. if tries > 60:
  38. break
  39. time.sleep(1)
  40. funcs = self.run_function("sys.list_functions")
  41. # We placed a test module under _modules.
  42. # The previous functions should also still exist.
  43. self.assertIn("test.ping", funcs)
  44. # A non existing function should, of course, not exist
  45. self.assertNotIn("brain.left_hemisphere", funcs)
  46. # There should be a new function for the test module, recho
  47. self.assertIn("test.recho", funcs)
  48. text = "foo bar baz quo qux"
  49. self.assertEqual(
  50. self.run_function("test.echo", arg=[text])[::-1],
  51. self.run_function("test.recho", arg=[text]),
  52. )