test_match.py 1.4 KB

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