test_opkg.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. _, exit_code = self.emulator.run(cmd)
  31. self.assertEqual(exit_code, 0)
  32. cmd = "opkg list-installed | grep example-snmpd-package"
  33. _, exit_code = self.emulator.run(cmd)
  34. self.assertEqual(exit_code, 0)
  35. # Check that postinst script ran to start the services
  36. cmd = "ps aux | grep [s]nmpd"
  37. _, exit_code = self.emulator.run(cmd)
  38. self.assertEqual(exit_code, 0)
  39. # If successful, the prerm script ran to stop the service prior to
  40. # the removal of the service scripting and files
  41. cmd = "opkg remove example-snmpd-package"
  42. _, exit_code = self.emulator.run(cmd)
  43. self.assertEqual(exit_code, 0)
  44. # Verify after package removal that the services is not
  45. # running, but let's give it some time to really stop
  46. # (otherwise a [snmpd] process might show up in the ps output)
  47. cmd = "sleep 1 && ps aux | grep [s]nmpd"
  48. _, exit_code = self.emulator.run(cmd)
  49. self.assertEqual(exit_code, 1)
  50. # This folder for configs is provided by the package install and
  51. # should no longer be present after package removal
  52. cmd = "ls /etc/snmp"
  53. _, exit_code = self.emulator.run(cmd)
  54. self.assertEqual(exit_code, 1)