test_match.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. tests.integration.states.match
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Import python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. import os
  10. # Import Salt Testing libs
  11. from tests.support.case import ModuleCase
  12. from tests.support.paths import FILES
  13. from tests.support.helpers import skip_if_not_root
  14. # Import salt libs
  15. import salt.utils.files
  16. import salt.utils.stringutils
  17. STATE_DIR = os.path.join(FILES, 'file', 'base')
  18. class StateMatchTest(ModuleCase):
  19. '''
  20. Validate the file state
  21. '''
  22. @skip_if_not_root
  23. def test_issue_2167_ipcidr_no_AttributeError(self):
  24. subnets = self.run_function('network.subnets')
  25. self.assertTrue(len(subnets) > 0)
  26. top_filename = 'issue-2167-ipcidr-match.sls'
  27. top_file = os.path.join(STATE_DIR, top_filename)
  28. try:
  29. with salt.utils.files.fopen(top_file, 'w') as fp_:
  30. fp_.write(
  31. salt.utils.stringutils.to_str(
  32. 'base:\n'
  33. ' {0}:\n'
  34. ' - match: ipcidr\n'
  35. ' - test\n'.format(subnets[0])
  36. )
  37. )
  38. ret = self.run_function('state.top', [top_filename])
  39. self.assertNotIn(
  40. 'AttributeError: \'Matcher\' object has no attribute '
  41. '\'functions\'',
  42. ret
  43. )
  44. finally:
  45. os.remove(top_file)