Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a651b4c
Fundamental test coverage of vgridaccess.py.
jonasbardino Oct 22, 2025
dda151d
Sort imports and remove debug.
jonasbardino Oct 22, 2025
f916030
Extend coverage of vgridaccess.py module.
jonasbardino Oct 23, 2025
ab69337
Increase coverage.
jonasbardino Oct 23, 2025
977af0a
Add better coverage of fundamental function use and clean up some unn…
jonasbardino Oct 23, 2025
ab00245
Make sure resources are provisioned with a valid minimal conf to get …
jonasbardino Oct 23, 2025
ee2837f
Add a few more very basic tests.
jonasbardino Oct 23, 2025
ae30422
Tweak dummy user provisioning a bit more to pick up more samples in t…
jonasbardino Oct 23, 2025
1030730
More or less completed basic function use coverage. Clean up some red…
jonasbardino Oct 23, 2025
7bbd02b
Removed inadvertently duplicated test functions.
jonasbardino Oct 23, 2025
d060e80
Consistency fixes across the board.
jonasbardino Oct 24, 2025
188e4b8
Introduce thorough cleaning of cache map and stamps in between tests …
jonasbardino Nov 2, 2025
9443b77
Go one step further to assure vgridaccess cache maps and stamps reall…
jonasbardino Nov 2, 2025
a664e9d
Another level ofassurance that tests don't have stale data and that a…
jonasbardino Nov 2, 2025
85adb30
Use assertIn helper to test for key or entry in list or dicts. More s…
jonasbardino Nov 2, 2025
b5a0ae2
More integrity self-checks.
jonasbardino Nov 2, 2025
96c4f88
Pull in PR #380 to see if that fixes the spurious CI test failures as
jonasbardino Nov 2, 2025
5d825fd
Minor docstring adjustments to fit tested function.
jonasbardino Nov 2, 2025
3b23550
It looks like the initial PR #380 adjustment to `VGRIDS` update loop …
jonasbardino Nov 2, 2025
8d8de65
Comment-only change to explain the implicit resource assignment to Ge…
jonasbardino Nov 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions mig/shared/vgridaccess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)

Check warning on line 23 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -48,7 +48,7 @@
from mig.shared.resource import list_resources, real_to_anon_res_map
from mig.shared.serial import load, dump
from mig.shared.user import list_users, real_to_anon_user_map, get_user_conf
from mig.shared.vgrid import vgrid_list_vgrids, vgrid_allowed, vgrid_resources, \

Check warning on line 51 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)

Check warning on line 51 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
user_allowed_vgrids, vgrid_owners, vgrid_members, vgrid_settings, \
vgrid_list_subvgrids, vgrid_list_parents, res_allowed_vgrids, \
merge_vgrid_settings
Expand All @@ -72,7 +72,7 @@

last_refresh = {USERS: 0, RESOURCES: 0, VGRIDS: 0}
last_load = {USERS: 0, RESOURCES: 0, VGRIDS: 0}
last_map = {USERS: {}, RESOURCES: {}, VGRIDS: {}}

Check failure on line 75 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Need type annotation for "last_map" [var-annotated]

Check failure on line 75 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Need type annotation for "last_map" [var-annotated]


def load_entity_map(configuration, kind, do_lock, caching):
Expand Down Expand Up @@ -159,7 +159,7 @@
lock_path = os.path.join(real_base, "%s.lock" % kind)
map_helpers = {'user': load_user_map, 'resource': load_resource_map,
'vgrid': load_vgrid_map}
if not kind in map_helpers:

Check warning on line 162 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 162 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
raise ValueError("invalid kind for load map: %s" % kind)
load_map = map_helpers[kind]
# NOTE: we need exclusive lock for the entire load and update process
Expand Down Expand Up @@ -277,7 +277,7 @@
dirty += [user]
# Remove any missing users from map
missing_user = [user for user in user_map
if not user in all_users]

