-
Notifications
You must be signed in to change notification settings - Fork 23
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
[WIP] kea dhcp4 testing #706
Open
rcmadhankumar
wants to merge
1
commit into
main
Choose a base branch
from
kea-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"Dhcp4": { | ||
"interfaces-config": { | ||
"interfaces": ["*"] | ||
}, | ||
"subnet4": [ | ||
{ | ||
"subnet": "192.168.1.0/24", | ||
"pools": [ | ||
{ "pool": "192.168.1.100-192.168.1.200" } | ||
], | ||
"option-data": [ | ||
{ "name": "routers", "data": "192.168.1.1" } | ||
], | ||
"id": 1 | ||
} | ||
], | ||
"lease-database": { | ||
"type": "memfile", | ||
"persist": true, | ||
"name": "/var/lib/kea/dhcp4.leases" | ||
}, | ||
"loggers": [ | ||
{ | ||
"name": "kea-dhcp4", | ||
"output_options": [ | ||
{ | ||
"output": "/tmp/kea-dhcp4.log", | ||
"maxsize": 1048576, | ||
"maxver": 8 | ||
} | ||
], | ||
"severity": "DEBUG" | ||
}, | ||
{ | ||
"name": "kea-dhcp4.packets", | ||
"output_options": [ | ||
{ | ||
"output": "/tmp/kea-dhcp4-packets.log", | ||
"maxver": 10 | ||
} | ||
], | ||
"severity": "DEBUG", | ||
"debuglevel": 99 | ||
} | ||
] | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import re | ||
|
||
import pytest | ||
from pytest_container import DerivedContainer | ||
from pytest_container.container import ContainerLauncher | ||
from pytest_container.runtime import OciRuntimeBase | ||
|
||
from bci_tester.data import KEA_CONTAINERS | ||
|
||
|
||
@pytest.mark.parametrize("ctr_image", KEA_CONTAINERS) | ||
def test_kea_dhcp4( | ||
container_runtime: OciRuntimeBase, | ||
pytestconfig: pytest.Config, | ||
ctr_image: DerivedContainer, | ||
) -> None: | ||
kea_ctr = DerivedContainer( | ||
base=ctr_image, | ||
# below base image was used for testing as we haven't published kea image yet | ||
# base="registry.opensuse.org/devel/bci/tumbleweed/containerfile/opensuse/kea:latest", | ||
containerfile="COPY tests/files/kea-dhcp4.conf /etc/kea/kea-dhcp4.conf", | ||
custom_entry_point="kea-dhcp4", | ||
extra_entrypoint_args=["-c", "/etc/kea/kea-dhcp4.conf"], | ||
extra_launch_args=["--network=host", "--privileged"], | ||
) | ||
|
||
dhcp_client_ctr = DerivedContainer( | ||
base="registry.opensuse.org/opensuse/tumbleweed:latest", | ||
containerfile="RUN zypper refresh && zypper -n install dhcp-client iproute2 && zypper clean --all", | ||
custom_entry_point="/bin/sh", | ||
extra_launch_args=["--network=host", "--privileged"], | ||
) | ||
|
||
with ContainerLauncher.from_pytestconfig( | ||
kea_ctr, container_runtime, pytestconfig | ||
) as kea_launcher, ContainerLauncher.from_pytestconfig( | ||
dhcp_client_ctr, container_runtime, pytestconfig | ||
) as cli_launcher: | ||
kea_launcher.launch_container() | ||
cli_launcher.launch_container() | ||
|
||
cli_con = cli_launcher.container_data.connection | ||
# output of ip route show: | ||
# default via 192.168.1.1 dev wlp0s20f3 proto dhcp src 192.168.1.97 metric 600 | ||
# 10.0.0.0/8 via 10.149.211.61 dev tun0 proto static metric 50 | ||
# 10.149.208.1 via 10.149.211.61 dev tun0 proto static metric 50 | ||
default_interface_line = [ | ||
line | ||
for line in cli_con.check_output("ip route show").splitlines() | ||
if line.startswith("default") | ||
][0] | ||
default_interface = default_interface_line.split()[4] | ||
|
||
client_log = cli_con.run_expect( | ||
[0], "dhclient -v " + default_interface | ||
).stderr | ||
|
||
mac_pattern = r"LPF/\S+/([0-9a-fA-F:]+)" | ||
ip_pattern = r"bound to (\d+\.\d+\.\d+\.\d+)" | ||
mac_match = re.search(mac_pattern, client_log) | ||
ip_match = re.search(ip_pattern, client_log) | ||
|
||
client_mac = mac_match.group(1) if mac_match else None | ||
received_ip = ip_match.group(1) if ip_match else None | ||
assert client_mac is not None | ||
assert received_ip is not None | ||
|
||
kea_con = kea_launcher.container_data.connection | ||
log_lines = kea_con.check_output("cat /tmp/kea-dhcp4.log") | ||
pattern = r"DHCP4_LEASE_ALLOC .*?hwtype=1 ([\da-f:]+).*?lease ([\d.]+)" | ||
match = re.search(pattern, log_lines) | ||
if match: | ||
mac, ip = match.groups() | ||
assert mac == client_mac | ||
assert ip == received_ip | ||
else: | ||
pytest.fail("IP is not allocated by the kea dhcp server") |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
I think we should fail if there is no match