Issue #39860: Add 'not_contains' method to parsing.py (#39874)

* Issue #39860: Add 'not_contains' method to parsing.py

* Issue #30860 Adds self.negate to Conditional class in lib/ansible/module_utils/network/common/parsing.py

* Issue #39860 Fix singleton-comparison issue per sanity tests

* Issue #39860 'test/integration/targets/nxos_command/tests/cli/not_comparison_operator.yaml' integration test

* Issue #39860 Add unit tests to '../../test/units/module_utils/network/common/test_parsing.py'

* Issue #39860 Fix singleton comparison issue

* Fix E302 expected 2 blank lines, found 1

* Issue #39860 Add license header to unit tests

* Issue #39860 Move integration test to 'test/integration/targets/nxos_command/tests/common/'; remove unnecessary comment from unit test

* Issue #39860 remove unnecessary comment from unit test
This commit is contained in:
Eitan Akman 2018-06-27 00:51:17 -04:00 committed by Trishna Guha
parent 77526a5036
commit fb7882bf86
3 changed files with 76 additions and 3 deletions

View file

@ -205,9 +205,16 @@ class Conditional(object):
def __init__(self, conditional, encoding=None):
self.raw = conditional
self.negate = False
try:
key, op, val = shlex.split(conditional)
components = shlex.split(conditional)
key, val = components[0], components[-1]
op_components = components[1:-1]
if 'not' in op_components:
self.negate = True
op_components.pop(op_components.index('not'))
op = op_components[0]
except ValueError:
raise ValueError('failed to parse conditional')
@ -217,7 +224,10 @@ class Conditional(object):
def __call__(self, data):
value = self.get_value(dict(result=data))
return self.func(value)
if not self.negate:
return self.func(value)
else:
return not self.func(value)
def _cast_value(self, value):
if value in BOOLEANS_TRUE: