summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <gamblin2@llnl.gov>2022-11-02 03:00:16 -0700
committerGitHub <noreply@github.com>2022-11-02 11:00:16 +0100
commita4d978be596829d006c50778179a2a497ec0f155 (patch)
tree35fe637377450203196ce5efd1ceaf2e010fb1d3 /lib
parent4bad9f9b1380e33499b6f8e06531898d8b7d679f (diff)
downloadspack-a4d978be596829d006c50778179a2a497ec0f155.tar.gz
spack-a4d978be596829d006c50778179a2a497ec0f155.tar.bz2
spack-a4d978be596829d006c50778179a2a497ec0f155.tar.xz
spack-a4d978be596829d006c50778179a2a497ec0f155.zip
tests: fix group membership check in sbang tests. (#33658)
Fixes an issue on the RHEL8 UBI container where this test would fail because `gr_mem` was empty for every entry in the `grp` DB. You have to check *both* the `pwd` database (which has primary groups) and `grp` (which has other gorups) to do this correctly. - [x] update `llnl.util.filesystem.group_ids()` to do this - [x] use it in the `sbang` test
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py11
-rw-r--r--lib/spack/spack/test/sbang.py6
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index fa1188c133..aece52f843 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -505,8 +505,15 @@ def group_ids(uid=None):
if uid is None:
uid = getuid()
- user = pwd.getpwuid(uid).pw_name
- return [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
+
+ pwd_entry = pwd.getpwuid(uid)
+ user = pwd_entry.pw_name
+
+ # user's primary group id may not be listed in grp (i.e. /etc/group)
+ # you have to check pwd for that, so start the list with that
+ gids = [pwd_entry.pw_gid]
+
+ return sorted(set(gids + [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]))
@system_path_filter(arg_slice=slice(1))
diff --git a/lib/spack/spack/test/sbang.py b/lib/spack/spack/test/sbang.py
index 18a408a549..876f3f4d0f 100644
--- a/lib/spack/spack/test/sbang.py
+++ b/lib/spack/spack/test/sbang.py
@@ -7,7 +7,6 @@
Test that Spack's shebang filtering works correctly.
"""
import filecmp
-import getpass
import os
import shutil
import stat
@@ -273,6 +272,9 @@ def configure_group_perms():
# and grp does not act on remote groups.
# To ensure we find a group we can operate on, we get take the first group
# listed which has the current user as a member.
+ gid = fs.group_ids(os.getuid())[0]
+ group_name = grp.getgrgid(gid).gr_name
+
conf = syaml.load_config(
"""\
all:
@@ -281,7 +283,7 @@ all:
write: group
group: {0}
""".format(
- [g.gr_name for g in grp.getgrall() if getpass.getuser() in g.gr_mem][0]
+ group_name
)
)
spack.config.set("packages", conf, scope="user")