* Fix #209 ansible.utils filters should raise AnsibleFilterError Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>pull/207/head
parent
462e4e7f71
commit
e3e4f7595d
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- Fix filters to only raise AnsibleFilterError exceptions (https://github.com/ansible-collections/ansible.utils/issues/209).
|
|
@ -10,7 +10,7 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||||
AnsibleArgSpecValidator,
|
AnsibleArgSpecValidator,
|
||||||
|
@ -261,7 +261,7 @@ def _ipaddr(*args, **kwargs):
|
||||||
elif isinstance(data["value"], list):
|
elif isinstance(data["value"], list):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipaddr filter <{1}>".format(
|
"Unrecognized type <{0}> for ipaddr filter <{1}>".format(
|
||||||
type(data["value"]),
|
type(data["value"]),
|
||||||
"value",
|
"value",
|
||||||
|
@ -269,7 +269,7 @@ def _ipaddr(*args, **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipaddr filter <{1}>".format(type(data["value"]), "value"),
|
"Unrecognized type <{0}> for ipaddr filter <{1}>".format(type(data["value"]), "value"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||||
AnsibleArgSpecValidator,
|
AnsibleArgSpecValidator,
|
||||||
|
@ -139,7 +139,7 @@ def _ipv4(*args, **kwargs):
|
||||||
elif isinstance(data["value"], list):
|
elif isinstance(data["value"], list):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipv4 filter <{1}>".format(
|
"Unrecognized type <{0}> for ipv4 filter <{1}>".format(
|
||||||
type(data["value"]),
|
type(data["value"]),
|
||||||
"value",
|
"value",
|
||||||
|
@ -147,7 +147,7 @@ def _ipv4(*args, **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipv4 filter <{1}>".format(type(data["value"]), "value"),
|
"Unrecognized type <{0}> for ipv4 filter <{1}>".format(type(data["value"]), "value"),
|
||||||
)
|
)
|
||||||
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipv4")
|
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipv4")
|
||||||
|
|
|
@ -10,7 +10,7 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||||
AnsibleArgSpecValidator,
|
AnsibleArgSpecValidator,
|
||||||
|
@ -157,7 +157,7 @@ def _ipv6(*args, **kwargs):
|
||||||
elif isinstance(data["value"], list):
|
elif isinstance(data["value"], list):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipv6 filter <{1}>".format(
|
"Unrecognized type <{0}> for ipv6 filter <{1}>".format(
|
||||||
type(data["value"]),
|
type(data["value"]),
|
||||||
"value",
|
"value",
|
||||||
|
@ -165,7 +165,7 @@ def _ipv6(*args, **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipv6 filter <{1}>".format(type(data["value"]), "value"),
|
"Unrecognized type <{0}> for ipv6 filter <{1}>".format(type(data["value"]), "value"),
|
||||||
)
|
)
|
||||||
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipv6")
|
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipv6")
|
||||||
|
|
|
@ -12,7 +12,7 @@ import types
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||||
AnsibleArgSpecValidator,
|
AnsibleArgSpecValidator,
|
||||||
|
@ -160,7 +160,7 @@ def _ipwrap(*args, **kwargs):
|
||||||
elif isinstance(data["value"], bool):
|
elif isinstance(data["value"], bool):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipwrap filter <{1}>".format(
|
"Unrecognized type <{0}> for ipwrap filter <{1}>".format(
|
||||||
type(data["value"]),
|
type(data["value"]),
|
||||||
"value",
|
"value",
|
||||||
|
@ -168,7 +168,7 @@ def _ipwrap(*args, **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
raise AnsibleError(
|
raise AnsibleFilterError(
|
||||||
"Unrecognized type <{0}> for ipwrap filter <{1}>".format(type(data["value"]), "value"),
|
"Unrecognized type <{0}> for ipwrap filter <{1}>".format(type(data["value"]), "value"),
|
||||||
)
|
)
|
||||||
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipwrap")
|
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="ipwrap")
|
||||||
|
|
|
@ -16,9 +16,11 @@ import unittest
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible.errors import AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.template import AnsibleUndefined
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.filter.cidr_merge import cidr_merge
|
from ansible_collections.ansible.utils.plugins.filter.cidr_merge import cidr_merge
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ip4_hex import ip4_hex
|
from ansible_collections.ansible.utils.plugins.filter.ip4_hex import ip4_hex
|
||||||
|
from ansible_collections.ansible.utils.plugins.filter.ipaddr import _ipaddr
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ipmath import ipmath
|
from ansible_collections.ansible.utils.plugins.filter.ipmath import ipmath
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ipsubnet import ipsubnet
|
from ansible_collections.ansible.utils.plugins.filter.ipsubnet import ipsubnet
|
||||||
from ansible_collections.ansible.utils.plugins.filter.network_in_network import network_in_network
|
from ansible_collections.ansible.utils.plugins.filter.network_in_network import network_in_network
|
||||||
|
@ -57,6 +59,15 @@ class TestIpFilter(unittest.TestCase):
|
||||||
self.assertEqual(cidr_merge(subnets), ["1.12.1.1/32", "1.12.1.255/32"])
|
self.assertEqual(cidr_merge(subnets), ["1.12.1.1/32", "1.12.1.255/32"])
|
||||||
self.assertEqual(cidr_merge(subnets, "span"), "1.12.1.0/24")
|
self.assertEqual(cidr_merge(subnets, "span"), "1.12.1.0/24")
|
||||||
|
|
||||||
|
def test_ipaddr_undefined_value(self):
|
||||||
|
"""Check ipaddr filter undefined value"""
|
||||||
|
args = ["", AnsibleUndefined(name="my_ip"), ""]
|
||||||
|
with pytest.raises(
|
||||||
|
AnsibleFilterError,
|
||||||
|
match="Unrecognized type <<class 'ansible.template.AnsibleUndefined'>> for ipaddr filter <value>",
|
||||||
|
):
|
||||||
|
_ipaddr(*args)
|
||||||
|
|
||||||
def test_ipaddr_empty_query(self):
|
def test_ipaddr_empty_query(self):
|
||||||
self.assertEqual(ipaddr("192.0.2.230"), "192.0.2.230")
|
self.assertEqual(ipaddr("192.0.2.230"), "192.0.2.230")
|
||||||
self.assertEqual(ipaddr("192.0.2.230/30"), "192.0.2.230/30")
|
self.assertEqual(ipaddr("192.0.2.230/30"), "192.0.2.230/30")
|
||||||
|
|
|
@ -14,6 +14,11 @@ __metaclass__ = type
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.template import AnsibleUndefined
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ipv4 import _ipv4
|
from ansible_collections.ansible.utils.plugins.filter.ipv4 import _ipv4
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +45,15 @@ class TestIp4(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_ipv4_undefined_value(self):
|
||||||
|
"""Check ipv4 filter undefined value"""
|
||||||
|
args = ["", AnsibleUndefined(name="my_ip"), ""]
|
||||||
|
with pytest.raises(
|
||||||
|
AnsibleFilterError,
|
||||||
|
match="Unrecognized type <<class 'ansible.template.AnsibleUndefined'>> for ipv4 filter <value>",
|
||||||
|
):
|
||||||
|
_ipv4(*args)
|
||||||
|
|
||||||
def test_ipv4_filter_empty_query(self):
|
def test_ipv4_filter_empty_query(self):
|
||||||
"""Check ipv4 filter empty query"""
|
"""Check ipv4 filter empty query"""
|
||||||
args = ["", VALID_DATA, ""]
|
args = ["", VALID_DATA, ""]
|
||||||
|
|
|
@ -14,6 +14,11 @@ __metaclass__ = type
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.template import AnsibleUndefined
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ipv6 import _ipv6
|
from ansible_collections.ansible.utils.plugins.filter.ipv6 import _ipv6
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +48,15 @@ class TestIp6(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_ipv6_undefined_value(self):
|
||||||
|
"""Check ipv6 filter undefined value"""
|
||||||
|
args = ["", AnsibleUndefined(name="my_ip"), ""]
|
||||||
|
with pytest.raises(
|
||||||
|
AnsibleFilterError,
|
||||||
|
match="Unrecognized type <<class 'ansible.template.AnsibleUndefined'>> for ipv6 filter <value>",
|
||||||
|
):
|
||||||
|
_ipv6(*args)
|
||||||
|
|
||||||
def test_ipv6_filter_empty_query(self):
|
def test_ipv6_filter_empty_query(self):
|
||||||
"""Check ipv6 filter empty query"""
|
"""Check ipv6 filter empty query"""
|
||||||
args = ["", VALID_DATA, ""]
|
args = ["", VALID_DATA, ""]
|
||||||
|
|
|
@ -14,6 +14,11 @@ __metaclass__ = type
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.template import AnsibleUndefined
|
||||||
|
|
||||||
from ansible_collections.ansible.utils.plugins.filter.ipwrap import _ipwrap
|
from ansible_collections.ansible.utils.plugins.filter.ipwrap import _ipwrap
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +50,15 @@ class TestIpWrap(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_ipwrap_undefined_value(self):
|
||||||
|
"""Check ipwrap filter undefined value"""
|
||||||
|
args = ["", AnsibleUndefined(name="my_ip"), ""]
|
||||||
|
with pytest.raises(
|
||||||
|
AnsibleFilterError,
|
||||||
|
match="Unrecognized type <<class 'ansible.template.AnsibleUndefined'>> for ipwrap filter <value>",
|
||||||
|
):
|
||||||
|
_ipwrap(*args)
|
||||||
|
|
||||||
def test_valid_data_list(self):
|
def test_valid_data_list(self):
|
||||||
"""Check passing valid argspec(list)"""
|
"""Check passing valid argspec(list)"""
|
||||||
args = ["", VALID_DATA, ""]
|
args = ["", VALID_DATA, ""]
|
||||||
|
|
Loading…
Reference in New Issue