Skip to content

Commit

Permalink
fix(forknet): Fix the state parts bucket cleanup logic (#12712)
Browse files Browse the repository at this point in the history
Allow `reset` command to run without `--gcs...` parameter.
```
mirror reset --backup-id start --yes        
Traceback (most recent call last):                                                                                                                                                                                  
  File "/Users/razvan/repos/nearcore/pytest/tests/mocknet/mirror.py", line 772, in <module>                                                                                                                         
    args.func(args, traffic_generator, wanted_nodes)                                                      
  File "/Users/razvan/repos/nearcore/pytest/tests/mocknet/mirror.py", line 381, in reset_cmd
    _clear_state_parts_if_exists(_get_state_parts_location(args), nodes)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                          
  File "/Users/razvan/repos/nearcore/pytest/tests/mocknet/mirror.py", line 280, in _get_state_parts_location
    if args.gcs_state_sync:                                                                               
       ^^^^^^^^^^^^^^^^^^^                       
AttributeError: 'Namespace' object has no attribute 'gcs_state_sync'
```
  • Loading branch information
VanBarbascu authored Jan 13, 2025
1 parent 8190923 commit 71f8ed3
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions pytest/tests/mocknet/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def _clear_state_parts_if_exists(location, nodes):
if location is None:
return

state_dumper_node = next(filter(lambda n: n.want_state_dump, nodes), None)
if state_dumper_node is None:
logger.info('No state dumper node found, skipping state parts cleanup.')
return
logger.info('State dumper node found, cleaning up state parts.')

if location.get('Filesystem') is not None:
root_dir = location['Filesystem']['root_dir']
shutil.rmtree(root_dir)
Expand All @@ -253,13 +259,7 @@ def _clear_state_parts_if_exists(location, nodes):
# bucket where it dumped the parts.
bucket_name = location['GCS']['bucket']

state_dumper_node = next(filter(lambda n: n.want_state_dump, nodes), None)
if state_dumper_node is None:
logger.info('No state dumper node found, skipping state parts cleanup.')
return

logger.info('State dumper node found, cleaning up state parts.')
state_dumper_node.run_cmd(f'gsutil -m rm -r gs://{bucket_name}/chain_id=\*',
state_dumper_node.run_cmd(f'gsutil -m rm -r gs://{bucket_name}/chain_id=*',
return_on_fail=True)


Expand All @@ -276,11 +276,7 @@ def _get_state_parts_location(args):
'state-parts')
}
}
else:
if args.gcs_state_sync:
return {"GCS": {"bucket": _get_state_parts_bucket_name(args)}}
else:
return None
return {"GCS": {"bucket": _get_state_parts_bucket_name(args)}}


def new_test_cmd(args, traffic_generator, nodes):
Expand Down Expand Up @@ -320,7 +316,9 @@ def new_test_cmd(args, traffic_generator, nodes):
args.genesis_protocol_version,
genesis_time=genesis_time), targeted)

location = _get_state_parts_location(args)
location = None
if args.gcs_state_sync:
location = _get_state_parts_location(args)
logger.info('Applying default config changes')
pmap(lambda node: _apply_config_changes(node, location), targeted)

Expand Down Expand Up @@ -624,7 +622,12 @@ def __call__(self, parser, namespace, values, option_string=None):
new_test_parser.add_argument('--new-chain-id', type=str)
new_test_parser.add_argument('--genesis-protocol-version', type=int)
new_test_parser.add_argument('--stateless-setup', action='store_true')
new_test_parser.add_argument('--gcs-state-sync', action='store_true')
new_test_parser.add_argument(
'--gcs-state-sync',
action='store_true',
help=
"""Enable state dumper nodes to sync state to GCS. On localtest, it will dump locally."""
)
new_test_parser.add_argument('--yes', action='store_true')
new_test_parser.set_defaults(func=new_test_cmd)

Expand Down

0 comments on commit 71f8ed3

Please sign in to comment.