test_ext_modules.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Import Python libs
  9. from __future__ import absolute_import, print_function, unicode_literals
  10. import os
  11. import time
  12. # Import Salt Testing libs
  13. from tests.support.runtests import RUNTIME_VARS
  14. from tests.support.case import ModuleCase
  15. class LoaderOverridesTest(ModuleCase):
  16. def setUp(self):
  17. self.run_function('saltutil.sync_modules')
  18. def test_overridden_internal(self):
  19. # To avoid a race condition on Windows, we need to make sure the
  20. # `override_test.py` file is present in the _modules directory before
  21. # trying to list all functions. This test may execute before the
  22. # minion has finished syncing down the files it needs.
  23. module = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache', 'files',
  24. 'base', '_modules', 'override_test.py')
  25. tries = 0
  26. while not os.path.exists(module):
  27. tries += 1
  28. if tries > 60:
  29. break
  30. time.sleep(1)
  31. funcs = self.run_function('sys.list_functions')
  32. # We placed a test module under _modules.
  33. # The previous functions should also still exist.
  34. self.assertIn('test.ping', funcs)
  35. # A non existing function should, of course, not exist
  36. self.assertNotIn('brain.left_hemisphere', funcs)
  37. # There should be a new function for the test module, recho
  38. self.assertIn('test.recho', funcs)
  39. text = 'foo bar baz quo qux'
  40. self.assertEqual(
  41. self.run_function('test.echo', arg=[text])[::-1],
  42. self.run_function('test.recho', arg=[text]),
  43. )