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
This commit is contained in:
parent
bdd5aab8be
commit
a48bdfaf1d
3 changed files with 29 additions and 16 deletions
|
@ -27,8 +27,10 @@
|
|||
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.
|
||||
"""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -72,10 +72,9 @@
|
|||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue