fix: fall back to lease file when DHCPLeases API is empty#190
Open
ajmeese7 wants to merge 6 commits intofog:masterfrom
Open
fix: fall back to lease file when DHCPLeases API is empty#190ajmeese7 wants to merge 6 commits intofog:masterfrom
ajmeese7 wants to merge 6 commits intofog:masterfrom
Conversation
The libvirt DHCPLeases API returns no results when the network was defined without a <dhcp> block, even if an external dnsmasq is serving DHCP on the bridge. This occurs on WSL2 with mirrored networking where port 67 is held by Windows ICS, forcing dnsmasq to run in an isolated network namespace outside libvirt's control. Add ip_address_from_leasefile() as a fallback in addresses() that reads the dnsmasq lease file directly, matching by MAC and picking the lease with the latest expiry — mirroring the existing dhcp_leases logic.
- Extract lease directory to DNSMASQ_LEASE_DIR constant - Remove bare rescue on net.name (fog attribute won't raise) - Handle Errno::EACCES/ENOENT during lease file reads - Log warning when falling back to dnsmasq lease file - Remove unused DOMAIN_CLEANUP_REGEXP constant - Add minitest suite for ip_address_from_leasefile
The addresses() method is polled in a tight loop while waiting for a VM to get an IP. The warning fired on every call, flooding logs with dozens of identical lines.
The Tempfile object was immediately discarded after calling .path, making it eligible for garbage collection. When GC finalized the object, the underlying ISO file was deleted before File.size could read it, causing flaky ENOENT failures in CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DHCPLeasesAPI returns empty and the VM's IP address can't be discovered. This adds a fallback that reads the dnsmasq lease file directly from/var/lib/libvirt/dnsmasq/<network>.leases.Changes
lib/fog/libvirt/models/compute/server.rbip_address_from_leasefile(net, mac)private method parses dnsmasq lease files, matches by MAC, returns IP with latest expiryaddresses()calls the fallback whendhcp_leasesreturns nil and a network existsDNSMASQ_LEASE_DIRconstant for the lease file directoryFog::Logger.warningwhen the fallback path is entered (emitted only once per MAC)Errno::EACCES/Errno::ENOENTrescue around file readsDOMAIN_CLEANUP_REGEXPconstantTempfilereference ingenerate_config_iso_in_dirto prevent GC from deleting the ISO file beforeFile.sizereads it (fixes flaky CIENOENTfailure)minitests/server/leasefile_fallback_test.rb— 8 test cases covering happy path, expiry selection, case-insensitive MAC, missing file, malformed lines, no match, permission error, and nil network nameTest plan
bundle exec rake minitestpassespublic_ip_addressbehavior is unchanged when libvirt DHCP is active (bundle exec rake test)