Check warning on line 280 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 280 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
for user in missing_user:
del user_map[user]
dirty += [user]
Expand Down Expand Up @@ -345,7 +345,7 @@
dirty += [res]
# Remove any missing resources from map
missing_res = [res for res in resource_map
if not res in all_resources]

Check warning on line 348 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 348 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
for res in missing_res:
del resource_map[res]
dirty += [res]
Expand Down Expand Up @@ -401,18 +401,18 @@
optional_conf = [SETTINGS, ]

for vgrid in all_vgrids:
# Make sure vgrid dict exists before filling it
vgrid_map[VGRIDS][vgrid] = vgrid_map[VGRIDS].get(vgrid, {})
for (field, name, list_call) in conf_read:
conf_path = os.path.join(configuration.vgrid_home, vgrid, name)
if not os.path.isfile(conf_path):
# Make sure vgrid dict exists before filling it
vgrid_map[VGRIDS][vgrid] = vgrid_map[VGRIDS].get(vgrid, {})
vgrid_map[VGRIDS][vgrid][field] = []
if vgrid != default_vgrid and field not in optional_conf:
_logger.warning('missing file: %s' %
conf_path)
dirty[VGRIDS] = dirty.get(VGRIDS, []) + [vgrid]

elif vgrid not in vgrid_map[VGRIDS] or \
elif field not in vgrid_map[VGRIDS][vgrid] or \
os.path.getmtime(conf_path) >= map_stamp:
(status, entries) = list_call(vgrid, configuration,
recursive=False)
Expand All @@ -425,9 +425,11 @@
vgrid_map[VGRIDS][vgrid] = map_entry
vgrid_map[VGRIDS][vgrid][field] = entries
dirty[VGRIDS] = dirty.get(VGRIDS, []) + [vgrid]
else:
_logger.debug("caching %s for %s in vgrid map" % (name, vgrid))
# Remove any missing vgrids from map
missing_vgrids = [vgrid for vgrid in vgrid_map[VGRIDS]
if not vgrid in all_vgrids]

Check warning on line 432 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 432 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
for vgrid in missing_vgrids:
vgrid_changes[vgrid] = vgrid_changes.get(vgrid, {})
map_entry = vgrid_map[VGRIDS].get(vgrid, {})
Expand All @@ -449,7 +451,8 @@
conf_path = os.path.join(configuration.resource_home, res, "config")
if not os.path.isfile(conf_path):
continue
if os.path.getmtime(conf_path) >= map_stamp:
if res not in vgrid_map[RESOURCES] or \
os.path.getmtime(conf_path) >= map_stamp:
# Read maps of exe name to vgrid list and of store name to vgrid
# list. Save them separately to be able to distinguish them in
# exe / store access and visibility
Expand Down Expand Up @@ -488,7 +491,7 @@
dirty[RESOURCES] = dirty.get(RESOURCES, []) + [res]
# Remove any missing resources from map
missing_res = [res for res in vgrid_map[RESOURCES]
if not res in all_resources]

Check warning on line 494 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 494 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
for res in missing_res:
del vgrid_map[RESOURCES][res]
dirty[RESOURCES] = dirty.get(RESOURCES, []) + [res]
Expand Down Expand Up @@ -560,7 +563,7 @@
else:
conf_mtime = -1
user_conf = {}
if conf_mtime >= map_stamp:
if user not in vgrid_map[USERS] or conf_mtime >= map_stamp:
vgrid_map[USERS][user] = user_conf
vgrid_map[USERS][user][ASSIGN] = vgrid_map[USERS][user].get(ASSIGN,
[])
Expand All @@ -573,7 +576,7 @@
dirty[USERS] = dirty.get(USERS, []) + [user]
# Remove any missing users from map
missing_user = [user for user in vgrid_map[USERS]
if not user in all_users]

