3333from mig .shared .fileio import pickle , read_file
3434from mig .shared .vgrid import vgrid_list , vgrid_set_entities , vgrid_settings
3535from mig .shared .vgridaccess import CONF , MEMBERS , OWNERS , RESOURCES , SETTINGS , \
36- USERID , VGRIDS , check_resources_modified , check_vgrid_access , \
36+ USERID , USERS , VGRIDS , check_resources_modified , check_vgrid_access , \
3737 check_vgrids_modified , fill_placeholder_cache , force_update_resource_map , \
3838 force_update_user_map , force_update_vgrid_map , get_re_provider_map , \
3939 get_resource_map , get_user_map , get_vgrid_map , get_vgrid_map_vgrids , \
40- is_vgrid_parent_placeholder , load_resource_map , load_user_map , \
41- load_vgrid_map , mark_vgrid_modified , refresh_resource_map , \
42- refresh_user_map , refresh_vgrid_map , res_vgrid_access , \
43- reset_resources_modified , reset_vgrids_modified , resources_using_re , \
44- unmap_inheritance , unmap_resource , unmap_vgrid , user_allowed_res_confs , \
45- user_allowed_res_exes , user_allowed_res_stores , user_allowed_res_units , \
46- user_allowed_user_confs , user_owned_res_exes , user_owned_res_stores , \
47- user_vgrid_access , user_visible_res_confs , user_visible_res_exes , \
48- user_visible_res_stores , user_visible_user_confs , vgrid_inherit_map
40+ is_vgrid_parent_placeholder , last_load , last_map , last_refresh , \
41+ load_resource_map , load_user_map , load_vgrid_map , mark_vgrid_modified , \
42+ refresh_resource_map , refresh_user_map , refresh_vgrid_map , \
43+ res_vgrid_access , reset_resources_modified , reset_vgrids_modified , \
44+ resources_using_re , unmap_inheritance , unmap_resource , unmap_vgrid , \
45+ user_allowed_res_confs , user_allowed_res_exes , user_allowed_res_stores , \
46+ user_allowed_res_units , user_allowed_user_confs , user_owned_res_exes , \
47+ user_owned_res_stores , user_vgrid_access , user_visible_res_confs , \
48+ user_visible_res_exes , user_visible_res_stores , user_visible_user_confs , \
49+ vgrid_inherit_map
4950from tests .support import MigTestCase , ensure_dirs_exist , testmain
5051
5152
@@ -126,8 +127,15 @@ def _create_resource(self, res_name, owners, config=None):
126127 saved = pickle (config , res_config_path , self .logger )
127128 self .assertTrue (saved )
128129
130+ def _reset_caches (self ):
131+ """Assure all vgrid maps and stamps are wiped for next test"""
132+ for field in (USERS , RESOURCES , VGRIDS ):
133+ last_refresh [field ] = 0
134+ last_load [field ] = 0
135+ last_map [field ].clear ()
136+
129137 def before_each (self ):
130- """Create test environment for vgridaccess tests"""
138+ """Create clean test environment for vgridaccess tests"""
131139 used_state_dirs = [
132140 self .configuration .mig_system_files ,
133141 self .configuration .mig_system_run ,
@@ -139,15 +147,42 @@ def before_each(self):
139147 for state_dir in used_state_dirs :
140148 ensure_dirs_exist (state_dir )
141149
150+ # Drop all caches and state between tests
151+ self ._reset_caches ()
152+
153+ # Make sure we start with a clean slate for each test
154+ for field in (USERS , RESOURCES , VGRIDS ):
155+ self .assertTrue (last_refresh [field ] == 0 )
156+ self .assertTrue (last_load [field ] == 0 )
157+ self .assertEqual (last_map [field ], {})
158+
142159 # IMPORTANT: don't use refresh_X here as it does not reset last_X cache
143160 # Start with minimal maps and corresponding cache - only default vgrid
144161 vgrid_map = force_update_vgrid_map (self .configuration )
145162 self .assertEqual (vgrid_map .get (VGRIDS , {}), self .MINIMAL_VGRIDS )
163+
164+ # Make sure all vgrid map entries are complete
165+ for vgrid_name in vgrid_map .get (VGRIDS , {}):
166+ for field in (OWNERS , MEMBERS , SETTINGS , RESOURCES ):
167+ vgrid_entry = vgrid_map [VGRIDS ][vgrid_name ]
168+ self .assertIn (field , vgrid_entry )
169+
146170 res_map = force_update_resource_map (self .configuration )
171+ # Make sure no resource map entries exist initially
147172 self .assertEqual (res_map , {})
173+
148174 user_map = force_update_user_map (self .configuration )
175+ # Make sure no user map entries exist initially
149176 self .assertEqual (user_map , {})
150177
178+ # Make sure accounting and caching entries are consistent and complete
179+ for field in (USERS , RESOURCES , VGRIDS ):
180+ self .assertTrue (last_refresh [field ] > 0 )
181+ self .assertTrue (last_load [field ] > 0 )
182+ self .assertEqual (vgrid_map , last_map [VGRIDS ])
183+ self .assertEqual (res_map , last_map [RESOURCES ])
184+ self .assertEqual (user_map , last_map [USERS ])
185+
151186 def test_force_update_user_map (self ):
152187 """Simple test that user map refresh completes"""
153188 # Verify empty map on init
0 commit comments