test_proxy_minion.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Gareth J. Greenaway <gareth@saltstack.com>
  4. '''
  5. # Import python libs
  6. from __future__ import absolute_import
  7. import copy
  8. import logging
  9. import salt.ext.tornado
  10. import salt.ext.tornado.testing
  11. # Import Salt Testing libs
  12. from tests.support.unit import TestCase
  13. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  14. # Import salt libs
  15. import salt.minion
  16. import salt.syspaths
  17. log = logging.getLogger(__name__)
  18. __opts__ = {}
  19. class ProxyMinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  20. def test_post_master_init_metaproxy_called(self):
  21. '''
  22. Tests that when the _post_master_ini function is called, _metaproxy_call is also called.
  23. '''
  24. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  25. mock_jid_queue = [123]
  26. proxy_minion = salt.minion.ProxyMinion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=salt.ext.tornado.ioloop.IOLoop())
  27. try:
  28. ret = proxy_minion._post_master_init('dummy_master')
  29. self.assert_called_once(salt.minion._metaproxy_call)
  30. finally:
  31. proxy_minion.destroy()
  32. def test_handle_decoded_payload_metaproxy_called(self):
  33. '''
  34. Tests that when the _handle_decoded_payload function is called, _metaproxy_call is also called.
  35. '''
  36. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  37. mock_data = {'fun': 'foo.bar',
  38. 'jid': 123}
  39. mock_jid_queue = [123]
  40. proxy_minion = salt.minion.ProxyMinion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=salt.ext.tornado.ioloop.IOLoop())
  41. try:
  42. ret = proxy_minion._handle_decoded_payload(mock_data).result()
  43. self.assertEqual(proxy_minion.jid_queue, mock_jid_queue)
  44. self.assertIsNone(ret)
  45. self.assert_called_once(salt.minion._metaproxy_call)
  46. finally:
  47. proxy_minion.destroy()
  48. def test_handle_payload_metaproxy_called(self):
  49. '''
  50. Tests that when the _handle_payload function is called, _metaproxy_call is also called.
  51. '''
  52. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  53. mock_data = {'fun': 'foo.bar',
  54. 'jid': 123}
  55. mock_jid_queue = [123]
  56. proxy_minion = salt.minion.ProxyMinion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=salt.ext.tornado.ioloop.IOLoop())
  57. try:
  58. ret = proxy_minion._handle_decoded_payload(mock_data).result()
  59. self.assertEqual(proxy_minion.jid_queue, mock_jid_queue)
  60. self.assertIsNone(ret)
  61. self.assert_called_once(salt.minion._metaproxy_call)
  62. finally:
  63. proxy_minion.destroy()