Skip to content

Commit 856f956

Browse files
authored
Merge pull request #864 from skalenetwork/add-redis-conn
Drop node_cli.status. Use redis instead
2 parents b3b6846 + c3c4320 commit 856f956

25 files changed

Lines changed: 412 additions & 74 deletions

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ jobs:
7171
run: |
7272
scripts/build.sh test test normal
7373
74+
- name: Run redis
75+
run: |
76+
./helper-scripts/redis/run.sh
77+
7478
- name: Run tests
7579
run: |
7680
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python3/dist-packages/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,6 @@ test-env
122122
nginx.conf
123123
tests/.skale/node_data/docker.json
124124
tests/.skale/node_data/node_options.json
125-
tests/.skale/config/nginx.conf.j2
125+
tests/.skale/config/nginx.conf.j2
126+
127+
.zed

node_cli/cli/mirage_boot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import click
2121

2222
from node_cli.core.node import get_node_signature, register_node as register, get_node_info
23-
from node_cli.core.mirage_boot import init, migrate, update
23+
from node_cli.mirage.mirage_boot import init, migrate, update
2424
from node_cli.configs import DEFAULT_NODE_BASE_PORT
2525
from node_cli.utils.helper import streamed_cmd, IP_TYPE, error_exit, abort_if_false
2626

node_cli/cli/mirage_node.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import click
2121

2222
from node_cli.core.node import get_node_signature, backup, get_node_info
23-
from node_cli.core.mirage_node import restore_mirage
24-
from node_cli.utils.helper import error_exit, streamed_cmd, abort_if_false
23+
from node_cli.mirage.mirage_node import restore_mirage, request_repair
24+
from node_cli.utils.helper import error_exit, streamed_cmd, abort_if_false, URL_TYPE
25+
from node_cli.utils.texts import safe_load_texts
26+
27+
TEXTS = safe_load_texts()
2528

2629

2730
@click.group()
@@ -94,3 +97,22 @@ def backup_node(backup_folder_path):
9497
@streamed_cmd
9598
def restore_node(backup_path, env_file, config_only):
9699
restore_mirage(backup_path, env_file, config_only)
100+
101+
102+
@node.command('repair', help='Toggle mirage chain repair mode')
103+
@click.option(
104+
'--yes',
105+
is_flag=True,
106+
callback=abort_if_false,
107+
expose_value=False,
108+
prompt=TEXTS['mirage']['node']['repair']['warning'],
109+
)
110+
@click.option(
111+
'--snapshot-from',
112+
type=URL_TYPE,
113+
default='',
114+
hidden=True,
115+
help=TEXTS['mirage']['node']['repair']['snapshot_from'],
116+
)
117+
def repair(snapshot_from: str = '') -> None:
118+
request_repair(snapshot_from=snapshot_from)

node_cli/configs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,5 @@ def _get_env():
169169

170170
UFW_CONFIG_PATH = '/etc/default/ufw'
171171
UFW_IPV6_BEFORE_INPUT_CHAIN = 'ufw6-before-input'
172+
173+
REDIS_URI: str = os.getenv('REDIS_URI', 'redis://@127.0.0.1:6379')

node_cli/core/checks.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
import docker # type: ignore
4747
import psutil # type: ignore
48-
import yaml
4948
from debian import debian_support
5049
from packaging.version import parse as version_parse
5150

@@ -55,11 +54,10 @@
5554
DOCKER_CONFIG_FILEPATH,
5655
DOCKER_DAEMON_HOSTS,
5756
REPORTS_PATH,
58-
STATIC_PARAMS_FILEPATH,
59-
MIRAGE_STATIC_PARAMS_FILEPATH,
6057
)
6158
from node_cli.core.host import is_ufw_ipv6_chain_exists, is_ufw_ipv6_option_enabled
6259
from node_cli.core.resources import get_disk_size
60+
from node_cli.core.static_config import get_static_params
6361
from node_cli.utils.docker_utils import NodeType
6462
from node_cli.utils.helper import run_cmd, safe_mkdir
6563

