test_ext_modules.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.runtests import RUNTIME_VARS
  14. @pytest.mark.windows_whitelisted
  15. class LoaderOverridesTest(ModuleCase):
  16. def setUp(self):
  17. self.run_function("saltutil.sync_modules")
  18. @pytest.mark.slow_test(seconds=120) # Test takes >60 and <=120 seconds
  19. def test_overridden_internal(self):
  20. # To avoid a race condition on Windows, we need to make sure the
  21. # `override_test.py` file is present in the _modules directory before
  22. # trying to list all functions. This test may execute before the
  23. # minion has finished syncing down the files it needs.
  24. module = os.path.join(
  25. RUNTIME_VARS.TMP,
  26. "rootdir",
  27. "cache",
  28. "files",
  29. "base",
  30. "_modules",
  31. "override_test.py",
  32. )
  33. tries = 0
  34. while not os.path.exists(module):
  35. tries += 1
  36. if tries > 60:
  37. break
  38. time.sleep(1)
  39. funcs = self.run_function("sys.list_functions")
  40. # We placed a test module under _modules.
  41. # The previous functions should also still exist.
  42. self.assertIn("test.ping", funcs)
  43. # A non existing function should, of course, not exist
  44. self.assertNotIn("brain.left_hemisphere", funcs)
  45. # There should be a new function for the test module, recho
  46. self.assertIn("test.recho", funcs)
  47. text = "foo bar baz quo qux"
  48. self.assertEqual(
  49. self.run_function("test.echo", arg=[text])[::-1],
  50. self.run_function("test.recho", arg=[text]),
  51. )