Files
buildroot/support/testing/tests/package/test_firewalld.py
Romain Naour 803cac2271 support/testing: TestFirewalld{Systemd, SysVInit}: fix expected ouput
Since Firewalld v2.4.3 [1] firewall-cmd added a new log line while
waiting for dbus connection [2].

  [BRTEST# firewall-cmd --state
  Waiting on dbus connection...
  running

The line "Waiting on dbus connection..." is not always printed by
firewall-cmd, so we have to search explicitely for the expected
string to get a reproducible test result.

Update both TestFirewalld accordingly.

This change is required to fix:
https://gitlab.com/buildroot.org/buildroot/-/jobs/16060152329 (TestFirewalldSysVInit)
https://gitlab.com/buildroot.org/buildroot/-/jobs/16060152332 (TestFirewalldSystemd)

[1] 380dd8a348
[2] 5e1c37c966

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Julien Olivain <ju.o@free.fr>
2026-08-27 19:55:18 +02:00

115 lines
4.5 KiB
Python

"""Test firewalld for both systemd and sysvinit."""
import os
import time
import infra.basetest
# gitlab-runner: large
class TestFirewalldSystemd(infra.basetest.BRTest):
"""Build the kernel as firewalld requires several the nftable options."""
config = """
BR2_arm=y
BR2_cortex_a9=y
BR2_ARM_ENABLE_VFP=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
BR2_INIT_SYSTEMD=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.61"
BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_FIREWALLD=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
ext2_file = os.path.join(self.builddir, "images", "rootfs.ext2")
kernel_file = os.path.join(self.builddir, "images", "zImage")
dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
self.emulator.boot(arch="armv7",
kernel=kernel_file,
kernel_cmdline=["console=ttyAMA0,115200",
"rootwait", "root=/dev/mmcblk0"],
options=[
'-drive', f'file={ext2_file},if=sd,format=raw',
"-dtb", dtb_file,
"-M", "vexpress-a9"
])
# It takes quite some time for the system to boot with firewalld,
self.emulator.login(timeout=120)
# It may take some time for firewalld to finish startup.
# Give it at least 15 seconds.
is_active = False
for i in range(15):
output, _ = self.emulator.run("systemctl is-active firewalld")
if output[0] == "active":
is_active = True
break
time.sleep(1)
if not is_active:
self.fail("firewalld failed to activate!")
cmd = "firewall-cmd --state"
output, exit_code = self.emulator.run(cmd, timeout=10)
# Ignore any unexpected log from firewall-cmd
# like "Waiting on dbus connection..."
expected_line = next(ln for ln in output if ln.strip().startswith('running'))
self.assertIn("running", expected_line)
self.assertEqual(exit_code, 0)
# gitlab-runner: large
class TestFirewalldSysVInit(infra.basetest.BRTest):
"""Build the kernel as firewalld requires several nftable options."""
config = """
BR2_arm=y
BR2_cortex_a9=y
BR2_ARM_ENABLE_VFP=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.61"
BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_FIREWALLD=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
ext2_file = os.path.join(self.builddir, "images", "rootfs.ext2")
kernel_file = os.path.join(self.builddir, "images", "zImage")
dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
self.emulator.boot(arch="armv7",
kernel=kernel_file,
kernel_cmdline=["console=ttyAMA0,115200",
"rootwait", "root=/dev/mmcblk0"],
options=[
'-drive', f'file={ext2_file},if=sd,format=raw',
"-dtb", dtb_file,
"-M", "vexpress-a9"
])
# It takes quite some time for the system to boot with firewalld.
self.emulator.login(timeout=120)
cmd = "firewall-cmd --state"
output, exit_code = self.emulator.run(cmd, timeout=10)
# Ignore any unexpected log from firewall-cmd
# like "Waiting on dbus connection..."
expected_line = next(ln for ln in output if ln.strip().startswith('running'))
self.assertIn("running", expected_line)
self.assertEqual(exit_code, 0)