Merge pull request #35232 from theredcat/fix-rabbitmq-version-detection

fix rabbitmq version detection using a package-agnostic version
This commit is contained in:
Mike Place 2016-08-06 17:13:01 +09:00 committed by GitHub
commit 7302a8a6e5

View file

@ -8,6 +8,7 @@ from __future__ import absolute_import
# Import python libs
import json
import re
import logging
import random
import string
@ -306,16 +307,24 @@ def check_password(name, password, runas=None):
salt '*' rabbitmq.check_password rabbit_user password
'''
# try to get the rabbitmq-version - adapted from _get_rabbitmq_plugin
if runas is None:
runas = salt.utils.get_user()
try:
version = [int(i) for i in __salt__['pkg.version']('rabbitmq-server').split('-')[0].split('.')]
res = __salt__['cmd.run'](['rabbitmqctl', 'status'], runas=runas, python_shell=False)
server_version = re.search(r'\{rabbit,"RabbitMQ","(.+)"\}',res)
if server_version is None:
raise ValueError("")
server_version = server_version.group(1)
version = [int(i) for i in server_version.split('.')]
except ValueError:
version = (0, 0, 0)
if len(version) < 3:
version = (0, 0, 0)
if runas is None:
runas = salt.utils.get_user()
# rabbitmq introduced a native api to check a username and password in version 3.5.7.
if tuple(version) >= (3, 5, 7):
res = __salt__['cmd.run'](
@ -323,8 +332,8 @@ def check_password(name, password, runas=None):
runas=runas,
output_loglevel='quiet',
python_shell=False)
msg = 'password-check'
return _format_response(res, msg)
return not 'Error:' in res
cmd = ('rabbit_auth_backend_internal:check_user_login'
'(<<"{0}">>, [{{password, <<"{1}">>}}]).').format(