test_proxy_minion.py 2.7 KB

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