1
0

test_proxy_minion.py 2.8 KB

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