test_firewalld.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. """Test firewalld for both systemd and sysvinit."""
  2. import os
  3. import time
  4. import infra.basetest
  5. class TestFirewalldSystemd(infra.basetest.BRTest):
  6. """Build the kernel as firewalld requires several the nftable options."""
  7. config = """
  8. BR2_arm=y
  9. BR2_cortex_a9=y
  10. BR2_ARM_ENABLE_VFP=y
  11. BR2_TOOLCHAIN_EXTERNAL=y
  12. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  13. BR2_INIT_SYSTEMD=y
  14. BR2_LINUX_KERNEL=y
  15. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  16. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.61"
  17. BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
  18. BR2_LINUX_KERNEL_DTS_SUPPORT=y
  19. BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
  20. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  21. BR2_PACKAGE_PYTHON3=y
  22. BR2_PACKAGE_FIREWALLD=y
  23. BR2_TARGET_ROOTFS_CPIO=y
  24. # BR2_TARGET_ROOTFS_TAR is not set
  25. """
  26. def test_run(self):
  27. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  28. kernel_file = os.path.join(self.builddir, "images", "zImage")
  29. dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
  30. self.emulator.boot(arch="armv7",
  31. kernel=kernel_file,
  32. kernel_cmdline=["console=ttyAMA0,115200"],
  33. options=[
  34. "-initrd", cpio_file,
  35. "-dtb", dtb_file,
  36. "-M", "vexpress-a9"
  37. ])
  38. # It takes quite some time for the system to boot with firewalld,
  39. self.emulator.login(timeout=120)
  40. # It may take some time for firewalld to finish startup.
  41. # Give it at least 15 seconds.
  42. is_active = False
  43. for i in range(15):
  44. output, _ = self.emulator.run("systemctl is-active firewalld")
  45. if output[0] == "active":
  46. is_active = True
  47. break
  48. time.sleep(1)
  49. if not is_active:
  50. self.fail("firewalld failed to activate!")
  51. cmd = "firewall-cmd --state"
  52. output, exit_code = self.emulator.run(cmd, timeout=10)
  53. self.assertIn("running", output[0])
  54. self.assertEqual(exit_code, 0)
  55. class TestFirewalldSysVInit(infra.basetest.BRTest):
  56. """Build the kernel as firewalld requires several nftable options."""
  57. config = """
  58. BR2_arm=y
  59. BR2_cortex_a9=y
  60. BR2_ARM_ENABLE_VFP=y
  61. BR2_TOOLCHAIN_EXTERNAL=y
  62. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  63. BR2_LINUX_KERNEL=y
  64. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  65. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.61"
  66. BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
  67. BR2_LINUX_KERNEL_DTS_SUPPORT=y
  68. BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
  69. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  70. BR2_PACKAGE_PYTHON3=y
  71. BR2_PACKAGE_FIREWALLD=y
  72. BR2_TARGET_ROOTFS_CPIO=y
  73. # BR2_TARGET_ROOTFS_TAR is not set
  74. """
  75. def test_run(self):
  76. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  77. kernel_file = os.path.join(self.builddir, "images", "zImage")
  78. dtb_file = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
  79. self.emulator.boot(arch="armv7",
  80. kernel=kernel_file,
  81. kernel_cmdline=["console=ttyAMA0,115200"],
  82. options=[
  83. "-initrd", cpio_file,
  84. "-dtb", dtb_file,
  85. "-M", "vexpress-a9"
  86. ])
  87. # It takes quite some time for the system to boot with firewalld.
  88. self.emulator.login(timeout=120)
  89. cmd = "firewall-cmd --state"
  90. output, exit_code = self.emulator.run(cmd, timeout=10)
  91. self.assertIn("running", output[0])
  92. self.assertEqual(exit_code, 0)