Skip to content

Commit

Permalink
[dhcp_static] Allow removing entry with just name, fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
opoplawski committed Dec 18, 2023
1 parent 768d5f6 commit 322b53d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/modules/pfsense_dhcp_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _validate_params(self):

params = self.params

if re.fullmatch(r'(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}', params['macaddr']) is None:
if params['macaddr'] is not None and re.fullmatch(r'(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}', params['macaddr']) is None:
self.module.fail_json(msg='A valid MAC address must be specified.')

if params['netif'] is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@
<numberoptions></numberoptions>
<staticmap>
<mac>ab:ab:ab:ab:ab:ab</mac>
<cid></cid>
<cid>dhcphostid</cid>
<ipaddr>10.0.0.100</ipaddr>
<hostname></hostname>
<hostname>dhcphostname</hostname>
<descr></descr>
<filename></filename>
<rootpath></rootpath>
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/plugins/modules/test_pfsense_dhcp_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ def test_dhcp_static_create_invalid_macaddr(self):
obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:hh', ipaddr='10.10.0.101', netif='opt2')
self.do_module_test(obj, failed=True, msg=msg)

def test_dhcp_static_delete(self):
def test_dhcp_static_delete_macaddr(self):
""" test """
obj = dict(macaddr='ab:ab:ab:ab:ab:ab', netif='opt1', state='absent')
command = "delete dhcp_static ''"

def test_dhcp_static_delete_name(self):
""" test """
obj = dict(name='dhcphostid', netif='opt1', state='absent')
command = "delete dhcp_static 'dhcphostid'"
self.do_module_test(obj, command=command, delete=True)

0 comments on commit 322b53d

Please sign in to comment.