From b6e8546cbbbf6c10a9b42d7bb2c3b5415c9b0a05 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Sun, 30 Jul 2023 17:48:44 -0600 Subject: [PATCH] [dhcp_static] Allow use of display name for netif; Error in case a interface group name is specified; Fixes #79 --- plugins/modules/pfsense_dhcp_static.py | 9 +++++++-- .../modules/fixtures/pfsense_dhcp_static_config.xml | 7 +++++++ .../plugins/modules/test_pfsense_dhcp_static.py | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/modules/pfsense_dhcp_static.py b/plugins/modules/pfsense_dhcp_static.py index eb1e435f..db58a81f 100644 --- a/plugins/modules/pfsense_dhcp_static.py +++ b/plugins/modules/pfsense_dhcp_static.py @@ -223,10 +223,15 @@ def _validate_params(self): self.module.fail_json(msg='A valid MAC address must be specified.') if params['netif'] is not None: - self.pfsense.parse_interface(params['netif']) + if self.pfsense.is_interface_group(params['netif']): + self.module.fail_json(msg='DHCP cannot be configured for interface groups') + else: + netif = self.pfsense.parse_interface(params['netif']) + else: + netif = None # find staticmaps and determine interface - self._find_staticmaps(params['netif']) + self._find_staticmaps(netif) if params['ipaddr'] is not None: addr = ip_address(u'{0}'.format(params['ipaddr'])) diff --git a/tests/unit/plugins/modules/fixtures/pfsense_dhcp_static_config.xml b/tests/unit/plugins/modules/fixtures/pfsense_dhcp_static_config.xml index b2589ca5..ed5eabfa 100644 --- a/tests/unit/plugins/modules/fixtures/pfsense_dhcp_static_config.xml +++ b/tests/unit/plugins/modules/fixtures/pfsense_dhcp_static_config.xml @@ -1741,6 +1741,13 @@ acme.com + + + opt1 opt2 opt3 + + IFGROUP1 + + vmx0 diff --git a/tests/unit/plugins/modules/test_pfsense_dhcp_static.py b/tests/unit/plugins/modules/test_pfsense_dhcp_static.py index fb6059c5..3563c01e 100644 --- a/tests/unit/plugins/modules/test_pfsense_dhcp_static.py +++ b/tests/unit/plugins/modules/test_pfsense_dhcp_static.py @@ -86,6 +86,14 @@ def test_dhcp_static_create_empty(self): ) self.do_module_test(obj, command=command) + def test_dhcp_static_create_display(self): + """ test create with netif display name """ + obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:ac', ipaddr='10.0.0.101', netif='pub') + command = ( + "create dhcp_static 'test_entry', macaddr='ab:ab:ab:ab:ab:ac', ipaddr='10.0.0.101'" + ) + self.do_module_test(obj, command=command) + def test_dhcp_static_create_wrong_subnet(self): """ test create with IP address in the wrong subnet """ obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:ab', ipaddr='1.2.3.4', netif='opt1') @@ -96,6 +104,11 @@ def test_dhcp_static_create_no_netif(self): obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:ab', ipaddr='1.2.3.4') self.do_module_test(obj, failed=True, msg='Multiple DHCP servers enabled and no netif specified') + def test_dhcp_static_create_ifgroup(self): + """ test create with interface group """ + obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:ab', ipaddr='1.2.3.4', netif='IFGROUP1') + self.do_module_test(obj, failed=True, msg='DHCP cannot be configured for interface groups') + def test_dhcp_static_create_invalid_macaddr(self): """ test create with invalid macaddr """ msg = 'A valid MAC address must be specified.'