public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2 1/2] fix group splitting in user creation
@ 2023-07-27  3:24 Felix Moessbauer
  2023-07-27  3:24 ` [PATCH v2 2/2] add unit test for user creation with groups Felix Moessbauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Moessbauer @ 2023-07-27  3:24 UTC (permalink / raw)
  To: isar-users; +Cc: tobias.schaffner, Felix Moessbauer

There is a bug when converting the USER_<foo>[groups] configuration
from the bitbake format (space separated) to the format useradd
expects (comma separated). We cannot simply replace spaces with commas,
as then multiple spaces in a row would create multiple commas. Instead,
we need to split it first into the tokens and then join these tokens by
comma.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/image-account-extension.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/meta/classes/image-account-extension.bbclass b/meta/classes/image-account-extension.bbclass
index e783c135..6f67f459 100644
--- a/meta/classes/image-account-extension.bbclass
+++ b/meta/classes/image-account-extension.bbclass
@@ -98,10 +98,10 @@ def image_create_users(d: "DataSmart") -> None:
         add_user_option("--comment", "comment")
         add_user_option("--shell", "shell")
 
-        groups = d.getVarFlag(user_entry, "groups") or ""
+        groups = (d.getVarFlag(user_entry, "groups") or "").split()
         if groups:
             args.append("--groups")
-            args.append(groups.replace(' ', ','))
+            args.append(','.join(groups))
 
         flags = (d.getVarFlag(user_entry, "flags") or "").split()
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] add unit test for user creation with groups
  2023-07-27  3:24 [PATCH v2 1/2] fix group splitting in user creation Felix Moessbauer
@ 2023-07-27  3:24 ` Felix Moessbauer
  2023-08-01  7:21 ` [PATCH v2 1/2] fix group splitting in user creation Schaffner, Tobias
  2023-08-02 21:31 ` Uladzimir Bely
  2 siblings, 0 replies; 4+ messages in thread
From: Felix Moessbauer @ 2023-07-27  3:24 UTC (permalink / raw)
  To: isar-users; +Cc: tobias.schaffner, Felix Moessbauer

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 testsuite/unittests/test_image_account_extension.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/testsuite/unittests/test_image_account_extension.py b/testsuite/unittests/test_image_account_extension.py
index b7ad0c5c..08021a4a 100644
--- a/testsuite/unittests/test_image_account_extension.py
+++ b/testsuite/unittests/test_image_account_extension.py
@@ -39,12 +39,15 @@ class TestImageAccountExtensionImageCreateUsers(TestImageAccountExtensionCommon)
     def test_new_user(self):
         test_user = "new"
         d, rootfs = self.setup(test_user)
+        # make the list a bit clumsy to simulate appends and removals to that var
+        d.setVarFlag('USER_{}'.format(test_user), 'groups', 'dialout render  foo ')
 
         with patch.object(bb.process, "run") as run_mock:
             image_create_users(d)
 
         run_mock.assert_called_once_with(
-            ["sudo", "-E", "chroot", rootfs.path(), "/usr/sbin/useradd", test_user])
+            ["sudo", "-E", "chroot", rootfs.path(), "/usr/sbin/useradd",
+             '--groups', 'dialout,render,foo', test_user])
 
     def test_existing_user_no_change(self):
         test_user = "test"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] fix group splitting in user creation
  2023-07-27  3:24 [PATCH v2 1/2] fix group splitting in user creation Felix Moessbauer
  2023-07-27  3:24 ` [PATCH v2 2/2] add unit test for user creation with groups Felix Moessbauer
@ 2023-08-01  7:21 ` Schaffner, Tobias
  2023-08-02 21:31 ` Uladzimir Bely
  2 siblings, 0 replies; 4+ messages in thread
From: Schaffner, Tobias @ 2023-08-01  7:21 UTC (permalink / raw)
  To: MOESSBAUER, FELIX JONATHAN, isar-users

On 27.07.23 05:24, MOESSBAUER, Felix (T CED INW-CN) wrote:
> There is a bug when converting the USER_<foo>[groups] configuration
> from the bitbake format (space separated) to the format useradd
> expects (comma separated). We cannot simply replace spaces with commas,
> as then multiple spaces in a row would create multiple commas. Instead,
> we need to split it first into the tokens and then join these tokens by
> comma.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>   meta/classes/image-account-extension.bbclass | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/image-account-extension.bbclass b/meta/classes/image-account-extension.bbclass
> index e783c135..6f67f459 100644
> --- a/meta/classes/image-account-extension.bbclass
> +++ b/meta/classes/image-account-extension.bbclass
> @@ -98,10 +98,10 @@ def image_create_users(d: "DataSmart") -> None:
>           add_user_option("--comment", "comment")
>           add_user_option("--shell", "shell")
>   
> -        groups = d.getVarFlag(user_entry, "groups") or ""
> +        groups = (d.getVarFlag(user_entry, "groups") or "").split()
>           if groups:
>               args.append("--groups")
> -            args.append(groups.replace(' ', ','))
> +            args.append(','.join(groups))
>   
>           flags = (d.getVarFlag(user_entry, "flags") or "").split()
>   

Acked-by: Tobias Schaffner <tobias.schaffner@siemens.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] fix group splitting in user creation
  2023-07-27  3:24 [PATCH v2 1/2] fix group splitting in user creation Felix Moessbauer
  2023-07-27  3:24 ` [PATCH v2 2/2] add unit test for user creation with groups Felix Moessbauer
  2023-08-01  7:21 ` [PATCH v2 1/2] fix group splitting in user creation Schaffner, Tobias
@ 2023-08-02 21:31 ` Uladzimir Bely
  2 siblings, 0 replies; 4+ messages in thread
From: Uladzimir Bely @ 2023-08-02 21:31 UTC (permalink / raw)
  To: Felix Moessbauer, isar-users; +Cc: tobias.schaffner

On Thu, 2023-07-27 at 03:24 +0000, 'Felix Moessbauer' via isar-users
wrote:
> There is a bug when converting the USER_<foo>[groups] configuration
> from the bitbake format (space separated) to the format useradd
> expects (comma separated). We cannot simply replace spaces with
> commas,
> as then multiple spaces in a row would create multiple commas.
> Instead,
> we need to split it first into the tokens and then join these tokens
> by
> comma.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta/classes/image-account-extension.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/image-account-extension.bbclass
> b/meta/classes/image-account-extension.bbclass
> index e783c135..6f67f459 100644
> --- a/meta/classes/image-account-extension.bbclass
> +++ b/meta/classes/image-account-extension.bbclass
> @@ -98,10 +98,10 @@ def image_create_users(d: "DataSmart") -> None:
>          add_user_option("--comment", "comment")
>          add_user_option("--shell", "shell")
>  
> -        groups = d.getVarFlag(user_entry, "groups") or ""
> +        groups = (d.getVarFlag(user_entry, "groups") or "").split()
>          if groups:
>              args.append("--groups")
> -            args.append(groups.replace(' ', ','))
> +            args.append(','.join(groups))
>  
>          flags = (d.getVarFlag(user_entry, "flags") or "").split()
>  
> -- 
> 2.34.1
> 

Series applied to next, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-02 21:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27  3:24 [PATCH v2 1/2] fix group splitting in user creation Felix Moessbauer
2023-07-27  3:24 ` [PATCH v2 2/2] add unit test for user creation with groups Felix Moessbauer
2023-08-01  7:21 ` [PATCH v2 1/2] fix group splitting in user creation Schaffner, Tobias
2023-08-02 21:31 ` Uladzimir Bely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox