test_custom_module.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. :codeauthor: Daniel Mizyrycki (mzdaniel@glidelink.net)
  3. tests.integration.cli.custom_module
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Test salt-ssh sls with a custom module work.
  6. $ cat srv/custom_module.sls
  7. custom-module:
  8. module.run:
  9. - name: test.recho
  10. - text: hello
  11. $ cat srv/_modules/override_test.py
  12. __virtualname__ = 'test'
  13. def __virtual__():
  14. return __virtualname__
  15. def recho(text):
  16. return text[::-1]
  17. $ salt-ssh localhost state.sls custom_module
  18. localhost:
  19. olleh
  20. """
  21. import pytest
  22. from tests.support.case import SSHCase
  23. from tests.support.helpers import slowTest
  24. @pytest.mark.windows_whitelisted
  25. class SSHCustomModuleTest(SSHCase):
  26. """
  27. Test sls with custom module functionality using ssh
  28. """
  29. @slowTest
  30. def test_ssh_regular_module(self):
  31. """
  32. Test regular module work using SSHCase environment
  33. """
  34. expected = "hello"
  35. cmd = self.run_function("test.echo", arg=["hello"])
  36. self.assertEqual(expected, cmd)
  37. @slowTest
  38. def test_ssh_custom_module(self):
  39. """
  40. Test custom module work using SSHCase environment
  41. """
  42. expected = "hello"[::-1]
  43. cmd = self.run_function("test.recho", arg=["hello"])
  44. self.assertEqual(expected, cmd)
  45. @slowTest
  46. def test_ssh_sls_with_custom_module(self):
  47. """
  48. Test sls with custom module work using SSHCase environment
  49. """
  50. expected = {
  51. "module_|-regular-module_|-test.echo_|-run": "hello",
  52. "module_|-custom-module_|-test.recho_|-run": "olleh",
  53. }
  54. cmd = self.run_function("state.sls", arg=["custom_module"])
  55. for key in cmd:
  56. if not isinstance(cmd, dict) or not isinstance(cmd[key], dict):
  57. raise AssertionError("{} is not a proper state return".format(cmd))
  58. elif not cmd[key]["result"]:
  59. raise AssertionError(cmd[key]["comment"])
  60. cmd_ret = cmd[key]["changes"].get("ret", None)
  61. self.assertEqual(cmd_ret, expected[key])