test_proxy_minion.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 pytest
  10. import salt.ext.tornado
  11. import salt.ext.tornado.testing
  12. # Import salt libs
  13. import salt.minion
  14. import salt.syspaths
  15. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  16. # Import Salt Testing libs
  17. from tests.support.unit import TestCase
  18. log = logging.getLogger(__name__)
  19. __opts__ = {}
  20. class ProxyMinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
  21. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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.copy()
  27. mock_jid_queue = [123]
  28. proxy_minion = salt.minion.ProxyMinion(
  29. mock_opts,
  30. jid_queue=copy.copy(mock_jid_queue),
  31. io_loop=salt.ext.tornado.ioloop.IOLoop(),
  32. )
  33. try:
  34. ret = proxy_minion._post_master_init("dummy_master")
  35. self.assert_called_once(salt.minion._metaproxy_call)
  36. finally:
  37. proxy_minion.destroy()
  38. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  39. def test_handle_decoded_payload_metaproxy_called(self):
  40. """
  41. Tests that when the _handle_decoded_payload function is called, _metaproxy_call is also called.
  42. """
  43. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  44. mock_data = {"fun": "foo.bar", "jid": 123}
  45. mock_jid_queue = [123]
  46. proxy_minion = salt.minion.ProxyMinion(
  47. mock_opts,
  48. jid_queue=copy.copy(mock_jid_queue),
  49. io_loop=salt.ext.tornado.ioloop.IOLoop(),
  50. )
  51. try:
  52. ret = proxy_minion._handle_decoded_payload(mock_data).result()
  53. self.assertEqual(proxy_minion.jid_queue, mock_jid_queue)
  54. self.assertIsNone(ret)
  55. self.assert_called_once(salt.minion._metaproxy_call)
  56. finally:
  57. proxy_minion.destroy()
  58. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  59. def test_handle_payload_metaproxy_called(self):
  60. """
  61. Tests that when the _handle_payload function is called, _metaproxy_call is also called.
  62. """
  63. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  64. mock_data = {"fun": "foo.bar", "jid": 123}
  65. mock_jid_queue = [123]
  66. proxy_minion = salt.minion.ProxyMinion(
  67. mock_opts,
  68. jid_queue=copy.copy(mock_jid_queue),
  69. io_loop=salt.ext.tornado.ioloop.IOLoop(),
  70. )
  71. try:
  72. ret = proxy_minion._handle_decoded_payload(mock_data).result()
  73. self.assertEqual(proxy_minion.jid_queue, mock_jid_queue)
  74. self.assertIsNone(ret)
  75. self.assert_called_once(salt.minion._metaproxy_call)
  76. finally:
  77. proxy_minion.destroy()