Bug 1759160

Summary: [RFE] Rake task for cleaning up DHCP records on proxy
Product: Red Hat Satellite Reporter: Lukas Zapletal <lzap>
Component: DHCP & DNSAssignee: Lukas Zapletal <lzap>
Status: CLOSED ERRATA QA Contact: Radovan Drazny <rdrazny>
Severity: medium Docs Contact:
Priority: unspecified    
Version: UnspecifiedCC: aruzicka, bkearney, egolov, ktordeur, mshira, vsedmik
Target Milestone: 6.8.0Keywords: FutureFeature, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: foreman-2.1.0-0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-10-27 12:59:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Lukas Zapletal 2019-10-07 14:09:02 UTC
A task that allows cleanup of DHCP subnets.

foreman-rake orchestration:dhcp:cleanup

QA: Create a host without Subnet - DHCP Capsule. Then assign Subnet - DHCP Capsule and run cleanup. And vice versa.

Comment 3 Bryan Kearney 2020-04-01 16:02:38 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/27975 has been resolved.

Comment 4 Radovan Drazny 2020-09-23 11:37:29 UTC
Tested on Satellite 6.8 Snap 16 using following scenarios:

Scenario A) Add missing DHCP records

1. Enable DHCP proxy on a Satellite server.
2. Create a managed network
3. Define and provision a host connected to the managed network, assign an IPv4 address to it, and let the host acquire the address from DHCP. 
4. Manually edit /var/lib/dhcpd/dhcpd.leases file, find the record of the host created in the step 3, and remove it.
5. Restart dhcpd service
6. Run "foreman-rake orchestration:dhcp:add_missing subnet_name=<networkname> perform=1"

The record deleted in the step 4 will be recreated in dhcpd.leases file, with messages in production.log similar to this:

2020-09-23T06:58:13 [W|app|] Host julie-magill.example.com needs config rebuild
2020-09-23T06:58:13 [I|app|] Delete DHCP reservation julie-magill.example.com for julie-magill.example.com-56:6f:0d:72:00:61/
2020-09-23T06:58:14 [I|app|] Create DHCP reservation julie-magill.example.com for julie-magill.example.com-56:6f:0d:72:00:61/

Scenario B)
1. Edit manually /var/lib/dhcpd/dhcpd.leases file and add a bogus DHCP record.
2. Restart dhcpd service
3. Run "foreman-rake orchestration:dhcp:remove_offending subnet_name=<networkname> perform=1"

The bogus record created in step 1 will get removed, with messages in production.log similar to this:

2020-09-23T07:08:16 [W|app|] DHCP record mess.example.com-56:6f:0d:72:00:65/ not found in DB, deleting
2020-09-23T07:08:16 [I|app|] DHCP record julie-magill.example.com-56:6f:0d:72:00:61/ is up-to-date
2020-09-23T07:08:16 [I|app|] DHCP record shana-cloud.example.com-52:54:00:96:45:81/ is up-to-date

Dropping "perform=1" from commands enables dry-run with messages present in the production.log, but not doing any changes to dhcpd.leases.

Comment 7 errata-xmlrpc 2020-10-27 12:59:02 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.8 release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.