Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire events to all syndics from MoM when using tcp transport and syndic topology #55607

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/transport/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def publish(self, load):
int_payload = {'payload': self.serial.dumps(payload)}

# add some targeting stuff for lists only (for now)
if load['tgt_type'] == 'list':
if load['tgt_type'] == 'list' and not self.opts.get("order_masters", False):
if isinstance(load['tgt'], six.string_types):
# Fetch a list of minions that match
_res = self.ckminions.check_minions(load['tgt'],
Expand Down
74 changes: 72 additions & 2 deletions tests/unit/transport/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import salt.transport.client
import salt.exceptions
from salt.ext.six.moves import range
from salt.transport.tcp import SaltMessageClientPool, SaltMessageClient
from salt.transport.tcp import SaltMessageClientPool, SaltMessageClient, TCPPubServerChannel

# Import Salt Testing libs
from tests.support.unit import TestCase, skipIf
Expand Down Expand Up @@ -223,7 +223,7 @@ def tearDown(self):
for k, v in six.iteritems(self.io_loop._handlers):
if self._start_handlers.get(k) != v:
failures.append((k, v))
if len(failures) > 0:
if failures:
raise Exception('FDs still attached to the IOLoop: {0}'.format(failures))
del self.channel
del self._start_handlers
Expand Down Expand Up @@ -359,3 +359,73 @@ def stop(*args, **kwargs):
orig_loop.stop = orig_loop.real_stop
del orig_loop.real_stop
del orig_loop.stop_called


class TCPPubServerChannelTest(TestCase, AdaptedConfigurationTestCaseMixin):
@patch('salt.master.SMaster.secrets')
@patch('salt.crypt.Crypticle')
@patch('salt.utils.asynchronous.SyncWrapper')
def test_publish_filtering(self, sync_wrapper, crypticle, secrets):
opts = self.get_temp_config('master')
opts["sign_pub_messages"] = False
channel = TCPPubServerChannel(opts)

wrap = MagicMock()
crypt = MagicMock()
crypt.dumps.return_value = {"test": "value"}

secrets.return_value = {"aes": {"secret": None}}
crypticle.return_value = crypt
sync_wrapper.return_value = wrap

# try simple publish with glob tgt_type
channel.publish({"test": "value", "tgt_type": "glob", "tgt": "*"})
payload = wrap.send.call_args[0][0]

# verify we send it without any specific topic
assert "topic_lst" not in payload

# try simple publish with list tgt_type
channel.publish({"test": "value", "tgt_type": "list", "tgt": ["minion01"]})
payload = wrap.send.call_args[0][0]

# verify we send it with correct topic
assert "topic_lst" in payload
self.assertEqual(payload["topic_lst"], ["minion01"])

# try with syndic settings
opts['order_masters'] = True
channel.publish({"test": "value", "tgt_type": "list", "tgt": ["minion01"]})
payload = wrap.send.call_args[0][0]

# verify we send it without topic for syndics
assert "topic_lst" not in payload

@patch('salt.utils.minions.CkMinions.check_minions')
@patch('salt.master.SMaster.secrets')
@patch('salt.crypt.Crypticle')
@patch('salt.utils.asynchronous.SyncWrapper')
def test_publish_filtering_str_list(self, sync_wrapper, crypticle, secrets, check_minions):
opts = self.get_temp_config('master')
opts["sign_pub_messages"] = False
channel = TCPPubServerChannel(opts)

wrap = MagicMock()
crypt = MagicMock()
crypt.dumps.return_value = {"test": "value"}

secrets.return_value = {"aes": {"secret": None}}
crypticle.return_value = crypt
sync_wrapper.return_value = wrap
check_minions.return_value = {"minions": ["minion02"]}

# try simple publish with list tgt_type
channel.publish({"test": "value", "tgt_type": "list", "tgt": "minion02"})
payload = wrap.send.call_args[0][0]

# verify we send it with correct topic
assert "topic_lst" in payload
self.assertEqual(payload["topic_lst"], ["minion02"])

# verify it was correctly calling check_minions
check_minions.assert_called_with("minion02", tgt_type="list")