Skip to content

Commit

Permalink
Merge pull request #874 from skalenetwork/update-deps
Browse files Browse the repository at this point in the history
Update dependencies. Remove unused packages
  • Loading branch information
badrogger authored Oct 26, 2022
2 parents 0818aa1 + b9bbfd6 commit b3da655
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 29 deletions.
6 changes: 4 additions & 2 deletions core/filebeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
from typing import Optional

from tools.helper import process_template
from tools.docker_utils import DockerUtils
from tools.str_formatters import arguments_list_string

from tools.configs.filebeat import (FILEBEAT_TEMPLATE_PATH, FILEBEAT_CONTAINER_NAME,
FILEBEAT_CONFIG_PATH)

dutils = DockerUtils()
logger = logging.getLogger(__name__)


def update_filebeat_service(node_ip, node_id, skale):
def update_filebeat_service(node_ip, node_id, skale, dutils: Optional[DockerUtils] = None):
logger.info('Going to update filebeat service...')
dutils = dutils or DockerUtils()
contract_address = skale.manager.address
template_data = {
'ip': node_ip,
Expand Down
5 changes: 2 additions & 3 deletions core/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from tools.docker_utils import DockerUtils
from tools.helper import process_template

gdutils = DockerUtils()
logger = logging.getLogger(__name__)


Expand All @@ -18,7 +17,7 @@ def reload_nginx(
config_filepath=NGINX_CONFIG_FILEPATH,
dutils=None
):
dutils = dutils or gdutils
dutils = dutils or DockerUtils()
generate_nginx_config(
template_filepath=template_filepath,
config_filepath=config_filepath
Expand All @@ -40,6 +39,6 @@ def generate_nginx_config(


def restart_nginx_container(dutils=None):
dutils = dutils or gdutils
dutils = dutils or DockerUtils()
nginx_container = dutils.client.containers.get(NGINX_CONTAINER_NAME)
nginx_container.restart()
2 changes: 1 addition & 1 deletion helper-scripts
11 changes: 4 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
peewee==3.9.5
PyMySQL==0.9.3

Flask==2.0.2
Werkzeug==2.0.2
gunicorn==20.1.0

Jinja2==3.0.3

docker==4.2.2
pyjwt==1.4.2
docker==5.0.3
simple-crypt==4.1.7
pycryptodome==3.12.0
python-iptables==0.14.0
python-iptables==1.0.0

skale.py==5.7dev7

Expand All @@ -24,10 +21,10 @@ multisigwallet-predeployed==0.0.1a5
predeployed-generator==1.1.0a8

pyyaml==5.4
psutil==5.7.0
psutil==5.9.3

colorful==0.5.4
celery==4.4.6
celery==5.0.2
redis==3.5.3

filelock==3.0.12
Expand Down
4 changes: 2 additions & 2 deletions tests/routes/ssl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def post_bp_files_data(bp, request, file_data, full_response=False, **kwargs):
def test_upload(skale_bp, ssl_folder, db, cert_key_pair_host):
cert_path, key_path = cert_key_pair_host
with mock.patch('web.routes.ssl.set_schains_need_reload'), \
mock.patch('core.nginx.restart_nginx_container'):
mock.patch('web.routes.ssl.reload_nginx'):
with files_data(cert_path, key_path, force=False) as data:
response = post_bp_files_data(
skale_bp,
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_upload_bad_cert(skale_bp, db, ssl_folder, bad_cert_host):
def test_upload_cert_exist(skale_bp, db, cert_key_pair_host, cert_key_pair):
cert_path, key_path = cert_key_pair_host
with mock.patch('web.routes.ssl.set_schains_need_reload'), \
mock.patch('core.nginx.restart_nginx_container'):
mock.patch('web.routes.ssl.reload_nginx'):
with files_data(cert_path, key_path, force=False) as data:
response = post_bp_files_data(
skale_bp,
Expand Down
5 changes: 3 additions & 2 deletions tests/schains/checks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ def test_blocks_check(schain_checks):
assert not schain_checks.blocks.status


def test_init_checks(skale, schain_db, uninited_rule_controller):
def test_init_checks(skale, schain_db, uninited_rule_controller, dutils):
schain_name = schain_db
schain_record = SChainRecord.get_by_name(schain_name)
checks = SChainChecks(
schain_name,
TEST_NODE_ID,
schain_record=schain_record,
rule_controller=uninited_rule_controller
rule_controller=uninited_rule_controller,
dutils=dutils
)
assert checks.name == schain_name
assert checks.node_id == TEST_NODE_ID
Expand Down
3 changes: 2 additions & 1 deletion tests/schains/monitor/base_monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def test_crashing_monitor(
node_config=node_config,
rotation_data={'rotation_id': 1, 'leaving_node': 1},
checks=schain_checks,
rule_controller=rule_controller
rule_controller=rule_controller,
dutils=dutils
)
with pytest.raises(Exception):
test_monitor.run()
Expand Down
32 changes: 25 additions & 7 deletions tests/schains/monitor/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,40 @@ def skaled_container(self) -> CheckRes:


@pytest.fixture
def checks(schain_db, _schain_name, rule_controller, node_config, ima_data):
def checks(
schain_db,
_schain_name,
rule_controller,
node_config,
ima_data,
dutils
):
schain_record = upsert_schain_record(schain_db)
return SChainChecksMock(
_schain_name,
node_config.id,
schain_record,
rule_controller=rule_controller
rule_controller=rule_controller,
dutils=dutils
)


@pytest.fixture
def bad_checks(schain_db, _schain_name, rule_controller, node_config, ima_data):
def bad_checks(
schain_db,
_schain_name,
rule_controller,
node_config,
ima_data,
dutils
):
schain_record = upsert_schain_record(schain_db)
return SChainChecksMockBad(
_schain_name,
node_config.id,
schain_record,
rule_controller=rule_controller
rule_controller=rule_controller,
dutils=dutils
)


Expand Down Expand Up @@ -131,23 +147,25 @@ def test_is_reload_mode(schain_db, checks, bad_checks, skaled_status_reload):
assert get_monitor_type(schain_record, bad_checks, False, skaled_status_reload) == ReloadMonitor


def test_run_monitor_for_schain(skale, skale_ima, node_config, schain_db):
def test_run_monitor_for_schain(skale, skale_ima, node_config, schain_db, dutils):
with mock.patch('core.schains.monitor.main.RegularMonitor', CrashingTestMonitor), \
mock.patch('core.schains.monitor.main.is_node_part_of_chain', return_value=True):
assert not run_monitor_for_schain(
skale,
skale_ima,
node_config,
{'name': schain_db, 'partOfNode': 0, 'generation': 0},
once=True
once=True,
dutils=dutils
)
with mock.patch('core.schains.monitor.main.RegularMonitor', BaseTestMonitor):
assert run_monitor_for_schain(
skale,
skale_ima,
node_config,
{'name': schain_db, 'partOfNode': 0, 'generation': 0},
once=True
once=True,
dutils=dutils
)


Expand Down
11 changes: 7 additions & 4 deletions tests/schains/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_set_rotation(schain_config):
assert data['params'] == params


def test_is_exited():
def test_is_exited(dutils):
schain_name = 'schain_test'
info_mock = {
'status': 'exited',
Expand All @@ -36,9 +36,12 @@ def test_is_exited():
}
}
}
with mock.patch('core.schains.runner.DockerUtils.get_info',
new=mock.Mock(return_value=info_mock)):
assert is_exited(schain_name)
get_info = dutils.get_info
try:
dutils.get_info = mock.Mock(return_value=info_mock)
assert is_exited(schain_name, dutils=dutils)
finally:
dutils.get_info = get_info


def test_get_leaving_schains_for_node(skale, node_config): # TODO: improve test
Expand Down

0 comments on commit b3da655

Please sign in to comment.