[RFC] meta-skeleton: useradd-dep: add example of recipe using useradd and group created in other recipe

Submitted by Martin Jansa on Oct. 9, 2020, 1:16 p.m. | Patch ID: 177088

Details

Message ID 20201009131616.3036495-1-Martin.Jansa@gmail.com
State New
Headers show

Commit Message

Martin Jansa Oct. 9, 2020, 1:16 p.m.
* maybe this would be better in meta-selftest, I can move it there
  once we agree how this is supposed to work

* https://www.openembedded.org/pipermail/bitbake-devel/2018-March/009256.html
  says that RDEPENDS_${PN} should be enough, but in my testing we need
  built time dependency as well for groups to exist early enough

* and unfortunately even with the "useradd dependency" in DEPENDS is see
  very rare failures (in dunfell but I haven't found any changes in this area
  in master) when useradd-dep and useradd-example are reused from sstate.

  In these cases I've noticed that useradd-dep.do_package_setscene is running before useradd-example.do_package_setscene:

  NOTE: Running setscene task 268 of 3783 (useradd-dep.bb:do_package_write_ipk_setscene)
  NOTE: Running setscene task 269 of 3783 (useradd-dep.bb:do_populate_lic_setscene)
  NOTE: useradd-dep-1.0-r1: task do_package_write_ipk_setscene: Started
  NOTE: useradd-dep-1.0-r1: task do_populate_lic_setscene: Started
  NOTE: useradd-dep-1.0-r1: task do_package_write_ipk_setscene: Succeeded
  NOTE: Running setscene task 279 of 3783 (useradd-dep.bb:do_packagedata_setscene)
  NOTE: useradd-dep-1.0-r1: task do_populate_lic_setscene: Succeeded
  NOTE: useradd-dep-1.0-r1: task do_packagedata_setscene: Started
  NOTE: useradd-dep-1.0-r1: task do_packagedata_setscene: Succeeded
  NOTE: Running setscene task 3336 of 3783 (useradd-dep.bb:do_package_setscene)
  NOTE: Running setscene task 3337 of 3783 (useradd-dep.bb:do_populate_sysroot_setscene)
  NOTE: useradd-dep-1.0-r1: task do_package_setscene: Started
  NOTE: useradd-dep-1.0-r1: task do_populate_sysroot_setscene: Started
  ERROR: useradd-dep-1.0-r1 do_package_setscene: useradd-dep: useradd command did not succeed.
  ERROR: useradd-dep-1.0-r1 do_package_setscene: Error executing a python function in exec_python_func() autogenerated:
  ...
  Exception: bb.process.ExecutionError: Execution of 'useradd-dep/1.0-r1/temp/run.useradd_sysroot.8980' failed with exit code 1:
    useradd-dep/1.0-r1/recipe-sysroot-native/usr/sbin/useradd
    Running useradd commands...
    useradd: Warning: missing or non-executable shell '/bin/bash'
    useradd: group 'group1' does not exist
    WARNING: exit code 1 from a shell command.
  ...
  WARNING: Setscene task (useradd-dep.bb:do_package_setscene) failed with exit code '1' - real task will be run instead

  NOTE: Running setscene task 3347 of 3783 (useradd-example.bb:do_packagedata_setscene)
  NOTE: Running setscene task 3348 of 3783 (useradd-example.bb:do_populate_sysroot_setscene)
  NOTE: recipe useradd-example-1.0-r1: task do_packagedata_setscene: Started
  NOTE: recipe useradd-example-1.0-r1: task do_populate_sysroot_setscene: Started
  NOTE: recipe useradd-example-1.0-r1: task do_packagedata_setscene: Succeeded
  NOTE: Running setscene task 3358 of 3783 (useradd-example.bb:do_package_setscene)
  NOTE: recipe useradd-example-1.0-r1: task do_populate_sysroot_setscene: Succeeded
  NOTE: recipe useradd-example-1.0-r1: task do_package_setscene: Started
  NOTE: recipe useradd-example-1.0-r1: task do_package_setscene: Succeeded

  and then the real task works fine.

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 .../recipes-skeleton/useradd/useradd-dep.bb   | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb

Patch hide | download patch | download mbox

diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb b/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
new file mode 100644
index 0000000000..b5cbc5d170
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
@@ -0,0 +1,39 @@ 
+SUMMARY = "Example recipe for using inherit useradd and reusing group from useradd-example"
+DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
+SECTION = "examples"
+PR = "r1"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+S = "${WORKDIR}"
+
+EXCLUDE_FROM_WORLD = "1"
+
+inherit useradd
+
+# https://www.openembedded.org/pipermail/bitbake-devel/2018-March/009256.html
+# says that RDEPENDS_${PN} should be enough, but in my testing we need
+# built time dependency as well for groups to exist early enough
+DEPENDS = "useradd-example"
+
+RDEPENDS_${PN} = "useradd-example"
+RDEPENDS_${PN}-user3 = "useradd-example-user3"
+
+# You must set USERADD_PACKAGES when you inherit useradd. This
+# lists which output packages will include the user/group
+# creation code.
+USERADD_PACKAGES = "${PN} ${PN}-user3"
+
+# USERADD_PARAM specifies command line options to pass to the
+# useradd command. Multiple users can be created by separating
+# the commands with a semicolon. Here we'll create two users,
+# user1 and user2:
+USERADD_PARAM_${PN} = "-u 2200 -d /home/user1dep -r -s /bin/bash -G group1 user1dep; -u 2201 -d /home/user2dep -r -s /bin/bash -G group2 user2dep"
+
+# user3 will be managed in the useradd-example-user3 pacakge:
+# As an example, we use the -P option to set clear text password for user3
+USERADD_PARAM_${PN}-user3 = "-u 2202 -d /home/user3dep -r -s /bin/bash -P 'user3' -G group3 user3dep"
+
+# Prevents do_package failures with:
+# debugsources.list: No such file or directory:
+INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

Comments

Martin Jansa Oct. 10, 2020, 1:51 p.m.
This seems to be the same as
https://bugzilla.yoctoproject.org/show_bug.cgi?id=13904

On Fri, Oct 9, 2020 at 3:16 PM Martin Jansa <martin.jansa@gmail.com> wrote:

> * maybe this would be better in meta-selftest, I can move it there
>   once we agree how this is supposed to work
>
> *
> https://www.openembedded.org/pipermail/bitbake-devel/2018-March/009256.html
>   says that RDEPENDS_${PN} should be enough, but in my testing we need
>   built time dependency as well for groups to exist early enough
>
> * and unfortunately even with the "useradd dependency" in DEPENDS is see
>   very rare failures (in dunfell but I haven't found any changes in this
> area
>   in master) when useradd-dep and useradd-example are reused from sstate.
>
>   In these cases I've noticed that useradd-dep.do_package_setscene is
> running before useradd-example.do_package_setscene:
>
>   NOTE: Running setscene task 268 of 3783 (useradd-dep.bb:
> do_package_write_ipk_setscene)
>   NOTE: Running setscene task 269 of 3783 (useradd-dep.bb:
> do_populate_lic_setscene)
>   NOTE: useradd-dep-1.0-r1: task do_package_write_ipk_setscene: Started
>   NOTE: useradd-dep-1.0-r1: task do_populate_lic_setscene: Started
>   NOTE: useradd-dep-1.0-r1: task do_package_write_ipk_setscene: Succeeded
>   NOTE: Running setscene task 279 of 3783 (useradd-dep.bb:
> do_packagedata_setscene)
>   NOTE: useradd-dep-1.0-r1: task do_populate_lic_setscene: Succeeded
>   NOTE: useradd-dep-1.0-r1: task do_packagedata_setscene: Started
>   NOTE: useradd-dep-1.0-r1: task do_packagedata_setscene: Succeeded
>   NOTE: Running setscene task 3336 of 3783 (useradd-dep.bb:
> do_package_setscene)
>   NOTE: Running setscene task 3337 of 3783 (useradd-dep.bb:
> do_populate_sysroot_setscene)
>   NOTE: useradd-dep-1.0-r1: task do_package_setscene: Started
>   NOTE: useradd-dep-1.0-r1: task do_populate_sysroot_setscene: Started
>   ERROR: useradd-dep-1.0-r1 do_package_setscene: useradd-dep: useradd
> command did not succeed.
>   ERROR: useradd-dep-1.0-r1 do_package_setscene: Error executing a python
> function in exec_python_func() autogenerated:
>   ...
>   Exception: bb.process.ExecutionError: Execution of
> 'useradd-dep/1.0-r1/temp/run.useradd_sysroot.8980' failed with exit code 1:
>     useradd-dep/1.0-r1/recipe-sysroot-native/usr/sbin/useradd
>     Running useradd commands...
>     useradd: Warning: missing or non-executable shell '/bin/bash'
>     useradd: group 'group1' does not exist
>     WARNING: exit code 1 from a shell command.
>   ...
>   WARNING: Setscene task (useradd-dep.bb:do_package_setscene) failed with
> exit code '1' - real task will be run instead
>
>   NOTE: Running setscene task 3347 of 3783 (useradd-example.bb:
> do_packagedata_setscene)
>   NOTE: Running setscene task 3348 of 3783 (useradd-example.bb:
> do_populate_sysroot_setscene)
>   NOTE: recipe useradd-example-1.0-r1: task do_packagedata_setscene:
> Started
>   NOTE: recipe useradd-example-1.0-r1: task do_populate_sysroot_setscene:
> Started
>   NOTE: recipe useradd-example-1.0-r1: task do_packagedata_setscene:
> Succeeded
>   NOTE: Running setscene task 3358 of 3783 (useradd-example.bb:
> do_package_setscene)
>   NOTE: recipe useradd-example-1.0-r1: task do_populate_sysroot_setscene:
> Succeeded
>   NOTE: recipe useradd-example-1.0-r1: task do_package_setscene: Started
>   NOTE: recipe useradd-example-1.0-r1: task do_package_setscene: Succeeded
>
>   and then the real task works fine.
>
> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
> ---
>  .../recipes-skeleton/useradd/useradd-dep.bb   | 39 +++++++++++++++++++
>  1 file changed, 39 insertions(+)
>  create mode 100644 meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
>
> diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
> b/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
> new file mode 100644
> index 0000000000..b5cbc5d170
> --- /dev/null
> +++ b/meta-skeleton/recipes-skeleton/useradd/useradd-dep.bb
> @@ -0,0 +1,39 @@
> +SUMMARY = "Example recipe for using inherit useradd and reusing group
> from useradd-example"
> +DESCRIPTION = "This recipe serves as an example for using features from
> useradd.bbclass"
> +SECTION = "examples"
> +PR = "r1"
> +LICENSE = "MIT"
> +LIC_FILES_CHKSUM =
> "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
> +
> +S = "${WORKDIR}"
> +
> +EXCLUDE_FROM_WORLD = "1"
> +
> +inherit useradd
> +
> +#
> https://www.openembedded.org/pipermail/bitbake-devel/2018-March/009256.html
> +# says that RDEPENDS_${PN} should be enough, but in my testing we need
> +# built time dependency as well for groups to exist early enough
> +DEPENDS = "useradd-example"
> +
> +RDEPENDS_${PN} = "useradd-example"
> +RDEPENDS_${PN}-user3 = "useradd-example-user3"
> +
> +# You must set USERADD_PACKAGES when you inherit useradd. This
> +# lists which output packages will include the user/group
> +# creation code.
> +USERADD_PACKAGES = "${PN} ${PN}-user3"
> +
> +# USERADD_PARAM specifies command line options to pass to the
> +# useradd command. Multiple users can be created by separating
> +# the commands with a semicolon. Here we'll create two users,
> +# user1 and user2:
> +USERADD_PARAM_${PN} = "-u 2200 -d /home/user1dep -r -s /bin/bash -G
> group1 user1dep; -u 2201 -d /home/user2dep -r -s /bin/bash -G group2
> user2dep"
> +
> +# user3 will be managed in the useradd-example-user3 pacakge:
> +# As an example, we use the -P option to set clear text password for user3
> +USERADD_PARAM_${PN}-user3 = "-u 2202 -d /home/user3dep -r -s /bin/bash -P
> 'user3' -G group3 user3dep"
> +
> +# Prevents do_package failures with:
> +# debugsources.list: No such file or directory:
> +INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
> --
> 2.25.1
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#143206): https://lists.openembedded.org/g/openembedded-core/message/143206
Mute This Topic: https://lists.openembedded.org/mt/77403697/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-