1
0

test_env.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test case for env sdb module
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. import textwrap
  8. import pytest
  9. import salt.utils.files
  10. from tests.support.case import ModuleCase
  11. from tests.support.helpers import slowTest
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. from tests.support.runtests import RUNTIME_VARS
  14. @pytest.mark.windows_whitelisted
  15. class EnvTestCase(ModuleCase, SaltReturnAssertsMixin):
  16. def setUp(self):
  17. self.state_name = "test_sdb_env"
  18. self.state_file_name = self.state_name + ".sls"
  19. self.state_file_set_var = os.path.join(
  20. RUNTIME_VARS.BASE_FILES, self.state_file_name
  21. )
  22. with salt.utils.files.fopen(self.state_file_set_var, "w") as wfh:
  23. wfh.write(
  24. textwrap.dedent(
  25. """\
  26. set some env var:
  27. cmd.run:
  28. - name: echo {{ salt['sdb.set']('sdb://osenv/foo', 'bar') }}
  29. - order: 1
  30. {% if salt['sdb.get']('sdb://osenv/foo') == 'bar' %}
  31. always-changes-and-succeeds:
  32. test.succeed_with_changes:
  33. - name: foo
  34. {% else %}
  35. always-changes-and-fails:
  36. test.fail_with_changes:
  37. - name: foo
  38. {% endif %}
  39. """
  40. )
  41. )
  42. def tearDown(self):
  43. os.remove(self.state_file_set_var)
  44. @slowTest
  45. def test_env_module_sets_key(self):
  46. state_key = "test_|-always-changes-and-succeeds_|-foo_|-succeed_with_changes"
  47. ret = self.run_function("state.sls", [self.state_name])
  48. self.assertTrue(ret[state_key]["result"])