Trying to remove a DHCP record fails due to an invalid subnet check
Take three hosts, add them into foreman via API. Then try and remove them. The first deletes fine, but the subsequent deletions fail. The problem is in file , line 196. When the subnet gets searched, the 1st host is not found, and then the entire subnet array is returned to the delete function, which then throws an error.
Pull request coming.
#1 Updated by Dominic Cleal about 5 years ago
- Category set to DHCP
- Status changed from New to Ready For Testing
- Assignee set to David Swift
- Target version set to 1.8.1
#2 Updated by David Swift about 5 years ago
Copying the description I just wrote into github, as it explains this behavior better:
A small correction - if it fails to find the DHCP record of a deleted host in the subnet under evaluation, it will not attempt to delete it from the subnet under evaluation. This allows it to carry on, and actually delete the record that is intended.
The problem arises due to the evaluation of DHCP records with a status of 'deleted'. These records are evaluated against the subnet that contains the actual host we want to delete, and if they are found, they are removed prior to executing the target deletion.
In the case that triggered this bug, the record with the DHCP deleted status was originally in a different subnet before it was removed. On a subsequent delete run for a second host, the previously deleted host could not be found in the subnet under evaluation, and line 198 never returned a value. This left the return value of find_record_by_hostname as the result of subnet.records.each (an array), which then caused the subnet.delete call to throw an error.
A better fix might be to track the subnets of hosts with a DHCP status of deleted, but this gets the job done without added complexity.
#7 Updated by Anonymous about 5 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset smart-proxy:57ea7e82f68395c61ab0515ea331423c9f4ac5ea.