Skip to content

Commit a1c51b6

Browse files
committed
Fix firewall migrate
1 parent 364d48c commit a1c51b6

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

node_cli/migrations/mirage/from_boot.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,47 @@
33
import os
44
from pathlib import Path
55

6+
from node_cli.core.docker_config import restart_docker_service
67
from node_cli.utils.helper import run_cmd
78

89
logger = logging.getLogger(__name__)
910

1011
NFT_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

1415
class 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

2649
def reload_nft():
@@ -29,6 +52,8 @@ def reload_nft():
2952

3053
def 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()

node_cli/operations/mirage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MirageUpdateType(Enum):
6060
@checked_host
6161
def update_mirage(env_filepath: str, env: dict, update_type: MirageUpdateType) -> bool:
6262
compose_rm(node_type=NodeType.MIRAGE, env=env)
63-
if update_type in (MirageUpdateType.INFRA_ONLY, MirageUpdateType.FROM_BOOT):
63+
if update_type not in (MirageUpdateType.INFRA_ONLY, MirageUpdateType.FROM_BOOT):
6464
remove_dynamic_containers()
6565

6666
sync_skale_node()

0 commit comments

Comments
 (0)