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-15 06:27:18 -0700
commit682705389526fba41ef8763d290ea4cab8787e43 (patch)
tree95ec95f772e6f04cd8d792e7ef0dfb54695ba75e
parentcd005e2d5bab8bc7cf4fd8b66c0bcc0328a0decd (diff)
downloadpoky-682705389526fba41ef8763d290ea4cab8787e43.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. (From OE-Core rev: 865fafb0dff19d27bd417c28c95fb8fdf0326a2b) 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"
3 3
4inherit allarch 4inherit allarch
5 5
6PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b" 6PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"
7 7
8ALLOW_EMPTY_${PN}-rootfs = "1" 8ALLOW_EMPTY_${PN}-rootfs = "1"
9ALLOW_EMPTY_${PN}-delayed-a = "1" 9ALLOW_EMPTY_${PN}-delayed-a = "1"
10ALLOW_EMPTY_${PN}-delayed-b = "1" 10ALLOW_EMPTY_${PN}-delayed-b = "1"
11ALLOW_EMPTY_${PN}-rootfs-failing = "1"
11 12
12RDEPENDS_${PN}-delayed-a = "${PN}-rootfs" 13RDEPENDS_${PN}-delayed-a = "${PN}-rootfs"
13RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a" 14RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a"
@@ -58,3 +59,14 @@ pkg_postinst_ontarget_${PN}-delayed-b () {
58 59
59 touch ${TESTDIR}/delayed-b 60 touch ${TESTDIR}/delayed-b
60} 61}
62
63# This scriptlet intentionally includes a bogus command in the middle to test
64# that we catch and report such errors properly.
65pkg_postinst_${PN}-rootfs-failing () {
66 mkdir -p $D${TESTDIR}
67 touch $D${TESTDIR}/rootfs-before-failure
68 run_a_really_broken_command
69 # Scriptlet execution should stop here; the following commands are NOT supposed to run.
70 # (oe-selftest checks for it).
71 touch $D${TESTDIR}/rootfs-after-failure
72}
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):
221 for filename in ("rootfs", "delayed-a", "delayed-b"): 221 for filename in ("rootfs", "delayed-a", "delayed-b"):
222 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename)) 222 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
223 self.assertEqual(output, "found", "%s was not present on boot" % filename) 223 self.assertEqual(output, "found", "%s was not present on boot" % filename)
224
225
226
227 def test_failing_postinst(self):
228 """
229 Summary: The purpose of this test case is to verify that post-installation
230 scripts that contain errors are properly reported.
231 Expected: The scriptlet failure is properly reported.
232 The file that is created after the error in the scriptlet is not present.
233 Product: oe-core
234 Author: Alexander Kanavin <alexander.kanavin@intel.com>
235 """
236
237 import oe.path
238
239 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
240 rootfs = vars["IMAGE_ROOTFS"]
241 self.assertIsNotNone(rootfs)
242 sysconfdir = vars["sysconfdir"]
243 self.assertIsNotNone(sysconfdir)
244 # Need to use oe.path here as sysconfdir starts with /
245 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
246
247 for classes in ("package_rpm", "package_deb", "package_ipk"):
248 with self.subTest(package_class=classes):
249 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
250 features += 'PACKAGE_CLASSES = "%s"\n' % classes
251 self.write_config(features)
252 bb_result = bitbake('core-image-minimal')
253 self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0,
254 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
255
256 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
257 "rootfs-before-failure file was not created")
258 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
259 "rootfs-after-failure file was created")
260