test_match.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 pytest
  11. # Import Salt Testing libs
  12. from tests.support.case import ModuleCase
  13. from tests.support.runtests import RUNTIME_VARS
  14. # Import salt libs
  15. import salt.utils.files
  16. import salt.utils.stringutils
  17. class StateMatchTest(ModuleCase):
  18. '''
  19. Validate the file state
  20. '''
  21. @pytest.mark.skip_if_not_root
  22. def test_issue_2167_ipcidr_no_AttributeError(self):
  23. subnets = self.run_function('network.subnets')
  24. self.assertTrue(len(subnets) > 0)
  25. top_filename = 'issue-2167-ipcidr-match.sls'
  26. top_file = os.path.join(RUNTIME_VARS.BASE_FILES, top_filename)
  27. try:
  28. with salt.utils.files.fopen(top_file, 'w') as fp_:
  29. fp_.write(
  30. salt.utils.stringutils.to_str(
  31. 'base:\n'
  32. ' {0}:\n'
  33. ' - match: ipcidr\n'
  34. ' - test\n'.format(subnets[0])
  35. )
  36. )
  37. ret = self.run_function('state.top', [top_filename])
  38. self.assertNotIn(
  39. 'AttributeError: \'Matcher\' object has no attribute '
  40. '\'functions\'',
  41. ret
  42. )
  43. finally:
  44. os.remove(top_file)