summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alexander.kanavin@linux.intel.com>2018-03-12 18:49:43 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-03-12 15:28:04 -0700
commit865fafb0dff19d27bd417c28c95fb8fdf0326a2b (patch)
tree0590d7ae4d01e9a33f3bad3b6b5b704281b5c536
parenta36671faf6e0b7623185b0e22814a786d5444592 (diff)
downloadopenembedded-core-contrib-865fafb0dff19d27bd417c28c95fb8fdf0326a2b.tar.gz
oe-selftest: add a test for failing package post-installation scriptlets
The test runs a scriptlet that has an intentionally failing command in the middle and checks for two things: 1) that bitbake does warn the user about the failure 2) that scriptlet execution stops at that point. The test is run for all three package types: rpm, deb, ipk. Signed-off-by: Alexander Kanavin <alexander.kanavin@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta-selftest/recipes-test/postinst/postinst_1.0.bb14
-rw-r--r--meta/lib/oeqa/selftest/cases/runtime_test.py37
2 files changed, 50 insertions, 1 deletions
diff --git a/meta-selftest/recipes-test/postinst/postinst_1.0.bb b/meta-selftest/recipes-test/postinst/postinst_1.0.bb
index d4bab6dcc2..913bfabf89 100644
--- a/meta-selftest/recipes-test/postinst/postinst_1.0.bb
+++ b/meta-selftest/recipes-test/postinst/postinst_1.0.bb
@@ -3,11 +3,12 @@ LICENSE = "MIT"
inherit allarch
-PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b"
+PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"
ALLOW_EMPTY_${PN}-rootfs = "1"
ALLOW_EMPTY_${PN}-delayed-a = "1"
ALLOW_EMPTY_${PN}-delayed-b = "1"
+ALLOW_EMPTY_${PN}-rootfs-failing = "1"
RDEPENDS_${PN}-delayed-a = "${PN}-rootfs"
RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a"
@@ -58,3 +59,14 @@ pkg_postinst_ontarget_${PN}-delayed-b () {
touch ${TESTDIR}/delayed-b
}
+
+# This scriptlet intentionally includes a bogus command in the middle to test
+# that we catch and report such errors properly.
+pkg_postinst_${PN}-rootfs-failing () {
+ mkdir -p $D${TESTDIR}
+ touch $D${TESTDIR}/rootfs-before-failure
+ run_a_really_broken_command
+ # Scriptlet execution should stop here; the following commands are NOT supposed to run.
+ # (oe-selftest checks for it).
+ touch $D${TESTDIR}/rootfs-after-failure
+}
diff --git a/meta/lib/oeqa/selftest/cases/runtime_test.py b/meta/lib/oeqa/selftest/cases/runtime_test.py
index 1c69255b56..9c9b4b3411 100644
--- a/meta/lib/oeqa/selftest/cases/runtime_test.py
+++ b/meta/lib/oeqa/selftest/cases/runtime_test.py
@@ -221,3 +221,40 @@ class Postinst(OESelftestTestCase):
for filename in ("rootfs", "delayed-a", "delayed-b"):
status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
self.assertEqual(output, "found", "%s was not present on boot" % filename)
+
+
+
+ def test_failing_postinst(self):
+ """
+ Summary: The purpose of this test case is to verify that post-installation
+ scripts that contain errors are properly reported.
+ Expected: The scriptlet failure is properly reported.
+ The file that is created after the error in the scriptlet is not present.
+ Product: oe-core
+ Author: Alexander Kanavin <alexander.kanavin@intel.com>
+ """
+
+ import oe.path
+
+ vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
+ rootfs = vars["IMAGE_ROOTFS"]
+ self.assertIsNotNone(rootfs)
+ sysconfdir = vars["sysconfdir"]
+ self.assertIsNotNone(sysconfdir)
+ # Need to use oe.path here as sysconfdir starts with /
+ hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
+
+ for classes in ("package_rpm", "package_deb", "package_ipk"):
+ with self.subTest(package_class=classes):
+ features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
+ features += 'PACKAGE_CLASSES = "%s"\n' % classes
+ self.write_config(features)
+ bb_result = bitbake('core-image-minimal')
+ self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0,
+ "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
+
+ self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
+ "rootfs-before-failure file was not created")
+ self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
+ "rootfs-after-failure file was created")
+