Check warning on line 579 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 579 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
for user in missing_user:
del vgrid_map[USERS][user]
dirty[USERS] = dirty.get(USERS, []) + [user]
Expand Down Expand Up @@ -668,7 +671,7 @@
for parent_name in parent_vgrid_list:
parent_vgrid = inherit_map[VGRIDS][parent_name]
for field in (OWNERS, MEMBERS, RESOURCES):
vgrid[field] += [i for i in parent_vgrid[field] if not i in

Check warning on line 674 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 674 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
vgrid[field]]
settings_list.append(dict(parent_vgrid.get(SETTINGS, [])))
settings_list.append(dict(vgrid.get(SETTINGS, [])))
Expand Down Expand Up @@ -708,7 +711,7 @@
}
}

if not key in map_helpers:

Check warning on line 714 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 714 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
raise ValueError("invalid entity last_X key: %s" % key)
helpers = map_helpers[key]
name = helpers['name']
Expand Down Expand Up @@ -853,7 +856,6 @@
the vgrid module and should replace that one everywhere that only vgrid map
(cached) lookups are needed.
"""
vgrid_access = [default_vgrid]
vgrid_map = get_vgrid_map(configuration, recursive, caching)
vgrid_entry = vgrid_map.get(VGRIDS, {}).get(
vgrid_name, {OWNERS: [], MEMBERS: []})
Expand Down Expand Up @@ -1258,10 +1260,10 @@
client_dir = real_path.replace(configuration.user_home, '')
client_dir = client_dir.lstrip(os.sep).split(os.sep, 1)[0]
client_id = client_dir_id(client_dir)
user_base = os.path.join(configuration.user_home, client_dir)

Check failure on line 1263 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_base' (60% confidence)

Check failure on line 1263 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_base' (60% confidence)
else:
client_dir = client_id_dir(client_id)
user_base = os.path.join(configuration.user_home, client_dir)

Check failure on line 1266 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_base' (60% confidence)

Check failure on line 1266 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_base' (60% confidence)

# Caching - build cache on first use and reuse from there
if isinstance(cache, dict):
Expand Down Expand Up @@ -1332,7 +1334,7 @@
mark_vgrid_modified(configuration, vgrid_name)


def unmap_inheritance(configuration, vgrid_name, cert_id):

Check failure on line 1337 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'cert_id' (100% confidence)

Check failure on line 1337 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'cert_id' (100% confidence)
"""Remove cert_id inherited access to all vgrid_name sub vgrids: Simply
force refresh of those vgrids as cert_id was never really there.
"""
Expand Down Expand Up @@ -1426,8 +1428,8 @@
print("%s owns: %s" %
(user_id, ', '.join(list(user_owned_confs))))
user_visible_confs = user_visible_res_confs(conf, user_id)
user_visible_exes = user_visible_res_exes(conf, user_id)

Check failure on line 1431 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_visible_exes' (60% confidence)

Check failure on line 1431 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_visible_exes' (60% confidence)
user_visible_stores = user_visible_res_stores(conf, user_id)

Check failure on line 1432 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_visible_stores' (60% confidence)

Check failure on line 1432 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_visible_stores' (60% confidence)
print("%s can view resources: %s" %
(user_id, ', '.join([i for i in user_visible_confs])))
# print "full access exe dicts for %s:\n%s\n%s\n%s" % \
Expand All @@ -1446,7 +1448,7 @@
print("inherited vgrid map vgrids: %s" % inherited_map[VGRIDS])

print("= testing in vgrid specials =")
cache = {}

Check failure on line 1451 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Need type annotation for "cache" (hint: "cache: Dict[<type>, <type>] = ...") [var-annotated]

Check failure on line 1451 in mig/shared/vgridaccess.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Need type annotation for "cache" (hint: "cache: Dict[<type>, <type>] = ...") [var-annotated]
client_dir = client_id_dir(user_id)
print("Testing with user home %r" % client_dir)
for path in ['.', './', 'welcome.txt', 'test', 'test/test'
Expand Down
Loading