diff options
5 files changed, 18 insertions, 7 deletions
diff --git a/changelogs/fragments/T7284-delete_firewall_description.yml b/changelogs/fragments/T7284-delete_firewall_description.yml new file mode 100644 index 00000000..fe2b1882 --- /dev/null +++ b/changelogs/fragments/T7284-delete_firewall_description.yml @@ -0,0 +1,2 @@ +bugfixes: + - vyos_firewall_rules - Allow deleting of firewall description. diff --git a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py index 34dc0ed6..e2a25e32 100644 --- a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py +++ b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py @@ -29,6 +29,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.u from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( list_diff_want_only, + in_target_not_none, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version @@ -374,11 +375,7 @@ class Firewall_global(ConfigBase): if key == "name" and self._is_grp_del(h, want, key): commands.append(cmd + " " + want["name"]) continue - if not (h and self._in_target(h, key)) and not self._is_grp_del( - h, - want, - key, - ): + if not (h and in_target_not_none(h, key)) and not self._is_grp_del(h, want, "name"): commands.append(cmd + " " + want["name"] + " " + key) elif key == "members": commands.extend( diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py index a6b03c80..4c371962 100644 --- a/plugins/module_utils/network/vyos/utils/utils.py +++ b/plugins/module_utils/network/vyos/utils/utils.py @@ -276,3 +276,13 @@ def _in_target(h, key): :return: True/False. """ return True if h and key in h else False + + +def in_target_not_none(h, key): + """ + This function checks whether the target exist,key present in target config, and the value is not None. + :param h: target config. + :param key: attribute name. + :return: True/False. + """ + return True if h and key in h and h[key] is not None else False diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_global.py b/tests/unit/modules/network/vyos/test_vyos_firewall_global.py index 2ecd0621..481cc1dd 100644 --- a/tests/unit/modules/network/vyos/test_vyos_firewall_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_firewall_global.py @@ -282,7 +282,7 @@ class TestVyosFirewallGlobalModule(TestVyosModule): dict( afi="ipv4", name="RND", - description="This group has the Management network addresses", + # Deleted the description here. members=[dict(address="192.0.2.0/24")], ), dict( @@ -311,6 +311,7 @@ class TestVyosFirewallGlobalModule(TestVyosModule): "delete firewall group address-group RND-HOSTS address 192.0.2.5", "set firewall group address-group RND-HOSTS address 192.0.2.7", "set firewall group address-group RND-HOSTS address 192.0.2.9", + "delete firewall group network-group RND description", "delete firewall group ipv6-address-group LOCAL-v6 address fdec:2503:89d6:59b3::1", "set firewall group ipv6-address-group LOCAL-v6 address fdec:2503:89d6:59b3::2", "delete firewall group port-group SSH port 22", diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_global14.py b/tests/unit/modules/network/vyos/test_vyos_firewall_global14.py index f4ae4add..aae4aa83 100644 --- a/tests/unit/modules/network/vyos/test_vyos_firewall_global14.py +++ b/tests/unit/modules/network/vyos/test_vyos_firewall_global14.py @@ -285,7 +285,7 @@ class TestVyosFirewallRulesModule14(TestVyosModule): dict( afi="ipv4", name="RND", - description="This group has the Management network addresses", + # Deleted the description here. members=[dict(address="192.0.2.0/24")], ), dict( @@ -317,6 +317,7 @@ class TestVyosFirewallRulesModule14(TestVyosModule): "set firewall global-options state-policy invalid action 'reject'", "set firewall group address-group RND-HOSTS address 192.0.2.7", "set firewall group address-group RND-HOSTS address 192.0.2.9", + "delete firewall group network-group RND description", "delete firewall group ipv6-address-group LOCAL-v6 address fdec:2503:89d6:59b3::1", "set firewall group ipv6-address-group LOCAL-v6 address fdec:2503:89d6:59b3::2", "delete firewall group port-group SSH port 22", |