Coverage for lib/ansible/plugins/test/core.py : 35%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2012, Jeroen Hoekx <jeroen@hoekx.be> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
''' Test if task result yields failed ''' if not isinstance(result, MutableMapping): raise errors.AnsibleFilterError("The failed test expects a dictionary") return result.get('failed', False)
''' Test if task result yields success ''' return not failed(result)
''' Test if task result yields changed ''' if not isinstance(result, MutableMapping): raise errors.AnsibleFilterError("The changed test expects a dictionary") if 'changed' not in result: changed = False if ( 'results' in result and # some modules return a 'results' key isinstance(result['results'], MutableSequence) and isinstance(result['results'][0], MutableMapping) ): for res in result['results']: if res.get('changed', False): changed = True break else: changed = result.get('changed', False) return changed
''' Test if task result yields skipped ''' if not isinstance(result, MutableMapping): raise errors.AnsibleFilterError("The skipped test expects a dictionary") return result.get('skipped', False)
''' Expose `re` as a boolean filter using the `search` method by default. This is likely only useful for `search` and `match` which already have their own filters. ''' flags |= re.I flags |= re.M
''' Perform a `re.match` returning a boolean '''
''' Perform a `re.search` returning a boolean '''
''' Perform a version comparison on a value ''' op_map = { '==': 'eq', '=': 'eq', 'eq': 'eq', '<': 'lt', 'lt': 'lt', '<=': 'le', 'le': 'le', '>': 'gt', 'gt': 'gt', '>=': 'ge', 'ge': 'ge', '!=': 'ne', '<>': 'ne', 'ne': 'ne' }
if strict: Version = StrictVersion else: Version = LooseVersion
if operator in op_map: operator = op_map[operator] else: raise errors.AnsibleFilterError('Invalid operator type')
try: method = getattr(py_operator, operator) return method(Version(str(value)), Version(str(version))) except Exception as e: raise errors.AnsibleFilterError('Version comparison: %s' % e)
''' Ansible core jinja2 tests '''
# failure testing 'failed': failed, 'failure': failed, 'succeeded': success, 'success': success, 'successful': success,
# changed testing 'changed': changed, 'change': changed,
# skip testing 'skipped': skipped, 'skip': skipped,
# regex 'match': match, 'search': search, 'regex': regex,
# version comparison 'version_compare': version_compare, 'version': version_compare,
# lists 'any': any, 'all': all, } |