33import os
44from pathlib import Path
55
6+ from node_cli .core .docker_config import restart_docker_service
67from node_cli .utils .helper import run_cmd
78
89logger = logging .getLogger (__name__ )
910
1011NFT_CHAIN_BASE_PATH = '/etc/nft.conf.d/skale/chains'
11- NFT_COMMITTEE_SCOPE_CHAIN_PATH = 'mirage-committee.conf '
12+ NFT_COMMITTEE_SCOPE_CHAIN_NAME = 'mirage-committee'
1213
1314
1415class NoLegacyNFTChainConfigError (Exception ):
1516 pass
1617
1718
18- def move_chain_to_new_name () -> None :
19+ def rename_chain_file (old_filepath : str , new_filepath : str ) -> None :
20+ old_path = Path (old_filepath )
21+ new_path = Path (new_filepath )
22+ if not old_path .exists ():
23+ raise NoLegacyNFTChainConfigError (f'File { old_filepath } does not exists' )
24+ old_path .rename (Path (new_path ))
25+
26+
27+ def rename_chain_in_config (config_path : str , old_chain_name : str , new_chain_name : str ) -> None :
28+ content = ''
29+ with open (config_path , 'r' ) as f :
30+ content = f .read ()
31+
32+ updated_content = content .replace (old_chain_name , new_chain_name )
33+
34+ with open (config_path , 'w' ) as f :
35+ f .write (updated_content )
36+
37+
38+ def migrate_nft_chain () -> None :
1939 after_boot_chain_path = glob .glob (os .path .join (NFT_CHAIN_BASE_PATH , '*' ))[0 ]
20- new_path = os .path .join (NFT_CHAIN_BASE_PATH , NFT_COMMITTEE_SCOPE_CHAIN_PATH )
21- if Path (after_boot_chain_path ).exists ():
22- raise NoLegacyNFTChainConfigError (f'File { after_boot_chain_path } does not exists' )
23- Path (after_boot_chain_path ).rename (Path (new_path ))
40+ old_chain_name = Path (after_boot_chain_path ).name .removesuffix ('.conf' )
41+ new_chain_name = NFT_COMMITTEE_SCOPE_CHAIN_NAME
42+ rename_chain_in_config (after_boot_chain_path , old_chain_name , new_chain_name )
43+ after_migration_chain_path = os .path .join (
44+ NFT_CHAIN_BASE_PATH , f'{ NFT_COMMITTEE_SCOPE_CHAIN_NAME } .conf'
45+ )
46+ rename_chain_file (after_boot_chain_path , after_migration_chain_path )
2447
2548
2649def reload_nft ():
@@ -29,6 +52,8 @@ def reload_nft():
2952
3053def migrate_nftables_from_boot ():
3154 logger .info ('Starting nftables migration from boot' )
32- move_chain_to_new_name ()
55+ migrate_nft_chain ()
3356 logger .info ('Reloading nftables rules' )
3457 reload_nft ()
58+ logger .info ('Restart docker service' )
59+ restart_docker_service ()
0 commit comments