test_zeromq.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 zmq
  8. from salt._compat import ipaddress
  9. # Import Salt Testing libs
  10. from tests.support.unit import TestCase, skipIf
  11. from tests.support.mock import (
  12. patch,
  13. )
  14. # Import salt libs
  15. import salt.utils.zeromq
  16. from salt.exceptions import SaltSystemExit
  17. class UtilsTestCase(TestCase):
  18. def test_ip_bracket(self):
  19. test_ipv4 = '127.0.0.1'
  20. test_ipv6 = '::1'
  21. test_ipv6_uri = '[::1]'
  22. self.assertEqual(test_ipv4, salt.utils.zeromq.ip_bracket(test_ipv4))
  23. self.assertEqual('[{0}]'.format(test_ipv6), salt.utils.zeromq.ip_bracket(test_ipv6))
  24. self.assertEqual('[{0}]'.format(test_ipv6), salt.utils.zeromq.ip_bracket(test_ipv6_uri))
  25. ip_addr_obj = ipaddress.ip_address(test_ipv4)
  26. self.assertEqual(test_ipv4, salt.utils.zeromq.ip_bracket(ip_addr_obj))
  27. @skipIf(not hasattr(zmq, 'IPC_PATH_MAX_LEN'), "ZMQ does not have max length support.")
  28. def test_check_ipc_length(self):
  29. '''
  30. Ensure we throw an exception if we have a too-long IPC URI
  31. '''
  32. with patch('zmq.IPC_PATH_MAX_LEN', 1):
  33. self.assertRaises(SaltSystemExit, salt.utils.zeromq.check_ipc_path_max_len, '1' * 1024)