Skip to content

Commit

Permalink
Merge pull request #1088 from skalenetwork/merge-develop
Browse files Browse the repository at this point in the history
Fix NewNodeSkaledMonitor condition (beta)
  • Loading branch information
dmytrotkk authored Jul 9, 2024
2 parents 5bdd056 + faf10dd commit 1180086
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
SGX_WALLET_TAG: "1.83.0-beta.5"
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
PYTHON_VERSION: 3.11

jobs:
test_core:
runs-on: ubuntu-latest
Expand All @@ -20,34 +21,61 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install python dependencies
run: bash ./scripts/install_python_dependencies.sh

- name: Lint with flake8
run: flake8 .

- name: Launch anvil node
run: |
docker run -d --network host --name anvil ghcr.io/foundry-rs/foundry anvil && sleep 5 && docker logs anvil --tail 1000
- name: Deploy manager & ima contracts
run: |
bash ./helper-scripts/deploy_test_ima.sh
- name: Cleanup skale-manager image
run: |
docker rmi -f skalenetwork/skale-manager:${{ env.MANAGER_TAG }}
- name: Show stats before tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run core tests
run: |
bash ./scripts/run_core_tests.sh
- name: Show stats after tests
- name: Cleanup docker artifacts
run: |
docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)
- name: Show stats after core tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run firewall tests
run: |
bash ./scripts/run_firewall_test.sh
- name: Show stats after firewall tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run codecov
run: |
codecov -t $CODECOV_TOKEN
8 changes: 4 additions & 4 deletions core/schains/monitor/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
save_dkg_results
)
from core.schains.ima import get_migration_ts as get_ima_migration_ts
from core.schains.ssl import update_ssl_change_date

from core.schains.cleaner import (
remove_ima_container,
Expand Down Expand Up @@ -74,6 +73,7 @@
from core.schains.ima import ImaData
from core.schains.external_config import ExternalConfig, ExternalState
from core.schains.skaled_status import init_skaled_status
from core.schains.ssl import update_ssl_change_date

from tools.configs import SYNC_NODE
from tools.configs.containers import IMA_CONTAINER, SCHAIN_CONTAINER
Expand Down Expand Up @@ -395,9 +395,10 @@ def restart_skaled_container(self) -> bool:
logger.info('Skaled container exists, restarting')
restart_container(SCHAIN_CONTAINER, self.schain,
dutils=self.dutils)
update_ssl_change_date(self.schain_record)
else:
logger.info(
'Skaled container doesn\'t exists, running skaled watchman')
'Skaled container does not exists, running skaled watchman')
initial_status = self.skaled_container()
return initial_status

Expand Down Expand Up @@ -426,10 +427,9 @@ def reloaded_skaled_container(self, abort_on_exit: bool = True) -> bool:
logger.info('Removing skaled container')
remove_schain_container(self.name, dutils=self.dutils)
else:
logger.warning('Container doesn\'t exists')
logger.warning('Container does not exists')
self.schain_record.set_restart_count(0)
self.schain_record.set_failed_rpc_count(0)
update_ssl_change_date(self.schain_record)
self.schain_record.set_needs_reload(False)
initial_status = self.skaled_container(
abort_on_exit=abort_on_exit)
Expand Down
3 changes: 3 additions & 0 deletions core/schains/monitor/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
from core.ima.schain import copy_schain_ima_abi
from core.schains.ima import get_ima_time_frame, ImaData
from core.schains.ssl import update_ssl_change_date

