test_netsnmp.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import infra.basetest
  3. class TestNetSNMP(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_netsnmp/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_NETSNMP=y
  9. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  10. BR2_TARGET_ROOTFS_CPIO=y
  11. # BR2_TARGET_ROOTFS_TAR is not set
  12. """
  13. def test_run(self):
  14. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  15. self.emulator.boot(arch="armv5",
  16. kernel="builtin",
  17. options=["-initrd", cpio_file])
  18. self.emulator.login()
  19. # We check the daemon and a client program can execute.
  20. self.assertRunOk("snmpd --version")
  21. self.assertRunOk("snmpget --version")
  22. # The daemon is supposed to be started by the initscript,
  23. # since we included a /etc/snmp/snmpd.conf file. We should be
  24. # able to walk through the SNMPv2 system MIB.
  25. self.assertRunOk("snmpwalk -v 2c -c public 127.0.0.1 system")
  26. # We check few OIDs has the expected values. sysContact and
  27. # sysLocation are set in the snmpd.conf file.
  28. tests = [
  29. ("system.sysName.0", "STRING: buildroot"),
  30. ("system.sysContact.0", "STRING: Buildroot Test User"),
  31. ("system.sysLocation.0", "STRING: Buildroot Test Infra")
  32. ]
  33. for oid, expected_out in tests:
  34. cmd = f"snmpget -v 2c -c public -Ov 127.0.0.1 {oid}"
  35. out, ret = self.emulator.run(cmd)
  36. self.assertEqual(ret, 0)
  37. self.assertEqual(out[0], expected_out)