mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Account for possibly missing data structures
This commit is contained in:
parent
ae6c6a0dbe
commit
8ac080e791
@ -40,31 +40,31 @@ def query(name, match=None, match_type='string', status=None, **kwargs):
|
||||
if __opts__['test']:
|
||||
kwargs['test'] = True
|
||||
|
||||
data = __salt__['http.query'](**kwargs)
|
||||
data = __salt__['http.query'](name, **kwargs)
|
||||
|
||||
if match is not None:
|
||||
if match_type == 'string':
|
||||
if match in data['text']:
|
||||
if match in data.get('text', ''):
|
||||
ret['result'] = True
|
||||
ret['comment'] += ' Match text "{0}" was found'.format(match)
|
||||
ret['comment'] += ' Match text "{0}" was found.'.format(match)
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] += ' Match text "{0}" was not found'.format(match)
|
||||
ret['comment'] += ' Match text "{0}" was not found.'.format(match)
|
||||
elif match_type == 'pcre':
|
||||
if re.search(match, data['text']):
|
||||
ret['result'] = True
|
||||
ret['comment'] += ' Match pattern "{0}" was found'.format(match)
|
||||
ret['comment'] += ' Match pattern "{0}" was found.'.format(match)
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] += ' Match pattern "{0}" was not found'.format(match)
|
||||
ret['comment'] += ' Match pattern "{0}" was not found.'.format(match)
|
||||
|
||||
if status is not None:
|
||||
if data['status'] == status:
|
||||
ret['comment'] += 'Status {0} was found, as specified'.format(status)
|
||||
if data.get('status', '') == status:
|
||||
ret['comment'] += 'Status {0} was found, as specified.'.format(status)
|
||||
if ret['result'] is None:
|
||||
ret['result'] = True
|
||||
else:
|
||||
ret['comment'] += 'Status {0} was not found, as specified'.format(status)
|
||||
ret['comment'] += 'Status {0} was not found, as specified.'.format(status)
|
||||
ret['result'] = False
|
||||
|
||||
if __opts__['test'] and ret['result'] is True:
|
||||
|
Loading…
Reference in New Issue
Block a user