Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SGX check #1111

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/routes/health_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def test_sgx(skale_bp, skale):
assert data == {
'payload': {
'sgx_server_url': SGX_SERVER_URL,
'status': 0,
'status_name': 'CONNECTED',
'status_zmq': True,
'status_https': True,
'sgx_wallet_version': version,
'sgx_keyname': TEST_SGX_KEYNAME,
},
Expand Down
44 changes: 18 additions & 26 deletions web/routes/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
import telnetlib
from enum import Enum
from http import HTTPStatus


from flask import Blueprint, g, request
from sgx import SgxClient


from urllib.parse import urlparse
from core.node import get_check_report, get_skale_node_version
from core.node import get_current_nodes
from core.schains.checks import SChainChecks
Expand All @@ -38,7 +35,6 @@
from core.schains.ima import get_ima_log_checks
from core.schains.external_config import ExternalState
from tools.sgx_utils import SGX_CERTIFICATES_FOLDER, SGX_SERVER_URL
from tools.configs import ZMQ_PORT, ZMQ_TIMEOUT
from web.models.schain import SChainRecord
from web.helper import (
construct_err_response,
Expand All @@ -51,11 +47,6 @@
BLUEPRINT_NAME = 'health'


class SGXStatus(Enum):
CONNECTED = 0
NOT_CONNECTED = 1


health_bp = Blueprint(BLUEPRINT_NAME, __name__)


Expand Down Expand Up @@ -137,27 +128,28 @@
@health_bp.route(get_api_url(BLUEPRINT_NAME, 'sgx'), methods=['GET'])
def sgx_info():
logger.debug(request)
sgx = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER)
status_zmq = False
status_https = False
version = None
sgx = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER, zmq=True)
try:
status = sgx.get_server_status()
version = sgx.get_server_version()
except Exception as e: # todo: catch specific error - edit sgx.py
logger.info(e)
status = 1
version = None
sgx_host = urlparse(SGX_SERVER_URL).hostname
tn = telnetlib.Telnet()
zmq_status = 0
if sgx.zmq.get_server_status() == 0:
status_zmq = True
version = sgx.zmq.get_server_version()
except Exception as err:
logger.error(f'Cannot make SGX ZMQ check {err}')

Check warning on line 140 in web/routes/health.py

View check run for this annotation

Codecov / codecov/patch

web/routes/health.py#L139-L140

Added lines #L139 - L140 were not covered by tests
sgx_https = SgxClient(SGX_SERVER_URL, SGX_CERTIFICATES_FOLDER)
try:
tn.open(sgx_host, ZMQ_PORT, timeout=ZMQ_TIMEOUT)
if sgx_https.get_server_status() == 0:
status_https = True
if version is None:
version = sgx_https.get_server_version()

Check warning on line 146 in web/routes/health.py

View check run for this annotation

Codecov / codecov/patch

web/routes/health.py#L146

Added line #L146 was not covered by tests
except Exception as err:
zmq_status = 1
logger.error(err)
else:
tn.close()
logger.error(f'Cannot make SGX HTTPS check {err}')

Check warning on line 148 in web/routes/health.py

View check run for this annotation

Codecov / codecov/patch

web/routes/health.py#L148

Added line #L148 was not covered by tests

res = {
'status': zmq_status,
'status_name': SGXStatus(status).name,
'status_zmq': status_zmq,
'status_https': status_https,
'sgx_server_url': SGX_SERVER_URL,
'sgx_keyname': g.config.sgx_key_name,
'sgx_wallet_version': version
Expand Down
Loading