diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2018-06-26 05:51:02 -0700 |
---|---|---|
committer | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2018-06-26 14:51:02 +0200 |
commit | a48bdfaf1d5c9c02f50e2fa8b8410b94ad8d29e8 (patch) | |
tree | 56883ec67df8eb6d330ab2b34e1da76809b561d9 /lib | |
parent | bdd5aab8be37d53090190ae1d4f12f49d09e0fb3 (diff) | |
download | spack-a48bdfaf1d5c9c02f50e2fa8b8410b94ad8d29e8.tar.gz spack-a48bdfaf1d5c9c02f50e2fa8b8410b94ad8d29e8.tar.bz2 spack-a48bdfaf1d5c9c02f50e2fa8b8410b94ad8d29e8.tar.xz spack-a48bdfaf1d5c9c02f50e2fa8b8410b94ad8d29e8.zip |
bugfix: fix macos incompatibility in lock test (#8573)
- Spack was assuming that a group with gid == current uid would always exist.
- This was breaking the travis build for macos.
- also fix issue with the DB tarball test finding coverage filesx
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 17 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/debug.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/test/llnl/util/lock.py | 25 |
3 files changed, 29 insertions, 16 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index cc15bd924f..b2591c2cf6 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -27,8 +27,10 @@ import errno import hashlib import fileinput import glob +import grp import numbers import os +import pwd import re import shutil import stat @@ -212,6 +214,21 @@ def set_install_permissions(path): os.chmod(path, 0o644) +def group_ids(uid=None): + """Get group ids that a uid is a member of. + + Arguments: + uid (int): id of user, or None for current user + + Returns: + (list of int): gids of groups the user is a member of + """ + if uid is None: + uid = os.getuid() + user = pwd.getpwuid(uid).pw_name + return [g.gr_gid for g in grp.getgrall() if user in g.gr_mem] + + def copy_mode(src, dest): """Set the mode of dest to that of src unless it is a link. """ diff --git a/lib/spack/spack/test/cmd/debug.py b/lib/spack/spack/test/cmd/debug.py index 76c81eb5a5..fe9d57a9c5 100644 --- a/lib/spack/spack/test/cmd/debug.py +++ b/lib/spack/spack/test/cmd/debug.py @@ -35,8 +35,9 @@ def test_create_db_tarball(tmpdir, database): with tmpdir.as_cwd(): debug('create-db-tarball') + # get the first non-dotfile to avoid coverage files in the directory files = os.listdir(os.getcwd()) - tarball_name = files[0] + tarball_name = next(f for f in files if not f.startswith('.')) # debug command made an archive assert os.path.exists(tarball_name) diff --git a/lib/spack/spack/test/llnl/util/lock.py b/lib/spack/spack/test/llnl/util/lock.py index c279d7e918..0060bc9273 100644 --- a/lib/spack/spack/test/llnl/util/lock.py +++ b/lib/spack/spack/test/llnl/util/lock.py @@ -72,10 +72,9 @@ from multiprocessing import Process import pytest -from llnl.util.filesystem import touch +from llnl.util.filesystem import touch, group_ids import spack.util.lock -from spack.util.executable import which from spack.util.multiproc import Barrier from spack.util.lock import Lock, WriteTransaction, ReadTransaction, LockError @@ -936,14 +935,16 @@ def test_disable_locking(private_lock_path): def test_lock_checks_user(tmpdir): - """Ensure lock checks work.""" - path = str(tmpdir) + """Ensure lock checks work with a self-owned, self-group repo.""" uid = os.getuid() + if uid not in group_ids(): + pytest.skip("user has no group with gid == uid") # self-owned, own group tmpdir.chown(uid, uid) # safe + path = str(tmpdir) tmpdir.chmod(0o744) spack.util.lock.check_lock_safety(path) @@ -966,23 +967,17 @@ def test_lock_checks_user(tmpdir): def test_lock_checks_group(tmpdir): - path = str(tmpdir) + """Ensure lock checks work with a self-owned, non-self-group repo.""" uid = os.getuid() - - id_cmd = which('id') - if not id_cmd: - pytest.skip("Can't determine user's groups.") - - # find a legal gid to user that is NOT the user's uid - gids = [int(gid) for gid in id_cmd('-G', output=str).split(' ')] - gid = next((g for g in gids if g != uid), None) - if gid is None: - pytest.skip("Can't determine user's groups.") + gid = next((g for g in group_ids() if g != uid), None) + if not gid: + pytest.skip("user has no group with gid != uid") # self-owned, another group tmpdir.chown(uid, gid) # safe + path = str(tmpdir) tmpdir.chmod(0o744) spack.util.lock.check_lock_safety(path) |