postinst: Add a test case to verify postinst scripts behavior

Add test case that verify behavior of postinst scripts at
roofts time and when is delayed to the first boot directly
on the target.

(From OE-Core rev: 82b171f3b37e6733997fc1e7685b7cac5a3476e7)

Signed-off-by: Jose Perez Carranza <jose.perez.carranza@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Jose Perez Carranza 2016-12-06 11:29:01 -06:00 committed by Richard Purdie
parent 23d1c4ffb7
commit 333890953d
2 changed files with 63 additions and 0 deletions

View File

@ -24,6 +24,7 @@ RDEPENDS_${PN}-delayed-t = "${PN}-delayed-p"
# Main recipe post-install
pkg_postinst_${PN}-at-rootfs () {
tfile="/etc/postinsta-test"
touch "$D"/this-was-created-at-rootfstime
if test "x$D" != "x" then
# Need to run on first boot
exit 1
@ -42,6 +43,7 @@ pkg_postinst_${PN}-delayed-a () {
# Need to run on first boot
exit 1
else
touch /etc/this-was-created-at-first-boot
if test -e $efile ; then
echo 'success' > $tfile
else

View File

@ -155,3 +155,64 @@ postinst-delayed-t \
elif found:
self.assertEqual(idx, len(postinst_list), "Not found all postinsts")
break
@testcase(1545)
def test_postinst_roofs_and_boot(self):
"""
Summary: The purpose of this test case is to verify Post-installation
scripts are called when roofs is created and also test
that script can be delayed to run at first boot.
Dependencies: NA
Steps: 1. Add proper configuration to local.conf file
2. Build a "core-image-full-cmdline" image
3. Verify that file created by postinst_rootfs recipe is
present on rootfs dir.
4. Boot the image created on qemu and verify that the file
created by postinst_boot recipe is present on image.
5. Clean the packages and image created to test with
different package managers
Expected: The files are successfully created during rootfs and boot
time for 3 different package managers: rpm,ipk,deb and
for initialization managers: sysvinit and systemd.
"""
file_rootfs_name = "this-was-created-at-rootfstime"
fileboot_name = "this-was-created-at-first-boot"
rootfs_pkg = 'postinst-at-rootfs'
boot_pkg = 'postinst-delayed-a'
#Step 1
features = 'MACHINE = "qemux86"\n'
features += 'CORE_IMAGE_EXTRA_INSTALL += "%s %s "\n'% (rootfs_pkg, boot_pkg)
for init_manager in ("sysvinit", "systemd"):
#for sysvinit no extra configuration is needed,
if (init_manager is "systemd"):
features += 'DISTRO_FEATURES_append = " systemd"\n'
features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
for classes in ("package_rpm package_deb package_ipk",
"package_deb package_rpm package_ipk",
"package_ipk package_deb package_rpm"):
features += 'PACKAGE_CLASSES = "%s"\n' % classes
self.write_config(features)
#Step 2
bitbake('core-image-full-cmdline')
#Step 3
file_rootfs_created = os.path.join(get_bb_var('IMAGE_ROOTFS',"core-image-full-cmdline"),
file_rootfs_name)
found = os.path.isfile(file_rootfs_created)
self.assertTrue(found, "File %s was not created at rootfs time by %s" % \
(file_rootfs_name, rootfs_pkg))
#Step 4
testcommand = 'ls /etc/'+fileboot_name
with runqemu('core-image-full-cmdline') as qemu:
sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand))
self.assertEqual(result.status, 0, 'File %s was not created at firts boot'% fileboot_name)
#Step 5
bitbake(' %s %s -c cleanall' % (rootfs_pkg, boot_pkg))
bitbake('core-image-full-cmdline -c cleanall')