mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #47557 from L4rS6/fix-broken-rabbitmq-list-policies
fix broken rabbitmq list policies in rabbitmq version 3.7
This commit is contained in:
commit
484d83014b
2 changed files with 59 additions and 13 deletions
|
@ -19,6 +19,7 @@ import salt.utils.path
|
|||
import salt.utils.platform
|
||||
import salt.utils.user
|
||||
from salt.exceptions import CommandExecutionError, SaltInvocationError
|
||||
from salt.utils.versions import LooseVersion as _LooseVersion
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
@ -828,24 +829,43 @@ def list_policies(vhost="/", runas=None):
|
|||
python_shell=False)
|
||||
_check_response(res)
|
||||
output = res['stdout']
|
||||
|
||||
if __grains__['os_family'] != 'FreeBSD':
|
||||
version = __salt__['pkg.version']('rabbitmq-server').split('-')[0]
|
||||
else:
|
||||
version = __salt__['pkg.version']('rabbitmq').split('-')[0]
|
||||
|
||||
for line in _output_lines_to_list(output):
|
||||
parts = line.split('\t')
|
||||
|
||||
if len(parts) not in (5, 6):
|
||||
continue
|
||||
|
||||
vhost, name = parts[0], parts[1]
|
||||
if vhost not in ret:
|
||||
ret[vhost] = {}
|
||||
ret[vhost][name] = {}
|
||||
# How many fields are there? - 'apply_to' was inserted in position
|
||||
# 2 at some point
|
||||
offset = len(parts) - 5
|
||||
if len(parts) == 6:
|
||||
ret[vhost][name]['apply_to'] = parts[2]
|
||||
ret[vhost][name].update({
|
||||
'pattern': parts[offset+2],
|
||||
'definition': parts[offset+3],
|
||||
'priority': parts[offset+4]
|
||||
})
|
||||
|
||||
if _LooseVersion(version) >= _LooseVersion("3.7"):
|
||||
# in version 3.7 the position of apply_to and pattern has been
|
||||
# switched
|
||||
ret[vhost][name]['pattern'] = parts[2]
|
||||
ret[vhost][name]['apply_to'] = parts[3]
|
||||
ret[vhost][name]['definition'] = parts[4]
|
||||
ret[vhost][name]['priority'] = parts[5]
|
||||
else:
|
||||
# How many fields are there? - 'apply_to' was inserted in position
|
||||
# 2 at some point
|
||||
# and in version 3.7 the position of apply_to and pattern has been
|
||||
# switched
|
||||
offset = len(parts) - 5
|
||||
if len(parts) == 6:
|
||||
ret[vhost][name]['apply_to'] = parts[2]
|
||||
ret[vhost][name].update({
|
||||
'pattern': parts[offset+2],
|
||||
'definition': parts[offset+3],
|
||||
'priority': parts[offset+4]
|
||||
})
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
@ -378,7 +378,7 @@ class RabbitmqTestCase(TestCase, LoaderModuleMockMixin):
|
|||
self.assertDictEqual(rabbitmq.list_queues_vhost('consumers'), {'saltstack': ['0'],
|
||||
'celeryev.234-234': ['10']})
|
||||
|
||||
# 'list_policies' function tests: 1
|
||||
# 'list_policies' function tests: 3
|
||||
|
||||
def test_list_policies(self):
|
||||
'''
|
||||
|
@ -386,7 +386,31 @@ class RabbitmqTestCase(TestCase, LoaderModuleMockMixin):
|
|||
and name based on the data returned from rabbitmqctl list_policies.
|
||||
'''
|
||||
mock_run = MagicMock(return_value={'retcode': 0, 'stdout': 'saltstack', 'stderr': ''})
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}):
|
||||
mock_pkg = MagicMock(return_value='3.7')
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run, 'pkg.version': mock_pkg}), \
|
||||
patch.dict(rabbitmq.__grains__, {'os_family': ''}):
|
||||
self.assertDictEqual(rabbitmq.list_policies(), {})
|
||||
|
||||
def test_list_policies_freebsd(self):
|
||||
'''
|
||||
Test if it return a dictionary of policies nested by vhost
|
||||
and name based on the data returned from rabbitmqctl list_policies.
|
||||
'''
|
||||
mock_run = MagicMock(return_value={'retcode': 0, 'stdout': 'saltstack', 'stderr': ''})
|
||||
mock_pkg = MagicMock(return_value='3.7')
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run, 'pkg.version': mock_pkg}), \
|
||||
patch.dict(rabbitmq.__grains__, {'os_family': 'FreeBSD'}):
|
||||
self.assertDictEqual(rabbitmq.list_policies(), {})
|
||||
|
||||
def test_list_policies_old_version(self):
|
||||
'''
|
||||
Test if it return a dictionary of policies nested by vhost
|
||||
and name based on the data returned from rabbitmqctl list_policies.
|
||||
'''
|
||||
mock_run = MagicMock(return_value={'retcode': 0, 'stdout': 'saltstack', 'stderr': ''})
|
||||
mock_pkg = MagicMock(return_value='3.0')
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run, 'pkg.version': mock_pkg}), \
|
||||
patch.dict(rabbitmq.__grains__, {'os_family': ''}):
|
||||
self.assertDictEqual(rabbitmq.list_policies(), {})
|
||||
|
||||
# 'set_policy' function tests: 1
|
||||
|
@ -420,7 +444,9 @@ class RabbitmqTestCase(TestCase, LoaderModuleMockMixin):
|
|||
based on rabbitmqctl list_policies.
|
||||
'''
|
||||
mock_run = MagicMock(return_value={'retcode': 0, 'stdout': 'saltstack', 'stderr': ''})
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}):
|
||||
mock_pkg = MagicMock(return_value='3.0')
|
||||
with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run, 'pkg.version': mock_pkg}), \
|
||||
patch.dict(rabbitmq.__grains__, {'os_family': ''}):
|
||||
self.assertFalse(rabbitmq.policy_exists('/', 'HA'))
|
||||
|
||||
# 'list_available_plugins' function tests: 2
|
||||
|
|
Loading…
Add table
Reference in a new issue