Skip to contentSkip to conversation

Allow postinst functions to be verbose

PATCH In review Peter Kjellerstedt 4 participants 7 messages Apr 14, 2017 – Apr 18, 2017

lore
Share & tools
lore
#0 lore raw

cover Allow postinst functions to be verbose

This enables tracing of the postinst functions created in base-passwd and useradd.bbclass if BB_VERBOSE_LOGS is enabled. I found this extremely useful during verification of the useradd functionality, especially as there otherwise is absolutely nothing in the logs of why a failure in a postinst function happened.

I also simplified useradd_sysroot_sstate() by only having the code to create the postinst files once.

Feel free to squash these commits with the "base-passwd/useradd:
Various improvements to useradd with RSS" commit if you prefer.

//Peter

The following changes since commit 79ac98550f0aa25940404a9805c12744f7047c76:

base-passwd/useradd: Various improvements to useradd with RSS (2017-04-14 00:03:19 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib pkj/verbose_postinst
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/verbose_postinst

Peter Kjellerstedt (2):
useradd.bbclass: Make postinst functions verbose if BB_VERBOSE_LOGS is
set
base-passwd: Make the postinst function verbose if BB_VERBOSE_LOGS is
set

 meta/classes/useradd.bbclass                        | 11 +++++------
 meta/recipes-core/base-passwd/base-passwd_3.5.29.bb |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.12.0
#1 lore raw

PATCH 1/2 useradd.bbclass: Make postinst functions verbose if BB_VERBOSE_LOGS is set

If BB_VERBOSE_LOGS is enabled, then make the postinst functions use set -x so that their execution is traced. This greatly simplifies debugging, especially in case of failures as nothing is recorded in the logs otherwise to indicate what caused the failure.

Also reduce code duplication in useradd_sysroot_sstate() by only having one copy of the code to create the postinst files.

---
 meta/classes/useradd.bbclass | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
meta/classes/useradd.bbclass +5 -6
index 4373677bd6..d9b5373d96 100644
@@ -133,26 +133,25 @@ useradd_sysroot () {
 }
 
 python useradd_sysroot_sstate () {
+    scriptfile = None
     task = d.getVar("BB_CURRENTTASK")
     if task == "package_setscene":
         bb.build.exec_func("useradd_sysroot", d)
     elif task == "prepare_recipe_sysroot":
         # Used to update this recipe's own sysroot so the user/groups are available to do_install
         scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-${PN}")
-        bb.utils.mkdirhier(os.path.dirname(scriptfile))
-        with open(scriptfile, 'w') as script:
-            script.write("#!/bin/sh\n")
-            bb.data.emit_func("useradd_sysroot", script, d)
-            script.write("useradd_sysroot\n")
-        os.chmod(scriptfile, 0o755)
         bb.build.exec_func("useradd_sysroot", d)
     elif task == "populate_sysroot":
         # Used when installed in dependent task sysroots
         scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-${PN}")
+
+    if scriptfile:
         bb.utils.mkdirhier(os.path.dirname(scriptfile))
         with open(scriptfile, 'w') as script:
             script.write("#!/bin/sh\n")
             bb.data.emit_func("useradd_sysroot", script, d)
+            if bb.msg.loggerVerboseLogs:
+                script.write("set -x\n")
             script.write("useradd_sysroot\n")
         os.chmod(scriptfile, 0o755)
 }
Signature · 1 line
2.12.0
#2 lore raw

PATCH 2/2 base-passwd: Make the postinst function verbose if BB_VERBOSE_LOGS is set

In reply to Peter Kjellerstedt

If BB_VERBOSE_LOGS is enabled, then make the postinst function use set -x so that its execution is traced. This greatly simplifies debugging, especially in case of failures as nothing is recorded in the logs otherwise to indicate what caused the failure.

---
 meta/recipes-core/base-passwd/base-passwd_3.5.29.bb | 2 ++
 1 file changed, 2 insertions(+)
meta/recipes-core/base-passwd/base-passwd_3.5.29.bb +2 -0
index c6be1c1d08..0d5deee7d0 100644
@@ -46,6 +46,8 @@ do_install () {
 basepasswd_sysroot_postinst() {
 #!/bin/sh
 
+${@"set -x" if bb.msg.loggerVerboseLogs else ""}
+
 # Install passwd.master and group.master to sysconfdir
 install -d -m 755 ${STAGING_DIR_TARGET}${sysconfdir}
 for i in passwd group; do
Signature · 1 line
2.12.0
#3 lore raw

✗ patchtest: failure for Allow postinst functions to be verbose

In reply to Peter Kjellerstedt

== Series Details ==

Series: Allow postinst functions to be verbose
Revision: 1
URL : https://patchwork.openembedded.org/series/6370/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 334020a800)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---

Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
#4 lore raw
In reply to Peter Kjellerstedt
Quoted 7 lines · Peter Kjellerstedt

This enables tracing of the postinst functions created in base-passwd and useradd.bbclass if BB_VERBOSE_LOGS is enabled. I found this extremely useful during verification of the useradd functionality, especially as there otherwise is absolutely nothing in the logs of why
a failure in a postinst function happened.

Quoted 5 lines

I also simplified useradd_sysroot_sstate() by only having the code to create the postinst files once.

Feel free to squash these commits with the "base-passwd/useradd:
Various improvements to useradd with RSS" commit if you prefer.

I'm afraid I can't take these since these scripts get written into the sstate objects for the recipes in question and this would make the sstate change depending on the parameters you call bitbake with. I think we'd both agree that is undesirable.

Not sure what we can do but this needs more thought.

Cheers,

Richard

#5 lore raw
Quoted 19 lines

-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: den 14 april 2017 10:49
To: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [OE-core] [PATCH 0/2] Allow postinst functions to be verbose

Quoted 10 lines · Peter Kjellerstedt

This enables tracing of the postinst functions created in base-passwd and useradd.bbclass if BB_VERBOSE_LOGS is enabled. I found this extremely useful during verification of the useradd functionality, especially as there otherwise is absolutely nothing in the logs of why
a failure in a postinst function happened.

I also simplified useradd_sysroot_sstate() by only having the code to create the postinst files once.

Quoted 7 lines
Quoted 2 lines

Feel free to squash these commits with the "base-passwd/useradd:
Various improvements to useradd with RSS" commit if you prefer.

I'm afraid I can't take these since these scripts get written into the sstate objects for the recipes in question and this would make the sstate change depending on the parameters you call bitbake with. I think we'd both agree that is undesirable.

Bother. Did not think of that (I am so used to having it enabled in all my builds).

Quoted 1 line

Not sure what we can do but this needs more thought.

Yeah, it would be great if the output from the postinst scripts was actually captured. But we can think of that for 2.4.

Quoted 3 lines

Cheers,

Richard

//Peter

#6 lore raw
Quoted 5 lines · Peter Kjellerstedt
Quoted 4 lines

I'm afraid I can't take these since these scripts get written into the sstate objects for the recipes in question and this would make the sstate change depending on the parameters you call bitbake with. I think we'd both agree that is undesirable.

Quoted 7 lines

Bother. Did not think of that (I am so used to having it enabled in all my builds).

Quoted 1 line

Not sure what we can do but this needs more thought.

Yeah, it would be great if the output from the postinst scripts was actually captured. But we can think of that for 2.4.

Are you using rpm? If you are, we already have ROOTFS_RPM_DEBUG variable which, if enabled, directs rpm to output a lot more to the log.do_rootfs than it normally would. Can you switch it on in your local.conf and see if you get what you need?

If the log still isn't verbose enough, please write a comment to this bug:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=11096

explaining what kind of output from rpm would be useful to have, and we can patch rpm to do that.

Alex