from tools.configs import SYNC_NODE
from tools.configs.containers import (
Expand Down Expand Up @@ -85,6 +86,7 @@ def monitor_schain_container(
sync_node=sync_node,
historic_state=historic_state,
)
update_ssl_change_date(schain_record)
schain_record.reset_failed_counters()
return

Expand All @@ -99,6 +101,7 @@ def monitor_schain_container(
if schain_record.restart_count < MAX_SCHAIN_RESTART_COUNT:
logger.info('sChain %s: restarting container', schain_name)
restart_container(SCHAIN_CONTAINER, schain, dutils=dutils)
update_ssl_change_date(schain_record)
schain_record.set_restart_count(schain_record.restart_count + 1)
schain_record.set_failed_rpc_count(0)
else:
Expand Down
8 changes: 4 additions & 4 deletions core/schains/monitor/skaled_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def is_config_update_time(
return not status['skaled_container'] and skaled_status.exit_time_reached


def is_recreate_mode(schain_record: SChainRecord) -> bool:
return ssl_reload_needed(schain_record)
def is_recreate_mode(status: Dict, schain_record: SChainRecord) -> bool:
return status['skaled_container'] and ssl_reload_needed(schain_record)


def is_new_node_mode(schain_record: SChainRecord, finish_ts: Optional[int]) -> bool:
Expand Down Expand Up @@ -311,7 +311,7 @@ def get_skaled_monitor(
if SYNC_NODE:
if no_config(status):
mon_type = NoConfigSkaledMonitor
if is_recreate_mode(schain_record):
if is_recreate_mode(status, schain_record):
mon_type = RecreateSkaledMonitor
elif is_config_update_time(status, skaled_status):
mon_type = UpdateConfigSkaledMonitor
Expand All @@ -327,7 +327,7 @@ def get_skaled_monitor(
mon_type = BackupSkaledMonitor
elif is_repair_mode(schain_record, status, skaled_status, automatic_repair):
mon_type = RepairSkaledMonitor
elif is_recreate_mode(schain_record):
elif is_recreate_mode(status, schain_record):
mon_type = RecreateSkaledMonitor
elif is_new_node_mode(schain_record, action_manager.finish_ts):
mon_type = NewNodeSkaledMonitor
Expand Down
1 change: 1 addition & 0 deletions scripts/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export_test_env () {
export SCHAIN_STOP_TIMEOUT=1
export ABI_FILEPATH=${ABI_FILEPATH="$PWD/helper-scripts/contracts_data/manager.json"}
export IMA_ABI_FILEPATH=${IMA_ABI_FILEPATH}
export DEFAULT_GAS_PRICE_WEI=1000000000

cp $PWD/helper-scripts/contracts_data/ima.json $SKALE_DIR_HOST/contracts_info
}
Expand Down
4 changes: 1 addition & 3 deletions scripts/run_core_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
set -ea

export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $DIR/helper.sh
Expand All @@ -15,5 +15,3 @@ bash scripts/run_redis.sh

py.test --cov-config=.coveragerc --cov=. tests/ --ignore=tests/firewall $@
tests_cleanup
scripts/run_firewall_test.sh
tests_cleanup
9 changes: 5 additions & 4 deletions scripts/run_firewall_test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash
set -e
set -ea

export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

docker rm -f test-firewall || true
DIR=$PWD
docker build -t admin:base .
docker build -f tests.Dockerfile -t test-firewall .
docker run -v "$DIR/tests/skale-data/node_data":"/skale_node_data" \
-v "$DIR/tests/skale-data":"/skale_vol" \
docker run -v "$DIR/../tests/skale-data/node_data":"/skale_node_data" \
-v "$DIR/../tests/skale-data":"/skale_vol" \
-e SGX_SERVER_URL="https://127.0.0.1:1026" \
-e ENDPOINT="http://127.0.0.1:8545" \
-e DB_USER="test" \
Expand Down
13 changes: 12 additions & 1 deletion tests/schains/monitor/skaled_monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,22 @@ def test_get_skaled_monitor_recreate(
name = schain_db
schain_record = SChainRecord.get_by_name(name)
schain_record.set_ssl_change_date(datetime.datetime.now())
status = skaled_checks.get_all()

with mock.patch('core.schains.ssl.get_ssl_files_change_date',
return_value=datetime.datetime.now()):
status['skaled_container'] = False
mon = get_skaled_monitor(
skaled_am,
skaled_checks.get_all(),
status,
schain_record,
skaled_status
)
assert mon == RegularSkaledMonitor
status['skaled_container'] = True
mon = get_skaled_monitor(
skaled_am,
status,
schain_record,
skaled_status
)
Expand Down

0 comments on commit 1180086

Please sign in to comment.