-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
T6948: Keep DHCP server leases in sync with hostd records #4237
base: current
Are you sure you want to change the base?
Conversation
👍 |
Keeping it as draft till I have a working test environment. |
5e444ca
to
748310c
Compare
748310c
to
d1a8438
Compare
Update: Ready for review. |
d1a8438
to
e8d7cc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for adding the smoketest.
e8d7cc3
to
5d094e9
Compare
@@ -5,3 +5,5 @@ After=vyos-router.service | |||
[Service] | |||
ExecStart= | |||
ExecStart=/usr/sbin/kea-dhcp4 -c /run/kea/kea-dhcp4.conf | |||
ExecStartPost=!/usr/bin/python3 /usr/libexec/vyos/op_mode/dhcp.py update_dhcp_server_lease_to_hostd_state --family inet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @sarthurdev! I need some feedback on the convention of invoking this one.
So far I haven't seen any precedence of invoking op_mode/*.py
directly in the codebase. Is this okay, or do you want me to revisit this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not the ideal solution, as I don't see a use case where it'd be needed in op-mode, nor is it defined in XML.
Probably best done in a script in src/system
like the Kea hook scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I asked :)
As you can see in the implementation of update_dhcp_server_lease_to_hostd_state
, the method crucially depends on _get_dhcp_pools
and _get_raw_server_leases
which are implemented in op_mode/dhcp.py
which is why I added the method in update_dhcp_server_lease_to_hostd_state
. Could they be refactored to kea lib (python/vyos/kea.py
) perhaps so that they can be reused?
Or what if we actually add an op-mode command - something like update hostd state
and define it in XML as well?
NB: I realize that we are getting into design discussion here. We can discuss the options on Slack if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally there shouldn't be a scenario where the user needs to manually re-sync hostd state.
I agree that the utility functions could move to the vyos.kea
module and be imported in op-mode and a new src/system script. Though for the module function, it should probably be just the logic that needs to be re-used (no sorting, filtering etc. Just returning the lease data as-is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarthurdev, raised #4307 to refactor utility functions to vyos.kea
. Would appreciate feedback on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that #4307 has been applied, I have made the necessary changes to better comply with the recommended convention.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
5d094e9
to
462f009
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
7c2f986
to
2aed4d7
Compare
3de32ce
to
6333e4f
Compare
Add helpers: - `kea_add_lease` to add a lease to the running kea server - `kea_get_domain_from_subnet_id` to get the domain name from subnet id Also, enrich leases with domain name from subnet id
Keep DHCP server leases in sync with vyos-hostd records via helper script invoked with `ExecStartPost` directive in kea-dhcp4-server.service. The helper script updates VyOS hostd records from DHCP server leases. This ensures that hostd records with the DHCP server leases are kept in sync with VyOS hostd records right after DHCP server is started. This is similar to the capability exposed via kea hook `libdhcp_run_script.so` which is invoked internally by kea when a single lease changes state. Since the kea hook is currently implemented for DHCPv4 only, this helper script is implemented for DHCPv4 only as well.
The helper script updates VyOS hostd records from DHCP server leases. This ensures that hostd records with the DHCP server leases are kept in sync with VyOS hostd records right after the DHCP server is started. Note that `Restart` directive needs to be updated to `on-failure` so that the service is restarted in case of failure/timeout in interaction with hostd service.
The test `test_dhcp_hostsd_lease_sync` validates DHCP server leases in sync with hostd records. Since the DHCP server running in smoketest environment might not have actual clients to lease IP addresses, we simulate the lease creation and deletion using kea helper functions (`kea_add_lease` and `kea_delete_lease`).
The formatter methods are mostly `family` agnostic now.
6333e4f
to
6c14589
Compare
CI integration 👍 passed! Details
|
Change Summary
Keep DHCP server leases in sync with vyos-hostd records via helper script invoked with
ExecStartPost
directive in kea-dhcp4-server.service.The helper script updates VyOS hostd records from DHCP server leases. This ensures that hostd records with the DHCP server leases are kept in sync with VyOS hostd records right after DHCP server is started.
This is similar to the capability exposed via kea hook
libdhcp_run_script.so
which is invoked internally by kea when a single lease changes state.Since the kea hook is currently implemented for DHCPv4 only, this helper script is implemented for DHCPv4 only as well.
Types of changes
Related Task(s)
Related PR(s)
#4307
Component(s) name
dhcp server
Proposed changes
How to test
/etc/hosts
and/or/run/vyos-hostsd/vyos-hostsd.state
show dhcp server leases
)/etc/hosts
restart dhcp server
)/etc/hosts
Smoketest result
Checklist: