mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Removing target and tgt_type from the cmdline that is passed along to Salt, the target is used else where and including it in the cmdline causes problem when it is passed along. Adding an additional test to ensure we are getting the right targt.
This commit is contained in:
parent
2ed4b38b02
commit
bcdef641e8
2 changed files with 32 additions and 11 deletions
|
@ -359,6 +359,12 @@ class SlackClient(object):
|
|||
use_cmdline = cmdline
|
||||
target = self.get_target(permitted_group, cmdline, use_cmdline)
|
||||
|
||||
# Remove target and tgt_type from commandline
|
||||
# that is sent along to Salt
|
||||
use_cmdline = [item for item
|
||||
in use_cmdline
|
||||
if all(not item.startswith(x) for x in ('target', 'tgt_type'))]
|
||||
|
||||
return (True, target, use_cmdline)
|
||||
|
||||
def message_text(self, m_data):
|
||||
|
|
|
@ -43,19 +43,20 @@ class EngineSlackTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
trigger_string = '!'
|
||||
|
||||
loaded_groups = {u'default': {u'targets': {},
|
||||
u'commands': set([u'cmd.run', u'test.ping']),
|
||||
u'default_target': {u'tgt_type': u'glob', u'target': u'*'},
|
||||
u'users': set([u'gareth']),
|
||||
u'aliases': {u'whoami': {u'cmd': u'cmd.run whoami'},
|
||||
u'list_pillar': {u'cmd': u'pillar.items'}}
|
||||
}}
|
||||
loaded_groups = {'default': {'targets': {},
|
||||
'commands': set(['cmd.run', 'test.ping']),
|
||||
'default_target': {'tgt_type': 'glob', 'target': '*'},
|
||||
'users': set(['gareth']),
|
||||
'aliases': {'whoami': {'cmd': 'cmd.run whoami'},
|
||||
'list_pillar': {'cmd': 'pillar.items'}}
|
||||
}}
|
||||
|
||||
slack_user_name = 'gareth'
|
||||
|
||||
# Check for correct cmdline
|
||||
_expected = (True,
|
||||
{u'tgt_type': u'glob', u'target': u'*'},
|
||||
[u'cmd.run', u'whoami'])
|
||||
{'tgt_type': 'glob', 'target': '*'},
|
||||
['cmd.run', 'whoami'])
|
||||
text = '!cmd.run whoami'
|
||||
target_commandline = self.client.control_message_target(slack_user_name,
|
||||
text,
|
||||
|
@ -64,6 +65,7 @@ class EngineSlackTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
self.assertEqual(target_commandline, _expected)
|
||||
|
||||
# Check aliases result in correct cmdline
|
||||
text = '!whoami'
|
||||
target_commandline = self.client.control_message_target(slack_user_name,
|
||||
text,
|
||||
|
@ -72,9 +74,10 @@ class EngineSlackTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
self.assertEqual(target_commandline, _expected)
|
||||
|
||||
# Check pillar is overrided
|
||||
_expected = (True,
|
||||
{u'tgt_type': u'glob', u'target': u'*'},
|
||||
[u'pillar.items', u'pillar={"hello": "world"}'])
|
||||
{'tgt_type': 'glob', 'target': '*'},
|
||||
['pillar.items', 'pillar={"hello": "world"}'])
|
||||
text = r"""!list_pillar pillar='{"hello": "world"}'"""
|
||||
target_commandline = self.client.control_message_target(slack_user_name,
|
||||
text,
|
||||
|
@ -82,3 +85,15 @@ class EngineSlackTestCase(TestCase, LoaderModuleMockMixin):
|
|||
trigger_string)
|
||||
|
||||
self.assertEqual(target_commandline, _expected)
|
||||
|
||||
# Check target is overrided
|
||||
_expected = (True,
|
||||
{'tgt_type': 'glob', 'target': 'localhost'},
|
||||
['cmd.run', 'whoami'])
|
||||
text = "!cmd.run whoami target='localhost'"
|
||||
target_commandline = self.client.control_message_target(slack_user_name,
|
||||
text,
|
||||
loaded_groups,
|
||||
trigger_string)
|
||||
|
||||
self.assertEqual(target_commandline, _expected)
|
||||
|
|
Loading…
Add table
Reference in a new issue