test_opkg.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import infra.basetest
  3. class TestOpkg(infra.basetest.BRTest):
  4. # The snmpd service is used as an example for this test of a set of files
  5. # that can be archived up and deployed/removed to test opkg
  6. #
  7. # The post build script uses an ipk-build template and assembles the test
  8. # package.
  9. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  10. """
  11. BR2_PACKAGE_NETSNMP=y
  12. # BR2_PACKAGE_NETSNMP_CLIENTS is not set
  13. # BR2_PACKAGE_NETSNMP_ENABLE_MIBS is not set
  14. BR2_PACKAGE_OPKG=y
  15. BR2_TARGET_ROOTFS_CPIO=y
  16. # BR2_TARGET_ROOTFS_TAR is not set
  17. BR2_PACKAGE_HOST_OPKG_UTILS=y
  18. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  19. """.format(infra.filepath("tests/package/test_opkg/post-build.sh"))
  20. def test_run(self):
  21. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  22. self.emulator.boot(arch="armv5",
  23. kernel="builtin",
  24. options=["-initrd", cpio_file])
  25. self.emulator.login()
  26. # This test sequence tests the install and removal of a running
  27. # service and configuration files. It also exercises the postinst
  28. # and prerm scripting provided in the package archive.
  29. cmd = "opkg install example-snmpd-package_1.0_arm.ipk"
  30. self.assertRunOk(cmd)
  31. cmd = "opkg list-installed | grep example-snmpd-package"
  32. self.assertRunOk(cmd)
  33. # Check that postinst script ran to start the services
  34. cmd = "ps aux | grep [s]nmpd"
  35. self.assertRunOk(cmd)
  36. # If successful, the prerm script ran to stop the service prior to
  37. # the removal of the service scripting and files
  38. cmd = "opkg remove example-snmpd-package"
  39. self.assertRunOk(cmd)
  40. # Verify after package removal that the services is not
  41. # running, but let's give it some time to really stop
  42. # (otherwise a [snmpd] process might show up in the ps output)
  43. cmd = "sleep 1 && ps aux | grep [s]nmpd"
  44. _, exit_code = self.emulator.run(cmd)
  45. self.assertEqual(exit_code, 1)
  46. # This folder for configs is provided by the package install and
  47. # should no longer be present after package removal
  48. cmd = "ls /etc/snmp"
  49. _, exit_code = self.emulator.run(cmd)
  50. self.assertEqual(exit_code, 1)