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