Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bci_tester/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,19 @@ def create_BCI(
forwarded_ports=[PortForwarding(container_port=80)],
)

_KEA_VERSION_OS_MATRIX: Tuple[Tuple[str, Tuple[str, ...]], ...] = (
("2.6", ("tumbleweed",)),
)

KEA_CONTAINERS = [
create_BCI(
build_tag=f"{APP_CONTAINER_PREFIX}/kea:{kea_ver}",
bci_type=ImageType.APPLICATION,
available_versions=os_versions,
)
for kea_ver, os_versions in _KEA_VERSION_OS_MATRIX
]

if OS_VERSION in ("16.0",):
KERNEL_MODULE_CONTAINER = create_BCI(
build_tag=f"{BCI_CONTAINER_PREFIX}/bci-sle16-kernel-module-devel:{OS_CONTAINER_TAG}",
Expand Down Expand Up @@ -1026,6 +1039,7 @@ def create_BCI(
+ RUST_CONTAINERS
+ SPACK_CONTAINERS
+ (DOTNET_CONTAINERS if LOCALHOST.system_info.arch == "x86_64" else [])
+ KEA_CONTAINERS
)

#: all containers with zypper and with the flag to launch them as root
Expand Down Expand Up @@ -1108,6 +1122,7 @@ def create_BCI(
+ RUBY_CONTAINERS
+ RUST_CONTAINERS
+ SPACK_CONTAINERS
+ KEA_CONTAINERS
)

ACC_CONTAINERS = POSTGRESQL_CONTAINERS
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ markers = [
'golang_unstable',
'grafana_9',
'grafana_11',
'kea_2.6',
'kiwi_9.24',
'kiwi_10.1',
'kiwi_latest',
Expand Down
48 changes: 48 additions & 0 deletions tests/files/kea-dhcp4.conf
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
}
]
}
}
77 changes: 77 additions & 0 deletions tests/test_kea.py
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:
Copy link
Collaborator

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

mac, ip = match.groups()
assert mac == client_mac
assert ip == received_ip
else:
pytest.fail("IP is not allocated by the kea dhcp server")
2 changes: 2 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from bci_tester.data import GRAFANA_CONTAINERS
from bci_tester.data import HELM_CONTAINER
from bci_tester.data import INIT_CONTAINER
from bci_tester.data import KEA_CONTAINERS
from bci_tester.data import KERNEL_MODULE_CONTAINER
from bci_tester.data import KIWI_CONTAINERS
from bci_tester.data import L3_CONTAINERS
Expand Down Expand Up @@ -173,6 +174,7 @@ def _get_container_label_prefix(
for container_pcp in PCP_CONTAINERS
]
+ [(kiwi, "kiwi", ImageType.LANGUAGE_STACK) for kiwi in KIWI_CONTAINERS]
+ [(kea, "kea", ImageType.APPLICATION) for kea in KEA_CONTAINERS]
+ [
(tomcat_ctr, "apache-tomcat", ImageType.SAC_APPLICATION)
for tomcat_ctr in TOMCAT_CONTAINERS
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = {py36,py39,py310,py311,py312,py313}-unit, all, base, cosign, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx, kernel_module, mariadb, tomcat, spack, gcc, prometheus, grafana, kiwi, postfix, ai
envlist = {py36,py39,py310,py311,py312,py313}-unit, all, base, cosign, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx, kernel_module, mariadb, tomcat, spack, gcc, prometheus, grafana, kiwi, postfix, ai, kea
skip_missing_interpreters = True

[common]
Expand Down
Loading