various fixes to the consul execution module, in particular a fix to address #29119

This commit is contained in:
Gareth J. Greenaway 2015-11-29 10:03:24 -08:00
parent b225263279
commit 655b0ec403

View File

@ -68,6 +68,10 @@ def _query(function,
base_url = _urljoin(consul_url, '{0}/'.format(api_version))
url = _urljoin(base_url, function, False)
if data is None:
data = {}
data = json.dumps(data)
result = salt.utils.http.query(
url,
method=method,
@ -309,7 +313,7 @@ def put(consul_url=None, key=None, value=None, **kwargs):
ret = _query(consul_url=consul_url,
function=function,
method=method,
data=json.dumps(data),
data=data,
query_params=query_params)
if ret['res']:
@ -695,9 +699,7 @@ def agent_check_register(consul_url=None, **kwargs):
if 'name' in kwargs:
data['Name'] = kwargs['name']
else:
ret['message'] = 'Required parameter "name" is missing.'
ret['res'] = False
return ret
raise SaltInvocationError('Required argument "name" is missing.')
if True not in [True for item in ('script', 'http') if item in kwargs]:
ret['message'] = 'Required parameter "script" or "http" is missing.'
@ -973,6 +975,8 @@ def agent_service_register(consul_url=None, **kwargs):
if 'name' in kwargs:
data['Name'] = kwargs['name']
else:
raise SaltInvocationError('Required argument "name" is missing.')
if 'address' in kwargs:
data['Address'] = kwargs['address']
@ -1031,7 +1035,7 @@ def agent_service_deregister(consul_url=None, serviceid=None):
Used to remove a service.
:param consul_url: The Consul server URL.
:param name: A name describing the service.
:param serviceid: A serviceid describing the service.
:return: Boolean and message indicating success or failure.
CLI Example:
@ -1176,6 +1180,8 @@ def session_create(consul_url=None, **kwargs):
if 'name' in kwargs:
data['Name'] = kwargs['name']
else:
raise SaltInvocationError('Required argument "name" is missing.')
if 'checks' in kwargs:
data['Touch'] = kwargs['touch']
@ -1455,11 +1461,11 @@ def catalog_register(consul_url=None, **kwargs):
if res['res']:
ret['res'] = True
ret['message'] = ('Catalog registration '
'for {0} successful.'.format(kwargs['name']))
'for {0} successful.'.format(kwargs['node']))
else:
ret['res'] = False
ret['message'] = ('Catalog registration '
'for {0} failed.'.format(kwargs['name']))
'for {0} failed.'.format(kwargs['node']))
return ret
@ -1516,11 +1522,11 @@ def catalog_deregister(consul_url=None, **kwargs):
data=data)
if res['res']:
ret['res'] = True
ret['message'] = 'Catalog item {0} removed.'.format(kwargs['name'])
ret['message'] = 'Catalog item {0} removed.'.format(kwargs['node'])
else:
ret['res'] = False
ret['message'] = ('Removing Catalog '
'item {0} failed.'.format(kwargs['name']))
'item {0} failed.'.format(kwargs['node']))
return ret
@ -1980,6 +1986,8 @@ def acl_create(consul_url=None, **kwargs):
if 'name' in kwargs:
data['Name'] = kwargs['name']
else:
raise SaltInvocationError('Required argument "name" is missing.')
if 'type' in kwargs:
data['Type'] = kwargs['type']
@ -2043,6 +2051,8 @@ def acl_update(consul_url=None, **kwargs):
if 'name' in kwargs:
data['Name'] = kwargs['name']
else:
raise SaltInvocationError('Required argument "name" is missing.')
if 'type' in kwargs:
data['Type'] = kwargs['type']
@ -2325,6 +2335,8 @@ def event_list(consul_url=None, **kwargs):
if 'name' in kwargs:
query_params = kwargs['name']
else:
raise SaltInvocationError('Required argument "name" is missing.')
function = 'event/list/'
ret = _query(consul_url=consul_url,