test_zeromq.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test salt.utils.zeromq
  4. """
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import salt libs
  8. import salt.utils.zeromq
  9. import zmq
  10. from salt._compat import ipaddress
  11. from salt.exceptions import SaltSystemExit
  12. from tests.support.mock import patch
  13. # Import Salt Testing libs
  14. from tests.support.unit import TestCase, skipIf
  15. class UtilsTestCase(TestCase):
  16. def test_ip_bracket(self):
  17. test_ipv4 = "127.0.0.1"
  18. test_ipv6 = "::1"
  19. test_ipv6_uri = "[::1]"
  20. self.assertEqual(test_ipv4, salt.utils.zeromq.ip_bracket(test_ipv4))
  21. self.assertEqual(
  22. "[{0}]".format(test_ipv6), salt.utils.zeromq.ip_bracket(test_ipv6)
  23. )
  24. self.assertEqual(
  25. "[{0}]".format(test_ipv6), salt.utils.zeromq.ip_bracket(test_ipv6_uri)
  26. )
  27. ip_addr_obj = ipaddress.ip_address(test_ipv4)
  28. self.assertEqual(test_ipv4, salt.utils.zeromq.ip_bracket(ip_addr_obj))
  29. @skipIf(
  30. not hasattr(zmq, "IPC_PATH_MAX_LEN"), "ZMQ does not have max length support."
  31. )
  32. def test_check_ipc_length(self):
  33. """
  34. Ensure we throw an exception if we have a too-long IPC URI
  35. """
  36. with patch("zmq.IPC_PATH_MAX_LEN", 1):
  37. self.assertRaises(
  38. SaltSystemExit, salt.utils.zeromq.check_ipc_path_max_len, "1" * 1024
  39. )