From 14a0ed585fb3ef2f4a62ec0895b312b515f64200 Mon Sep 17 00:00:00 2001 From: Weird Voodoo <109062285+WeirdVoodoo-418@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:51:56 +0300 Subject: [PATCH 1/2] [pfsense_rule] Add support for floating 'any' interface rule --- plugins/module_utils/rule.py | 5 ++++- plugins/modules/pfsense_rule.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/rule.py b/plugins/module_utils/rule.py index 54d5a6d0..25ace9ea 100644 --- a/plugins/module_utils/rule.py +++ b/plugins/module_utils/rule.py @@ -154,7 +154,10 @@ def _parse_floating_interfaces(self, interfaces): """ validate param interface field when floating is true """ res = [] for interface in interfaces.split(','): - res.append(self.pfsense.parse_interface(interface)) + if interface == 'any': + res.append(interface) + else: + res.append(self.pfsense.parse_interface(interface)) self._floating_interfaces = interfaces return ','.join(res) diff --git a/plugins/modules/pfsense_rule.py b/plugins/modules/pfsense_rule.py index 749358ef..0c22db1e 100644 --- a/plugins/modules/pfsense_rule.py +++ b/plugins/modules/pfsense_rule.py @@ -42,7 +42,7 @@ default: false type: bool interface: - description: The interface for the rule + description: The interface for the rule. Use 'any' to apply to all interface (for floating rules only). required: true type: str floating: From 7fd8a76afeca7b66d13b1c8d0d949f844aee1696 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Mon, 18 Dec 2023 20:01:05 -0700 Subject: [PATCH 2/2] [pfsense_rule] Add tests for interface='any' --- .../unit/plugins/modules/test_pfsense_rule_create.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/plugins/modules/test_pfsense_rule_create.py b/tests/unit/plugins/modules/test_pfsense_rule_create.py index 3855a37a..fd2fa61d 100644 --- a/tests/unit/plugins/modules/test_pfsense_rule_create.py +++ b/tests/unit/plugins/modules/test_pfsense_rule_create.py @@ -66,6 +66,17 @@ def test_rule_create_floating(self): command = "create rule 'one_rule' on 'floating(lan)', source='any', destination='any', direction='any'" self.do_module_test(obj, command=command) + def test_rule_create_floating_any(self): + """ test creation of a new floating rule with any interface """ + obj = dict(name='one_rule', source='any', destination='any', interface='any', floating='yes', direction='any') + command = "create rule 'one_rule' on 'floating(any)', source='any', destination='any', direction='any'" + + def test_rule_create_non_floating_any(self): + """ test creation of a new rule with any interface """ + obj = dict(name='one_rule', source='any', destination='any', interface='any', floating='no', direction='any') + msg = "any is not a valid interface" + self.do_module_test(obj, failed=True, msg=msg) + def test_rule_create_floating_quick(self): """ test creation of a new floating rule with quick match """ obj = dict(name='one_rule', source='any', destination='any', interface='lan', floating='yes', direction='any', quick='yes')