Skip to content

Commit 7f8612a

Browse files
committed
[dhcp_static] Allow removing entry with just name, fixes #69
1 parent 768d5f6 commit 7f8612a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

plugins/modules/pfsense_dhcp_static.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _validate_params(self):
223223

224224
params = self.params
225225

226-
if re.fullmatch(r'(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}', params['macaddr']) is None:
226+
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:
227227
self.module.fail_json(msg='A valid MAC address must be specified.')
228228

229229
if params['netif'] is not None:

tests/unit/plugins/modules/fixtures/pfsense_dhcp_static_config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@
211211
<numberoptions></numberoptions>
212212
<staticmap>
213213
<mac>ab:ab:ab:ab:ab:ab</mac>
214-
<cid></cid>
214+
<cid>dhcphostid</cid>
215215
<ipaddr>10.0.0.100</ipaddr>
216-
<hostname></hostname>
216+
<hostname>dhcphostname</hostname>
217217
<descr></descr>
218218
<filename></filename>
219219
<rootpath></rootpath>

tests/unit/plugins/modules/test_pfsense_dhcp_static.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ def test_dhcp_static_create_invalid_macaddr(self):
120120
obj = dict(name='test_entry', macaddr='ab:ab:ab:ab:ab:hh', ipaddr='10.10.0.101', netif='opt2')
121121
self.do_module_test(obj, failed=True, msg=msg)
122122

123-
def test_dhcp_static_delete(self):
123+
def test_dhcp_static_delete_macaddr(self):
124124
""" test """
125125
obj = dict(macaddr='ab:ab:ab:ab:ab:ab', netif='opt1', state='absent')
126126
command = "delete dhcp_static ''"
127+
128+
def test_dhcp_static_delete_name(self):
129+
""" test """
130+
obj = dict(name='dhcphostid', netif='opt1', state='absent')
131+
command = "delete dhcp_static 'dhcphostid'"
127132
self.do_module_test(obj, command=command, delete=True)

0 commit comments

Comments
 (0)