]> code.ossystems Code Review - openembedded-core.git/commitdiff
postinst: Add a test case to verify postinst scripts behavior
authorJose Perez Carranza <jose.perez.carranza@linux.intel.com>
Tue, 6 Dec 2016 17:29:01 +0000 (11:29 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 16 Dec 2016 08:30:01 +0000 (08:30 +0000)
Add test case that verify behavior of postinst scripts at
roofts time and when is delayed to the first boot directly
on the target.

Signed-off-by: Jose Perez Carranza <jose.perez.carranza@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta-selftest/recipes-test/postinst/postinst_1.0.bb
meta/lib/oeqa/selftest/runtime-test.py

index 97a19873057966093c13235e3285cfd938be11e2..6d497342779ba294cf1cf0d46895724299d09469 100644 (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
index 1dbfae1106ecb3411f63f3d7f700c37d6ec00b84..20caa97d16283b62656031d7003fa921e16f2e58 100644 (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')