Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwini Mhatre committed Nov 10, 2023
1 parent ea27ed6 commit b914321
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
75 changes: 38 additions & 37 deletions plugins/filter/fact_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,50 @@
DOCUMENTATION = """
name: fact_diff
author: Ashwini Mhatre ((@amhatre))
version_added: "2.12.0"
version_added: 2.12.0
short_description: Find the difference between currently set facts
description:
- Compare two facts or variables and get a diff.
- Compare two facts or variables and get a diff.
options:
before:
before:
description:
- The first fact to be used in the comparison.
type: raw
required: true
after:
description:
- The second fact to be used in the comparison.
type: raw
required: true
plugin:
description:
- Configure and specify the diff plugin to use
type: dict
default: {}
suboptions:
name:
description:
- The first fact to be used in the comparison.
type: raw
required: True
after:
- 'The diff plugin to use, in fully qualified collection name format.'
default: ansible.utils.native
type: str
vars:
description:
- The second fact to be used in the comparison.
type: raw
required: True
plugin:
description:
- Configure and specify the diff plugin to use
- Parameters passed to the diff plugin.
type: dict
default: {}
suboptions:
name:
description:
- The diff plugin to use, in fully qualified collection name format.
default: ansible.utils.native
type: str
vars:
description:
- Parameters passed to the diff plugin.
type: dict
default: {}
suboptions:
skip_lines:
description:
- Skip lines matching these regular expressions.
- Matches will be removed prior to the diff.
- If the provided I(before) and I(after) are a string, they will be split.
- Each entry in each list will be cast to a string for the comparison
type: list
elements: str
notes:
skip_lines:
description:
- Skip lines matching these regular expressions.
- Matches will be removed prior to the diff.
- >-
If the provided I(before) and I(after) are a string, they will
be split.
- >-
Each entry in each list will be cast to a string for the
comparison
type: list
elements: str
"""

EXAMPLES = """
Expand Down Expand Up @@ -164,6 +167,7 @@
- Returns diff between before and after facts.
"""
from ansible.errors import AnsibleFilterError
from ansible.module_utils._text import to_text

from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
AnsibleArgSpecValidator,
Expand All @@ -189,10 +193,7 @@ def _fact_diff(*args, **kwargs):
if not valid:
raise AnsibleFilterError(errors)
res = fact_diff(**updated_data)
import json

res = str(res)
return res
return to_text(res)


class FilterModule(object):
Expand Down
3 changes: 1 addition & 2 deletions plugins/filter/next_nth_usable.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def next_nth_usable(value, offset):
v = netaddr.IPNetwork(v)
except Exception:
return False

if isinstance(offset) is not int:
if not isinstance(offset, int):
raise AnsibleFilterError("Must pass in an integer")
if v.size > 1:
first_usable, last_usable = _first_last(v)
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/previous_nth_usable.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def previous_nth_usable(value, offset):
except Exception:
return False

if isinstance(offset) is not int:
if not isinstance(offset, int):
raise AnsibleFilterError("Must pass in an integer")
if v.size > 1:
first_usable, last_usable = _first_last(v)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mock/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class DictDataLoader(DataLoader):
def __init__(self, file_mapping=None):
file_mapping = {} if file_mapping is None else file_mapping
assert isinstance(file_mapping) is dict
assert isinstance(file_mapping, dict)

super(DictDataLoader, self).__init__()

Expand Down

0 comments on commit b914321

Please sign in to comment.