-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #697 from skalenetwork/no-major-snapshot-option
No major snapshot option
- Loading branch information
Showing
9 changed files
with
192 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of node-cli | ||
# | ||
# Copyright (C) 2022 SKALE Labs | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import os | ||
from node_cli.configs import NODE_DATA_PATH | ||
|
||
NODE_OPTIONS_FILEPATH = os.path.join(NODE_DATA_PATH, 'node_options.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of node-cli | ||
# | ||
# Copyright (C) 2022 SKALE Labs | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
from typing import Optional | ||
|
||
from node_cli.utils.helper import read_json, write_json, init_file | ||
from node_cli.configs.node_options import NODE_OPTIONS_FILEPATH | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NodeOptions: | ||
def __init__( | ||
self, | ||
filepath: str = NODE_OPTIONS_FILEPATH | ||
): | ||
self.filepath = filepath | ||
init_file(filepath, {}) | ||
|
||
def _get(self, field_name: str): | ||
config = read_json(self.filepath) | ||
return config.get(field_name) | ||
|
||
def _set(self, field_name: str, field_value) -> None: | ||
config = read_json(self.filepath) | ||
config[field_name] = field_value | ||
write_json(self.filepath, config) | ||
|
||
@property | ||
def snapshot_from(self) -> Optional[str]: | ||
return self._get('snapshot_from') | ||
|
||
@snapshot_from.setter | ||
def snapshot_from(self, ip: Optional[str]) -> None: | ||
return self._set('snapshot_from', ip) | ||
|
||
def all(self) -> dict: | ||
return read_json(self.filepath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from node_cli.core.host import ( | ||
is_btrfs_module_autoloaded, | ||
ensure_btrfs_kernel_module_autoloaded | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tmp_path(tmp_dir_path): | ||
path = os.path.join(tmp_dir_path, 'modules') | ||
return path | ||
|
||
|
||
def test_btrfs_module_autoload_config(tmp_path): | ||
ensure_btrfs_kernel_module_autoloaded(tmp_path) | ||
assert is_btrfs_module_autoloaded(tmp_path) | ||
with open(tmp_path) as tmp_file: | ||
tmp_file.read() == 'btrfs\n' | ||
|
||
|
||
def test_is_btrfs_module_autoloaded_negative(tmp_path): | ||
assert not is_btrfs_module_autoloaded(tmp_path) | ||
with open(tmp_path, 'w') as tmp_file: | ||
tmp_file.write('') | ||
|
||
assert not is_btrfs_module_autoloaded(tmp_path) | ||
|
||
with open(tmp_path, 'w') as tmp_file: | ||
tmp_file.write('# btrfs') | ||
|
||
assert not is_btrfs_module_autoloaded(tmp_path) |