Skip to content

Commit

Permalink
[dhcp_static] Allow use of display name for netif; Error in case a in…
Browse files Browse the repository at this point in the history
…terface group name is specified; Fixes #79
  • Loading branch information
opoplawski committed Dec 18, 2023
1 parent dada6d7 commit b6e8546
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions plugins/modules/pfsense_dhcp_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,13 @@
<domain>acme.com</domain>
</system>
</wizardtemp>
<ifgroups>
<ifgroupentry>
<members>opt1 opt2 opt3</members>
<descr></descr>
<ifname>IFGROUP1</ifname>
</ifgroupentry>
</ifgroups>
<vlans>
<vlan>
<if>vmx0</if>
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/plugins/modules/test_pfsense_dhcp_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.'
Expand Down

0 comments on commit b6e8546

Please sign in to comment.