@@ -78,23 +76,6 @@
7876
FuncList = List[Func]
7977

8078

81-
def get_static_params(
82-
node_type: NodeType,
83-
env_type: str = 'mainnet',
84-
config_path: str = CONTAINER_CONFIG_PATH,
85-
) -> Dict:
86-
if node_type == NodeType.MIRAGE:
87-
static_params_base_filepath = MIRAGE_STATIC_PARAMS_FILEPATH
88-
else:
89-
static_params_base_filepath = STATIC_PARAMS_FILEPATH
90-
91-
static_params_filename = os.path.basename(static_params_base_filepath)
92-
static_params_filepath = os.path.join(config_path, static_params_filename)
93-
with open(static_params_filepath) as requirements_file:
94-
ydata = yaml.load(requirements_file, Loader=yaml.Loader)
95-
return ydata['envs'][env_type]
96-
97-
9879
def check_quietly(check: Func, *args, **kwargs) -> CheckResult:
9980
try:
10081
return check(*args, **kwargs)

node_cli/core/schains.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is part of node-cli
4+
#
5+
# Copyright (C) 2025 SKALE Labs
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
120
import glob
221
import logging
322
import os
423
import pprint
524
import shutil
625
import time
726
from pathlib import Path
8-
927
from typing import Dict, Optional
1028

29+
from lvmpy.src.core import mount, volume_mountpoint
1130
from node_cli.configs import (
1231
ALLOCATION_FILEPATH,
13-
NODE_CONFIG_PATH,
1432
NODE_CLI_STATUS_FILENAME,
33+
NODE_CONFIG_PATH,
1534
SCHAIN_NODE_DATA_PATH,
1635
SCHAINS_MNT_DIR_SINGLE_CHAIN,
1736
)
1837
from node_cli.configs.env import get_validated_env_config
19-
20-
from node_cli.utils.helper import get_request, error_exit, safe_load_yml
38+
from node_cli.utils.docker_utils import ensure_volume, is_volume_exists
2139
from node_cli.utils.exit_codes import CLIExitCodes
40+
from node_cli.utils.helper import (
41+
error_exit,
42+
get_request,
43+
read_json,
44+
run_cmd,
45+
safe_load_yml,
46+
save_json,
47+
)
48+
from node_cli.utils.node_type import NodeType
2249
from node_cli.utils.print_formatters import (
2350
print_dkg_statuses,
2451
print_firewall_rules,
2552
print_schain_info,
2653
print_schains,
2754
)
28-
from node_cli.utils.docker_utils import ensure_volume, is_volume_exists
29-
from node_cli.utils.helper import read_json, run_cmd, save_json
30-
from node_cli.utils.node_type import NodeType
31-
from lvmpy.src.core import mount, volume_mountpoint
32-
3355

3456
logger = logging.getLogger(__name__)
3557

node_cli/core/static_config.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is part of node-cli
4+
#
5+
# Copyright (C) 2025 SKALE Labs
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
import os
21+
22+
import yaml
23+
24+
from node_cli.configs import (
25+
CONTAINER_CONFIG_PATH,
26+
MIRAGE_STATIC_PARAMS_FILEPATH,
27+
STATIC_PARAMS_FILEPATH,
28+
)
29+
from node_cli.utils.node_type import NodeType
30+
31+
32+
def get_static_params(
33+
node_type: NodeType,
34+
env_type: str = 'mainnet',
35+
config_path: str = CONTAINER_CONFIG_PATH,
36+
) -> dict:
37+
if node_type == NodeType.MIRAGE:
38+
static_params_base_filepath = MIRAGE_STATIC_PARAMS_FILEPATH
39+
else:
40+
static_params_base_filepath = STATIC_PARAMS_FILEPATH
41+
42+
static_params_filename = os.path.basename(static_params_base_filepath)
43+
static_params_filepath = os.path.join(config_path, static_params_filename)
44+
with open(static_params_filepath) as requirements_file:
45+
ydata = yaml.load(requirements_file, Loader=yaml.Loader)
46+
return ydata['envs'][env_type]

node_cli/mirage/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)